1 | /***************************************************************************
|
---|
2 | * Copyright (C) 2008 by Daniel Wendt *
|
---|
3 | * gentoo.murray@gmail.com *
|
---|
4 | * *
|
---|
5 | * This program is free software; you can redistribute it and/or modify *
|
---|
6 | * it under the terms of the GNU General Public License as published by *
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
8 | * (at your option) any later version. *
|
---|
9 | * *
|
---|
10 | * This program is distributed in the hope that it will be useful, *
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
13 | * GNU General Public License for more details. *
|
---|
14 | * *
|
---|
15 | * You should have received a copy of the GNU General Public License *
|
---|
16 | * along with this program; if not, write to the *
|
---|
17 | * Free Software Foundation, Inc., *
|
---|
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
---|
19 | ***************************************************************************/
|
---|
20 |
|
---|
21 | #include "stdafx.h"
|
---|
22 | #include "OSMDocumentParserCallback.h"
|
---|
23 | #include "OSMDocument.h"
|
---|
24 | #include "Way.h"
|
---|
25 | #include "Node.h"
|
---|
26 |
|
---|
27 | // define here, which streetstype you want to parse
|
---|
28 | // for applying this filter, compile with "DISTRICT" as flag (g++ -DRESTRICT)
|
---|
29 | #define _FILTER if(m_pActWay->highway == "motorway" || m_pActWay->highway == "primary" || m_pActWay->highway == "secondary")
|
---|
30 |
|
---|
31 | namespace osm
|
---|
32 | {
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | Parser callback for OSMDocument files
|
---|
37 | */
|
---|
38 | void OSMDocumentParserCallback::StartElement( const char *name, const char** atts )
|
---|
39 | {
|
---|
40 | if( strcmp(name,"nd") == 0 )
|
---|
41 | {
|
---|
42 | if( m_pActWay && atts != NULL )
|
---|
43 | {
|
---|
44 | const char* name = *atts++;
|
---|
45 | const char* value = *atts++;
|
---|
46 | if( strcmp(name,"ref")==0 )
|
---|
47 | {
|
---|
48 | long long nodeRefId = atol( value );
|
---|
49 | m_pActWay->AddNodeRef( m_rDocument.FindNode( nodeRefId ) );
|
---|
50 | m_rDocument.FindNode( nodeRefId )->numsOfUse+=1;
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | else if( strcmp(name,"node") == 0 )
|
---|
55 | {
|
---|
56 | if (atts != NULL)
|
---|
57 | {
|
---|
58 | long long id=-1;
|
---|
59 | double lat=-1;
|
---|
60 | double lon=-1;
|
---|
61 | const char** attribut = (const char**)atts;
|
---|
62 | while( *attribut != NULL )
|
---|
63 | {
|
---|
64 | const char* name = *attribut++;
|
---|
65 | const char* value = *attribut++;
|
---|
66 | if( strcmp( name, "id" ) == 0 )
|
---|
67 | {
|
---|
68 | id = atol( value);
|
---|
69 | }
|
---|
70 | else if( strcmp( name, "lat" ) == 0 )
|
---|
71 | {
|
---|
72 | lat = atof( value );
|
---|
73 | }
|
---|
74 | else if( strcmp( name, "lon" ) == 0 )
|
---|
75 | {
|
---|
76 | lon = atof( value );
|
---|
77 | }
|
---|
78 | }
|
---|
79 | if( id>0 ) m_rDocument.AddNode( new Node( id, lat, lon ) );
|
---|
80 | }
|
---|
81 | }
|
---|
82 | else if( strcmp(name,"tag") == 0 )
|
---|
83 | {
|
---|
84 | // <tag k="name" v="Pfänderweg"/>
|
---|
85 | if (atts != NULL)
|
---|
86 | {
|
---|
87 | std::string k;
|
---|
88 | std::string v;
|
---|
89 | const char** attribut = (const char**)atts;
|
---|
90 | while( *attribut != NULL )
|
---|
91 | {
|
---|
92 | const char* name = *attribut++;
|
---|
93 | const char* value = *attribut++;
|
---|
94 | if( strcmp( name, "k" ) == 0 )
|
---|
95 | {
|
---|
96 | k = value;
|
---|
97 | }
|
---|
98 | else if( strcmp( name, "v" ) == 0 )
|
---|
99 | {
|
---|
100 | v = value;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | if( !k.empty() )
|
---|
104 | {
|
---|
105 | if( m_pActWay && k.compare("name")==0 )
|
---|
106 | {
|
---|
107 | m_pActWay->name = v;
|
---|
108 | }
|
---|
109 | else if( m_pActWay && k.compare("highway")==0 )
|
---|
110 | {
|
---|
111 | m_pActWay->highway = v;
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 | else if( strcmp(name,"way") == 0 )
|
---|
117 | {
|
---|
118 | if (atts != NULL)
|
---|
119 | {
|
---|
120 | long long id=-1;
|
---|
121 | bool visibility = false;
|
---|
122 | const char** attribut = (const char**)atts;
|
---|
123 | while( *attribut != NULL )
|
---|
124 | {
|
---|
125 | const char* name = *attribut++;
|
---|
126 | const char* value = *attribut++;
|
---|
127 | if( strcmp( name, "id" ) == 0 )
|
---|
128 | {
|
---|
129 | id = atol( value);
|
---|
130 | }
|
---|
131 | else if( strcmp( name, "visible" ) == 0 )
|
---|
132 | {
|
---|
133 | visibility = strcmp(value,"true")==0;
|
---|
134 | }
|
---|
135 | }
|
---|
136 | if( id>0 )
|
---|
137 | {
|
---|
138 | m_pActWay = new Way( id, visibility );
|
---|
139 |
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | else if( strcmp(name,"osm") == 0 )
|
---|
144 | {
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 | void OSMDocumentParserCallback::EndElement( const char* name )
|
---|
151 | {
|
---|
152 | if( strcmp(name,"way") == 0 )
|
---|
153 | {
|
---|
154 | #ifdef RESTRICT
|
---|
155 | _FILTER
|
---|
156 | {
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | m_rDocument.AddWay( m_pActWay );
|
---|
160 | #ifdef RESTRICT
|
---|
161 | }
|
---|
162 | else
|
---|
163 | {
|
---|
164 | delete m_pActWay;
|
---|
165 | }
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | m_pActWay = 0;
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | }; // end namespace osm
|
---|