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 150 -
(hide annotations)
(download)
(as text)
Tue Apr 7 18:32:50 2009 UTC (15 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 5851 byte(s)
Tue Apr 7 18:32:50 2009 UTC (15 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 5851 byte(s)
Remove the --help-profile command line option.
1 | amb | 2 | /*************************************** |
2 | amb | 150 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.33 2009-04-07 18:32:50 amb Exp $ |
3 | amb | 2 | |
4 | OSM planet file splitter. | ||
5 | ******************/ /****************** | ||
6 | Written by Andrew M. Bishop | ||
7 | |||
8 | amb | 4 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | amb | 2 | It may be distributed under the GNU Public License, version 2, or |
10 | any higher version. See section COPYING of the GNU Public license | ||
11 | for conditions under which this file may be redistributed. | ||
12 | ***************************************/ | ||
13 | |||
14 | |||
15 | #include <stdio.h> | ||
16 | #include <stdlib.h> | ||
17 | amb | 60 | #include <string.h> |
18 | amb | 2 | |
19 | amb | 96 | #include "types.h" |
20 | amb | 109 | #include "functions.h" |
21 | #include "nodesx.h" | ||
22 | #include "segmentsx.h" | ||
23 | #include "waysx.h" | ||
24 | #include "superx.h" | ||
25 | amb | 82 | #include "profiles.h" |
26 | amb | 2 | |
27 | |||
28 | int main(int argc,char** argv) | ||
29 | { | ||
30 | amb | 97 | NodesX *OSMNodes; |
31 | SegmentsX *OSMSegments,*SuperSegments=NULL; | ||
32 | WaysX *OSMWays; | ||
33 | amb | 58 | int iteration=0,quit=0; |
34 | amb | 150 | int max_iterations=10; |
35 | amb | 93 | char *dirname=NULL,*prefix=NULL,*filename; |
36 | amb | 82 | Profile profile; |
37 | amb | 75 | int i; |
38 | amb | 26 | |
39 | amb | 82 | /* Fill in the default profile. */ |
40 | amb | 31 | |
41 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
42 | amb | 75 | |
43 | amb | 82 | profile.allow=Allow_ALL; |
44 | amb | 75 | |
45 | amb | 82 | for(i=1;i<Way_Unknown;i++) |
46 | profile.highways[i]=1; | ||
47 | |||
48 | for(i=1;i<Way_Unknown;i++) | ||
49 | profile.speed[i]=0; /* Not used by planetsplitter */ | ||
50 | |||
51 | profile.oneway=1; /* Not used by planetsplitter */ | ||
52 | |||
53 | /* Parse the command line arguments */ | ||
54 | |||
55 | amb | 60 | while(--argc>=1) |
56 | { | ||
57 | amb | 101 | if(!strcmp(argv[argc],"--help")) |
58 | amb | 75 | goto usage; |
59 | amb | 101 | else if(!strncmp(argv[argc],"--dir=",6)) |
60 | dirname=&argv[argc][6]; | ||
61 | else if(!strncmp(argv[argc],"--prefix=",9)) | ||
62 | prefix=&argv[argc][9]; | ||
63 | else if(!strncmp(argv[argc],"--max-iterations=",17)) | ||
64 | max_iterations=atoi(&argv[argc][17]); | ||
65 | else if(!strncmp(argv[argc],"--transport=",12)) | ||
66 | amb | 82 | { |
67 | amb | 101 | profile.transport=TransportType(&argv[argc][12]); |
68 | amb | 82 | profile.allow=1<<(profile.transport-1); |
69 | } | ||
70 | amb | 101 | else if(!strncmp(argv[argc],"--not-highway=",14)) |
71 | amb | 75 | { |
72 | amb | 101 | Highway highway=HighwayType(&argv[argc][14]); |
73 | amb | 82 | profile.highways[highway]=0; |
74 | amb | 75 | } |
75 | amb | 60 | else |
76 | { | ||
77 | amb | 75 | usage: |
78 | |||
79 | fprintf(stderr,"Usage: planetsplitter\n" | ||
80 | amb | 150 | " [--help]\n" |
81 | amb | 101 | " [--dir=<name>] [--prefix=<name>]\n" |
82 | " [--max-iterations=<number>]\n" | ||
83 | " [--transport=<transport>]\n" | ||
84 | " [--not-highway=<highway> ...]\n" | ||
85 | amb | 75 | "\n" |
86 | amb | 82 | "<transport> defaults to all but can be set to:\n" |
87 | amb | 75 | "%s" |
88 | "\n" | ||
89 | amb | 82 | "<highway> can be selected from:\n" |
90 | amb | 75 | "%s", |
91 | TransportList(),HighwayList()); | ||
92 | |||
93 | amb | 60 | return(1); |
94 | } | ||
95 | } | ||
96 | amb | 26 | |
97 | amb | 89 | /* Create new variables */ |
98 | amb | 82 | |
99 | amb | 97 | OSMNodes=NewNodeList(); |
100 | OSMSegments=NewSegmentList(); | ||
101 | OSMWays=NewWayList(); | ||
102 | amb | 26 | |
103 | amb | 89 | /* Parse the file */ |
104 | amb | 2 | |
105 | amb | 89 | printf("\nParsing OSM Data\n================\n\n"); fflush(stdout); |
106 | amb | 2 | |
107 | amb | 97 | ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile); |
108 | amb | 80 | |
109 | amb | 89 | printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout); |
110 | amb | 8 | |
111 | amb | 89 | /* Sort the ways */ |
112 | amb | 80 | |
113 | amb | 97 | SortWayList(OSMWays); |
114 | amb | 87 | |
115 | amb | 89 | /* Sort the segments */ |
116 | amb | 87 | |
117 | amb | 97 | SortSegmentList(OSMSegments); |
118 | amb | 84 | |
119 | amb | 89 | /* Remove bad segments */ |
120 | amb | 84 | |
121 | amb | 97 | RemoveBadSegments(OSMSegments); |
122 | amb | 87 | |
123 | amb | 97 | SortSegmentList(OSMSegments); |
124 | amb | 87 | |
125 | amb | 89 | /* Remove non-way nodes */ |
126 | amb | 41 | |
127 | amb | 97 | RemoveNonHighwayNodes(OSMNodes,OSMSegments); |
128 | amb | 41 | |
129 | amb | 97 | SortNodeList(OSMNodes); |
130 | amb | 41 | |
131 | amb | 89 | /* Measure the segments */ |
132 | amb | 66 | |
133 | amb | 97 | MeasureSegments(OSMSegments,OSMNodes); |
134 | amb | 66 | |
135 | |||
136 | amb | 58 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
137 | |||
138 | do | ||
139 | { | ||
140 | amb | 80 | printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout); |
141 | |||
142 | amb | 90 | if(iteration==0) |
143 | { | ||
144 | /* Select the super-nodes */ | ||
145 | amb | 58 | |
146 | amb | 97 | ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays,iteration); |
147 | amb | 58 | |
148 | amb | 90 | /* Select the super-segments */ |
149 | amb | 58 | |
150 | amb | 97 | SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration); |
151 | amb | 90 | } |
152 | else | ||
153 | { | ||
154 | amb | 97 | SegmentsX *SuperSegments2; |
155 | amb | 58 | |
156 | amb | 90 | /* Select the super-nodes */ |
157 | |||
158 | amb | 97 | ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays,iteration); |
159 | amb | 90 | |
160 | /* Select the super-segments */ | ||
161 | |||
162 | amb | 97 | SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration); |
163 | amb | 90 | |
164 | amb | 104 | if(SuperSegments->number==SuperSegments2->number) |
165 | quit=1; | ||
166 | |||
167 | amb | 97 | FreeSegmentList(SuperSegments); |
168 | amb | 90 | |
169 | amb | 97 | SuperSegments=SuperSegments2; |
170 | amb | 90 | } |
171 | |||
172 | amb | 66 | /* Sort the super-segments */ |
173 | amb | 58 | |
174 | amb | 97 | SortSegmentList(SuperSegments); |
175 | amb | 58 | |
176 | amb | 89 | iteration++; |
177 | amb | 58 | |
178 | amb | 89 | if(iteration>max_iterations) |
179 | quit=1; | ||
180 | } | ||
181 | while(!quit); | ||
182 | amb | 58 | |
183 | amb | 104 | printf("\n"); fflush(stdout); |
184 | amb | 58 | |
185 | amb | 104 | /* Mark the super-nodes */ |
186 | amb | 66 | |
187 | amb | 104 | MarkSuperNodes(OSMNodes,iteration); |
188 | amb | 66 | |
189 | amb | 104 | /* Merge the super-segments */ |
190 | |||
191 | MergeSuperSegments(OSMSegments,SuperSegments); | ||
192 | |||
193 | amb | 97 | FreeSegmentList(SuperSegments); |
194 | amb | 58 | |
195 | amb | 90 | /* Sort the segments */ |
196 | amb | 58 | |
197 | amb | 97 | SortSegmentList(OSMSegments); |
198 | amb | 90 | |
199 | amb | 104 | /* Rotate segments so that node1<node2 */ |
200 | amb | 90 | |
201 | amb | 104 | RotateSegments(OSMSegments,OSMNodes); |
202 | amb | 90 | |
203 | amb | 104 | /* Sort the segments */ |
204 | |||
205 | SortSegmentList(OSMSegments); | ||
206 | |||
207 | /* Remove duplicated segments */ | ||
208 | |||
209 | DeduplicateSegments(OSMSegments,OSMNodes,OSMWays); | ||
210 | |||
211 | /* Sort the segments */ | ||
212 | |||
213 | SortSegmentList(OSMSegments); | ||
214 | |||
215 | /* Fix the segment and node indexes */ | ||
216 | |||
217 | IndexNodes(OSMNodes,OSMSegments); | ||
218 | |||
219 | IndexSegments(OSMSegments,OSMNodes); | ||
220 | |||
221 | amb | 89 | /* Write out the nodes */ |
222 | amb | 58 | |
223 | amb | 95 | filename=(char*)malloc((dirname?strlen(dirname):0)+(prefix?strlen(prefix):0)+16); |
224 | |||
225 | amb | 93 | sprintf(filename,"%s%s%s%snodes.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
226 | amb | 97 | SaveNodeList(OSMNodes,filename); |
227 | amb | 58 | |
228 | amb | 89 | /* Write out the segments */ |
229 | amb | 58 | |
230 | amb | 93 | sprintf(filename,"%s%s%s%ssegments.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
231 | amb | 97 | SaveSegmentList(OSMSegments,filename); |
232 | amb | 58 | |
233 | amb | 89 | /* Write out the ways */ |
234 | amb | 58 | |
235 | amb | 93 | sprintf(filename,"%s%s%s%sways.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
236 | amb | 97 | SaveWayList(OSMWays,filename); |
237 | amb | 58 | |
238 | amb | 2 | return(0); |
239 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |