Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/planetsplitter.c
Parent Directory
|
Revision Log
Revision 279 -
(hide annotations)
(download)
(as text)
Thu Oct 8 19:20:29 2009 UTC (15 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 7217 byte(s)
Thu Oct 8 19:20:29 2009 UTC (15 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 7217 byte(s)
Replace node, segment and way indexes with a single index for a set of segments containing the location of the first segment for each node.
1 | amb | 2 | /*************************************** |
2 | amb | 279 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.59 2009-10-08 19:20:29 amb Exp $ |
3 | amb | 2 | |
4 | OSM planet file splitter. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 2 | ******************/ /****************** |
8 | amb | 151 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | amb | 2 | |
10 | amb | 151 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by | ||
12 | the Free Software Foundation, either version 3 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU Affero General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU Affero General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | amb | 2 | ***************************************/ |
23 | |||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | amb | 60 | #include <string.h> |
28 | amb | 2 | |
29 | amb | 199 | #include "typesx.h" |
30 | amb | 96 | #include "types.h" |
31 | amb | 199 | #include "functionsx.h" |
32 | amb | 109 | #include "functions.h" |
33 | #include "nodesx.h" | ||
34 | #include "segmentsx.h" | ||
35 | #include "waysx.h" | ||
36 | #include "superx.h" | ||
37 | amb | 82 | #include "profiles.h" |
38 | amb | 228 | #include "ways.h" |
39 | amb | 2 | |
40 | |||
41 | amb | 249 | /*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/ |
42 | int option_slim=0; | ||
43 | |||
44 | amb | 256 | /*+ The name of the temporary directory. +*/ |
45 | char *tmpdirname=NULL; | ||
46 | amb | 249 | |
47 | amb | 2 | int main(int argc,char** argv) |
48 | { | ||
49 | amb | 256 | NodesX *Nodes; |
50 | SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL; | ||
51 | WaysX *Ways; | ||
52 | amb | 58 | int iteration=0,quit=0; |
53 | amb | 150 | int max_iterations=10; |
54 | amb | 256 | char *dirname=NULL,*prefix=NULL; |
55 | amb | 220 | Profile profile={0}; |
56 | amb | 75 | int i; |
57 | amb | 26 | |
58 | amb | 82 | /* Fill in the default profile. */ |
59 | amb | 31 | |
60 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
61 | amb | 75 | |
62 | amb | 82 | profile.allow=Allow_ALL; |
63 | amb | 75 | |
64 | amb | 82 | for(i=1;i<Way_Unknown;i++) |
65 | amb | 166 | profile.highway[i]=1; |
66 | amb | 82 | |
67 | profile.oneway=1; /* Not used by planetsplitter */ | ||
68 | |||
69 | /* Parse the command line arguments */ | ||
70 | |||
71 | amb | 60 | while(--argc>=1) |
72 | { | ||
73 | amb | 101 | if(!strcmp(argv[argc],"--help")) |
74 | amb | 75 | goto usage; |
75 | amb | 249 | else if(!strcmp(argv[argc],"--slim")) |
76 | option_slim=1; | ||
77 | amb | 101 | else if(!strncmp(argv[argc],"--dir=",6)) |
78 | dirname=&argv[argc][6]; | ||
79 | amb | 252 | else if(!strncmp(argv[argc],"--tmpdir=",9)) |
80 | tmpdirname=&argv[argc][9]; | ||
81 | amb | 101 | else if(!strncmp(argv[argc],"--prefix=",9)) |
82 | prefix=&argv[argc][9]; | ||
83 | else if(!strncmp(argv[argc],"--max-iterations=",17)) | ||
84 | max_iterations=atoi(&argv[argc][17]); | ||
85 | else if(!strncmp(argv[argc],"--transport=",12)) | ||
86 | amb | 82 | { |
87 | amb | 101 | profile.transport=TransportType(&argv[argc][12]); |
88 | amb | 82 | profile.allow=1<<(profile.transport-1); |
89 | } | ||
90 | amb | 101 | else if(!strncmp(argv[argc],"--not-highway=",14)) |
91 | amb | 75 | { |
92 | amb | 101 | Highway highway=HighwayType(&argv[argc][14]); |
93 | amb | 166 | profile.highway[highway]=0; |
94 | amb | 75 | } |
95 | amb | 60 | else |
96 | { | ||
97 | amb | 75 | usage: |
98 | |||
99 | fprintf(stderr,"Usage: planetsplitter\n" | ||
100 | amb | 150 | " [--help]\n" |
101 | amb | 252 | " [--slim] [--tmpdir=<name>]\n" |
102 | amb | 101 | " [--dir=<name>] [--prefix=<name>]\n" |
103 | " [--max-iterations=<number>]\n" | ||
104 | " [--transport=<transport>]\n" | ||
105 | " [--not-highway=<highway> ...]\n" | ||
106 | amb | 75 | "\n" |
107 | amb | 82 | "<transport> defaults to all but can be set to:\n" |
108 | amb | 75 | "%s" |
109 | "\n" | ||
110 | amb | 82 | "<highway> can be selected from:\n" |
111 | amb | 75 | "%s", |
112 | TransportList(),HighwayList()); | ||
113 | |||
114 | amb | 60 | return(1); |
115 | } | ||
116 | } | ||
117 | amb | 26 | |
118 | amb | 252 | if(!tmpdirname) |
119 | { | ||
120 | if(!dirname) | ||
121 | tmpdirname="."; | ||
122 | else | ||
123 | tmpdirname=dirname; | ||
124 | } | ||
125 | |||
126 | amb | 275 | /* Create new node, segment and way variables */ |
127 | amb | 82 | |
128 | amb | 256 | Nodes=NewNodeList(); |
129 | amb | 275 | |
130 | amb | 256 | Segments=NewSegmentList(); |
131 | amb | 275 | |
132 | amb | 256 | Ways=NewWayList(); |
133 | amb | 26 | |
134 | amb | 89 | /* Parse the file */ |
135 | amb | 2 | |
136 | amb | 229 | printf("\nParse OSM Data\n==============\n\n"); |
137 | amb | 227 | fflush(stdout); |
138 | amb | 2 | |
139 | amb | 256 | ParseXML(stdin,Nodes,Segments,Ways,&profile); |
140 | amb | 80 | |
141 | amb | 229 | /* Process the data */ |
142 | |||
143 | printf("\nProcess OSM Data\n================\n\n"); | ||
144 | amb | 227 | fflush(stdout); |
145 | amb | 8 | |
146 | amb | 275 | /* Sort the nodes, segments and ways */ |
147 | amb | 263 | |
148 | SortNodeList(Nodes); | ||
149 | |||
150 | amb | 275 | SortSegmentList(Segments); |
151 | amb | 80 | |
152 | amb | 256 | SortWayList(Ways); |
153 | amb | 87 | |
154 | amb | 279 | /* Remove bad segments (must be after sorting the nodes and segments) */ |
155 | amb | 247 | |
156 | amb | 256 | RemoveBadSegments(Nodes,Segments); |
157 | amb | 87 | |
158 | amb | 247 | /* Remove non-highway nodes (must be after removing the bad segments) */ |
159 | amb | 66 | |
160 | amb | 256 | RemoveNonHighwayNodes(Nodes,Segments); |
161 | amb | 247 | |
162 | amb | 279 | /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */ |
163 | amb | 247 | |
164 | amb | 279 | UpdateSegments(Segments,Nodes,Ways); |
165 | amb | 66 | |
166 | |||
167 | amb | 258 | /* Repeated iteration on Super-Nodes and Super-Segments */ |
168 | amb | 58 | |
169 | do | ||
170 | { | ||
171 | amb | 229 | printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":""); |
172 | amb | 227 | fflush(stdout); |
173 | amb | 80 | |
174 | amb | 90 | if(iteration==0) |
175 | { | ||
176 | /* Select the super-nodes */ | ||
177 | amb | 58 | |
178 | amb | 256 | ChooseSuperNodes(Nodes,Segments,Ways); |
179 | amb | 58 | |
180 | amb | 90 | /* Select the super-segments */ |
181 | amb | 58 | |
182 | amb | 256 | SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration); |
183 | amb | 90 | } |
184 | else | ||
185 | { | ||
186 | amb | 97 | SegmentsX *SuperSegments2; |
187 | amb | 58 | |
188 | amb | 90 | /* Select the super-nodes */ |
189 | |||
190 | amb | 256 | ChooseSuperNodes(Nodes,SuperSegments,Ways); |
191 | amb | 90 | |
192 | /* Select the super-segments */ | ||
193 | |||
194 | amb | 256 | SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration); |
195 | amb | 90 | |
196 | amb | 104 | if(SuperSegments->number==SuperSegments2->number) |
197 | quit=1; | ||
198 | |||
199 | amb | 97 | FreeSegmentList(SuperSegments); |
200 | amb | 90 | |
201 | amb | 97 | SuperSegments=SuperSegments2; |
202 | amb | 90 | } |
203 | |||
204 | amb | 275 | /* Sort the super-segments */ |
205 | amb | 58 | |
206 | amb | 275 | SortSegmentList(SuperSegments); |
207 | amb | 58 | |
208 | amb | 229 | /* Remove duplicated super-segments */ |
209 | |||
210 | amb | 279 | DeduplicateSegments(SuperSegments,Nodes,Ways); |
211 | amb | 229 | |
212 | amb | 89 | iteration++; |
213 | amb | 58 | |
214 | amb | 89 | if(iteration>max_iterations) |
215 | quit=1; | ||
216 | } | ||
217 | while(!quit); | ||
218 | amb | 58 | |
219 | amb | 229 | /* Combine the super-segments */ |
220 | |||
221 | printf("\nCombine Segments and Super-Segments\n===================================\n\n"); | ||
222 | amb | 227 | fflush(stdout); |
223 | amb | 58 | |
224 | amb | 104 | /* Merge the super-segments */ |
225 | |||
226 | amb | 256 | MergedSegments=MergeSuperSegments(Segments,SuperSegments); |
227 | amb | 104 | |
228 | amb | 256 | FreeSegmentList(Segments); |
229 | |||
230 | amb | 97 | FreeSegmentList(SuperSegments); |
231 | amb | 58 | |
232 | amb | 256 | Segments=MergedSegments; |
233 | amb | 90 | |
234 | amb | 275 | /* Rotate segments so that node1<node2 */ |
235 | amb | 256 | |
236 | amb | 275 | RotateSegments(Segments); |
237 | amb | 256 | |
238 | amb | 275 | /* Sort the segments */ |
239 | amb | 258 | |
240 | amb | 275 | SortSegmentList(Segments); |
241 | amb | 258 | |
242 | amb | 275 | /* Remove duplicated segments */ |
243 | |||
244 | amb | 279 | DeduplicateSegments(Segments,Nodes,Ways); |
245 | amb | 275 | |
246 | amb | 229 | /* Cross reference the nodes and segments */ |
247 | amb | 90 | |
248 | amb | 229 | printf("\nCross-Reference Nodes and Segments\n==================================\n\n"); |
249 | fflush(stdout); | ||
250 | amb | 90 | |
251 | amb | 262 | /* Compact the ways */ |
252 | |||
253 | CompactWayNames(Ways); | ||
254 | |||
255 | CompactWayProperties(Ways); | ||
256 | |||
257 | amb | 212 | /* Sort the node list geographically */ |
258 | amb | 209 | |
259 | amb | 256 | SortNodeListGeographically(Nodes); |
260 | amb | 212 | |
261 | /* Create the real segments and nodes */ | ||
262 | |||
263 | amb | 256 | CreateRealNodes(Nodes,iteration); |
264 | amb | 212 | |
265 | amb | 256 | CreateRealSegments(Segments,Ways); |
266 | amb | 209 | |
267 | amb | 104 | /* Fix the segment and node indexes */ |
268 | |||
269 | amb | 256 | IndexNodes(Nodes,Segments); |
270 | amb | 104 | |
271 | amb | 256 | IndexSegments(Segments,Nodes); |
272 | amb | 104 | |
273 | amb | 229 | /* Output the results */ |
274 | |||
275 | printf("\nWrite Out Database Files\n========================\n\n"); | ||
276 | fflush(stdout); | ||
277 | |||
278 | amb | 89 | /* Write out the nodes */ |
279 | amb | 58 | |
280 | amb | 256 | SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem")); |
281 | amb | 95 | |
282 | amb | 256 | FreeNodeList(Nodes); |
283 | amb | 226 | |
284 | amb | 89 | /* Write out the segments */ |
285 | amb | 58 | |
286 | amb | 256 | SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem")); |
287 | amb | 58 | |
288 | amb | 256 | FreeSegmentList(Segments); |
289 | amb | 226 | |
290 | amb | 89 | /* Write out the ways */ |
291 | amb | 58 | |
292 | amb | 256 | SaveWayList(Ways,FileName(dirname,prefix,"ways.mem")); |
293 | amb | 58 | |
294 | amb | 256 | FreeWayList(Ways); |
295 | amb | 226 | |
296 | amb | 2 | return(0); |
297 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |