Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 298 - (hide annotations) (download) (as text)
Mon Nov 2 19:32:06 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 7810 byte(s)
Added the ability to set routing preferences using highway properties.
Initially the only choice is either paved or unpaved but the code has been
updated to allow any number of properties to be added.

1 amb 2 /***************************************
2 amb 298 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.62 2009-11-02 19:32:06 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 284 /* Variables */
42    
43 amb 249 /*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/
44     int option_slim=0;
45    
46 amb 256 /*+ The name of the temporary directory. +*/
47 amb 284 char *option_tmpdirname=NULL;
48 amb 249
49 amb 284
50 amb 2 int main(int argc,char** argv)
51     {
52 amb 256 NodesX *Nodes;
53     SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL;
54     WaysX *Ways;
55 amb 58 int iteration=0,quit=0;
56 amb 150 int max_iterations=10;
57 amb 256 char *dirname=NULL,*prefix=NULL;
58 amb 220 Profile profile={0};
59 amb 75 int i;
60 amb 26
61 amb 82 /* Fill in the default profile. */
62 amb 31
63 amb 82 profile.transport=Transport_None; /* Not used by planetsplitter */
64 amb 75
65 amb 82 profile.allow=Allow_ALL;
66 amb 75
67 amb 82 for(i=1;i<Way_Unknown;i++)
68 amb 166 profile.highway[i]=1;
69 amb 82
70 amb 298 for(i=1;i<Property_Count;i++)
71     profile.props_yes[i]=1;
72    
73 amb 82 profile.oneway=1; /* Not used by planetsplitter */
74    
75     /* Parse the command line arguments */
76    
77 amb 60 while(--argc>=1)
78     {
79 amb 101 if(!strcmp(argv[argc],"--help"))
80 amb 75 goto usage;
81 amb 249 else if(!strcmp(argv[argc],"--slim"))
82     option_slim=1;
83 amb 101 else if(!strncmp(argv[argc],"--dir=",6))
84     dirname=&argv[argc][6];
85 amb 252 else if(!strncmp(argv[argc],"--tmpdir=",9))
86 amb 284 option_tmpdirname=&argv[argc][9];
87 amb 101 else if(!strncmp(argv[argc],"--prefix=",9))
88     prefix=&argv[argc][9];
89     else if(!strncmp(argv[argc],"--max-iterations=",17))
90     max_iterations=atoi(&argv[argc][17]);
91     else if(!strncmp(argv[argc],"--transport=",12))
92 amb 82 {
93 amb 101 profile.transport=TransportType(&argv[argc][12]);
94 amb 82 profile.allow=1<<(profile.transport-1);
95     }
96 amb 101 else if(!strncmp(argv[argc],"--not-highway=",14))
97 amb 75 {
98 amb 101 Highway highway=HighwayType(&argv[argc][14]);
99 amb 298 if(highway==Way_Unknown)
100     goto usage;
101 amb 166 profile.highway[highway]=0;
102 amb 75 }
103 amb 298 else if(!strncmp(argv[argc],"--not-property=",15))
104     {
105     Property property=PropertyType(&argv[argc][15]);
106     if(property==Property_Count)
107     goto usage;
108     profile.props_yes[property]=0;
109     }
110 amb 60 else
111     {
112 amb 75 usage:
113    
114     fprintf(stderr,"Usage: planetsplitter\n"
115 amb 150 " [--help]\n"
116 amb 298 " [--dir=<name>] [--prefix=<name>]\n"
117 amb 252 " [--slim] [--tmpdir=<name>]\n"
118 amb 101 " [--max-iterations=<number>]\n"
119     " [--transport=<transport>]\n"
120     " [--not-highway=<highway> ...]\n"
121 amb 298 " [--not-property=<property> ...]\n"
122 amb 75 "\n"
123 amb 82 "<transport> defaults to all but can be set to:\n"
124 amb 75 "%s"
125     "\n"
126 amb 82 "<highway> can be selected from:\n"
127 amb 298 "%s"
128     "\n"
129     "<property> can be selected from:\n"
130 amb 75 "%s",
131 amb 298 TransportList(),HighwayList(),PropertyList());
132 amb 75
133 amb 60 return(1);
134     }
135     }
136 amb 26
137 amb 284 if(!option_tmpdirname)
138 amb 252 {
139     if(!dirname)
140 amb 284 option_tmpdirname=".";
141 amb 252 else
142 amb 284 option_tmpdirname=dirname;
143 amb 252 }
144    
145 amb 275 /* Create new node, segment and way variables */
146 amb 82
147 amb 256 Nodes=NewNodeList();
148 amb 275
149 amb 256 Segments=NewSegmentList();
150 amb 275
151 amb 256 Ways=NewWayList();
152 amb 26
153 amb 89 /* Parse the file */
154 amb 2
155 amb 229 printf("\nParse OSM Data\n==============\n\n");
156 amb 227 fflush(stdout);
157 amb 2
158 amb 256 ParseXML(stdin,Nodes,Segments,Ways,&profile);
159 amb 80
160 amb 229 /* Process the data */
161    
162     printf("\nProcess OSM Data\n================\n\n");
163 amb 227 fflush(stdout);
164 amb 8
165 amb 275 /* Sort the nodes, segments and ways */
166 amb 263
167     SortNodeList(Nodes);
168    
169 amb 275 SortSegmentList(Segments);
170 amb 80
171 amb 256 SortWayList(Ways);
172 amb 87
173 amb 279 /* Remove bad segments (must be after sorting the nodes and segments) */
174 amb 247
175 amb 256 RemoveBadSegments(Nodes,Segments);
176 amb 87
177 amb 247 /* Remove non-highway nodes (must be after removing the bad segments) */
178 amb 66
179 amb 256 RemoveNonHighwayNodes(Nodes,Segments);
180 amb 247
181 amb 279 /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */
182 amb 247
183 amb 279 UpdateSegments(Segments,Nodes,Ways);
184 amb 66
185    
186 amb 258 /* Repeated iteration on Super-Nodes and Super-Segments */
187 amb 58
188     do
189     {
190 amb 229 printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":"");
191 amb 227 fflush(stdout);
192 amb 80
193 amb 90 if(iteration==0)
194     {
195     /* Select the super-nodes */
196 amb 58
197 amb 256 ChooseSuperNodes(Nodes,Segments,Ways);
198 amb 58
199 amb 90 /* Select the super-segments */
200 amb 58
201 amb 256 SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration);
202 amb 90 }
203     else
204     {
205 amb 97 SegmentsX *SuperSegments2;
206 amb 58
207 amb 90 /* Select the super-nodes */
208    
209 amb 256 ChooseSuperNodes(Nodes,SuperSegments,Ways);
210 amb 90
211     /* Select the super-segments */
212    
213 amb 256 SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration);
214 amb 90
215 amb 282 if(SuperSegments->xnumber==SuperSegments2->xnumber)
216 amb 104 quit=1;
217    
218 amb 97 FreeSegmentList(SuperSegments);
219 amb 90
220 amb 97 SuperSegments=SuperSegments2;
221 amb 90 }
222    
223 amb 275 /* Sort the super-segments */
224 amb 58
225 amb 275 SortSegmentList(SuperSegments);
226 amb 58
227 amb 229 /* Remove duplicated super-segments */
228    
229 amb 279 DeduplicateSegments(SuperSegments,Nodes,Ways);
230 amb 229
231 amb 89 iteration++;
232 amb 58
233 amb 89 if(iteration>max_iterations)
234     quit=1;
235     }
236     while(!quit);
237 amb 58
238 amb 229 /* Combine the super-segments */
239    
240     printf("\nCombine Segments and Super-Segments\n===================================\n\n");
241 amb 227 fflush(stdout);
242 amb 58
243 amb 104 /* Merge the super-segments */
244    
245 amb 256 MergedSegments=MergeSuperSegments(Segments,SuperSegments);
246 amb 104
247 amb 256 FreeSegmentList(Segments);
248    
249 amb 97 FreeSegmentList(SuperSegments);
250 amb 58
251 amb 256 Segments=MergedSegments;
252 amb 90
253 amb 275 /* Rotate segments so that node1<node2 */
254 amb 256
255 amb 275 RotateSegments(Segments);
256 amb 256
257 amb 275 /* Sort the segments */
258 amb 258
259 amb 275 SortSegmentList(Segments);
260 amb 258
261 amb 275 /* Remove duplicated segments */
262    
263 amb 279 DeduplicateSegments(Segments,Nodes,Ways);
264 amb 275
265 amb 229 /* Cross reference the nodes and segments */
266 amb 90
267 amb 229 printf("\nCross-Reference Nodes and Segments\n==================================\n\n");
268     fflush(stdout);
269 amb 90
270 amb 262 /* Compact the ways */
271    
272     CompactWayNames(Ways);
273    
274     CompactWayProperties(Ways);
275    
276 amb 212 /* Sort the node list geographically */
277 amb 209
278 amb 256 SortNodeListGeographically(Nodes);
279 amb 212
280     /* Create the real segments and nodes */
281    
282 amb 256 CreateRealNodes(Nodes,iteration);
283 amb 212
284 amb 256 CreateRealSegments(Segments,Ways);
285 amb 209
286 amb 104 /* Fix the segment and node indexes */
287    
288 amb 256 IndexNodes(Nodes,Segments);
289 amb 104
290 amb 256 IndexSegments(Segments,Nodes);
291 amb 104
292 amb 229 /* Output the results */
293    
294     printf("\nWrite Out Database Files\n========================\n\n");
295     fflush(stdout);
296    
297 amb 89 /* Write out the nodes */
298 amb 58
299 amb 256 SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem"));
300 amb 95
301 amb 256 FreeNodeList(Nodes);
302 amb 226
303 amb 89 /* Write out the segments */
304 amb 58
305 amb 256 SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem"));
306 amb 58
307 amb 256 FreeSegmentList(Segments);
308 amb 226
309 amb 89 /* Write out the ways */
310 amb 58
311 amb 256 SaveWayList(Ways,FileName(dirname,prefix,"ways.mem"));
312 amb 58
313 amb 256 FreeWayList(Ways);
314 amb 226
315 amb 2 return(0);
316     }

Properties

Name Value
cvs:description Planet file splitter.