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 243 -
(hide annotations)
(download)
(as text)
Wed Aug 19 18:02:08 2009 UTC (15 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 6411 byte(s)
Wed Aug 19 18:02:08 2009 UTC (15 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 6411 byte(s)
Remove "sorted" parameter in data structure and change assert statements.
1 | amb | 2 | /*************************************** |
2 | amb | 243 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.50 2009-08-19 18:02:08 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 | int main(int argc,char** argv) | ||
42 | { | ||
43 | amb | 97 | NodesX *OSMNodes; |
44 | SegmentsX *OSMSegments,*SuperSegments=NULL; | ||
45 | WaysX *OSMWays; | ||
46 | amb | 58 | int iteration=0,quit=0; |
47 | amb | 150 | int max_iterations=10; |
48 | amb | 162 | char *dirname=NULL,*prefix=NULL; |
49 | amb | 220 | Profile profile={0}; |
50 | amb | 75 | int i; |
51 | amb | 26 | |
52 | amb | 82 | /* Fill in the default profile. */ |
53 | amb | 31 | |
54 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
55 | amb | 75 | |
56 | amb | 82 | profile.allow=Allow_ALL; |
57 | amb | 75 | |
58 | amb | 82 | for(i=1;i<Way_Unknown;i++) |
59 | amb | 166 | profile.highway[i]=1; |
60 | amb | 82 | |
61 | profile.oneway=1; /* Not used by planetsplitter */ | ||
62 | |||
63 | /* Parse the command line arguments */ | ||
64 | |||
65 | amb | 60 | while(--argc>=1) |
66 | { | ||
67 | amb | 101 | if(!strcmp(argv[argc],"--help")) |
68 | amb | 75 | goto usage; |
69 | amb | 101 | else if(!strncmp(argv[argc],"--dir=",6)) |
70 | dirname=&argv[argc][6]; | ||
71 | else if(!strncmp(argv[argc],"--prefix=",9)) | ||
72 | prefix=&argv[argc][9]; | ||
73 | else if(!strncmp(argv[argc],"--max-iterations=",17)) | ||
74 | max_iterations=atoi(&argv[argc][17]); | ||
75 | else if(!strncmp(argv[argc],"--transport=",12)) | ||
76 | amb | 82 | { |
77 | amb | 101 | profile.transport=TransportType(&argv[argc][12]); |
78 | amb | 82 | profile.allow=1<<(profile.transport-1); |
79 | } | ||
80 | amb | 101 | else if(!strncmp(argv[argc],"--not-highway=",14)) |
81 | amb | 75 | { |
82 | amb | 101 | Highway highway=HighwayType(&argv[argc][14]); |
83 | amb | 166 | profile.highway[highway]=0; |
84 | amb | 75 | } |
85 | amb | 60 | else |
86 | { | ||
87 | amb | 75 | usage: |
88 | |||
89 | fprintf(stderr,"Usage: planetsplitter\n" | ||
90 | amb | 150 | " [--help]\n" |
91 | amb | 101 | " [--dir=<name>] [--prefix=<name>]\n" |
92 | " [--max-iterations=<number>]\n" | ||
93 | " [--transport=<transport>]\n" | ||
94 | " [--not-highway=<highway> ...]\n" | ||
95 | amb | 75 | "\n" |
96 | amb | 82 | "<transport> defaults to all but can be set to:\n" |
97 | amb | 75 | "%s" |
98 | "\n" | ||
99 | amb | 82 | "<highway> can be selected from:\n" |
100 | amb | 75 | "%s", |
101 | TransportList(),HighwayList()); | ||
102 | |||
103 | amb | 60 | return(1); |
104 | } | ||
105 | } | ||
106 | amb | 26 | |
107 | amb | 89 | /* Create new variables */ |
108 | amb | 82 | |
109 | amb | 97 | OSMNodes=NewNodeList(); |
110 | OSMSegments=NewSegmentList(); | ||
111 | OSMWays=NewWayList(); | ||
112 | amb | 26 | |
113 | amb | 89 | /* Parse the file */ |
114 | amb | 2 | |
115 | amb | 229 | printf("\nParse OSM Data\n==============\n\n"); |
116 | amb | 227 | fflush(stdout); |
117 | amb | 2 | |
118 | amb | 97 | ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile); |
119 | amb | 80 | |
120 | amb | 229 | /* Process the data */ |
121 | |||
122 | printf("\nProcess OSM Data\n================\n\n"); | ||
123 | amb | 227 | fflush(stdout); |
124 | amb | 8 | |
125 | amb | 243 | /* Compact the ways */ |
126 | amb | 80 | |
127 | amb | 97 | SortWayList(OSMWays); |
128 | amb | 87 | |
129 | amb | 243 | CompactWays(OSMWays); |
130 | |||
131 | amb | 89 | /* Sort the segments */ |
132 | amb | 87 | |
133 | amb | 97 | SortSegmentList(OSMSegments); |
134 | amb | 84 | |
135 | amb | 243 | /* Remove non-way nodes */ |
136 | amb | 195 | |
137 | amb | 243 | RemoveNonHighwayNodes(OSMNodes,OSMSegments); |
138 | |||
139 | amb | 195 | SortNodeList(OSMNodes); |
140 | |||
141 | amb | 89 | /* Remove bad segments */ |
142 | amb | 84 | |
143 | amb | 204 | RemoveBadSegments(OSMNodes,OSMSegments); |
144 | amb | 87 | |
145 | amb | 97 | SortSegmentList(OSMSegments); |
146 | amb | 87 | |
147 | amb | 89 | /* Measure the segments */ |
148 | amb | 66 | |
149 | amb | 97 | MeasureSegments(OSMSegments,OSMNodes); |
150 | amb | 66 | |
151 | |||
152 | amb | 58 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
153 | |||
154 | do | ||
155 | { | ||
156 | amb | 229 | printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":""); |
157 | amb | 227 | fflush(stdout); |
158 | amb | 80 | |
159 | amb | 90 | if(iteration==0) |
160 | { | ||
161 | /* Select the super-nodes */ | ||
162 | amb | 58 | |
163 | amb | 214 | ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays); |
164 | amb | 58 | |
165 | amb | 90 | /* Select the super-segments */ |
166 | amb | 58 | |
167 | amb | 97 | SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration); |
168 | amb | 90 | } |
169 | else | ||
170 | { | ||
171 | amb | 97 | SegmentsX *SuperSegments2; |
172 | amb | 58 | |
173 | amb | 90 | /* Select the super-nodes */ |
174 | |||
175 | amb | 214 | ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays); |
176 | amb | 90 | |
177 | /* Select the super-segments */ | ||
178 | |||
179 | amb | 97 | SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration); |
180 | amb | 90 | |
181 | amb | 104 | if(SuperSegments->number==SuperSegments2->number) |
182 | quit=1; | ||
183 | |||
184 | amb | 97 | FreeSegmentList(SuperSegments); |
185 | amb | 90 | |
186 | amb | 97 | SuperSegments=SuperSegments2; |
187 | amb | 90 | } |
188 | |||
189 | amb | 66 | /* Sort the super-segments */ |
190 | amb | 58 | |
191 | amb | 97 | SortSegmentList(SuperSegments); |
192 | amb | 58 | |
193 | amb | 229 | /* Remove duplicated super-segments */ |
194 | |||
195 | DeduplicateSegments(SuperSegments,OSMWays); | ||
196 | |||
197 | SortSegmentList(SuperSegments); | ||
198 | |||
199 | amb | 89 | iteration++; |
200 | amb | 58 | |
201 | amb | 89 | if(iteration>max_iterations) |
202 | quit=1; | ||
203 | } | ||
204 | while(!quit); | ||
205 | amb | 58 | |
206 | amb | 229 | /* Combine the super-segments */ |
207 | |||
208 | printf("\nCombine Segments and Super-Segments\n===================================\n\n"); | ||
209 | amb | 227 | fflush(stdout); |
210 | amb | 58 | |
211 | amb | 104 | /* Merge the super-segments */ |
212 | |||
213 | MergeSuperSegments(OSMSegments,SuperSegments); | ||
214 | |||
215 | amb | 97 | FreeSegmentList(SuperSegments); |
216 | amb | 58 | |
217 | amb | 97 | SortSegmentList(OSMSegments); |
218 | amb | 90 | |
219 | amb | 229 | /* Cross reference the nodes and segments */ |
220 | amb | 90 | |
221 | amb | 229 | printf("\nCross-Reference Nodes and Segments\n==================================\n\n"); |
222 | fflush(stdout); | ||
223 | amb | 90 | |
224 | amb | 212 | /* Sort the node list geographically */ |
225 | amb | 209 | |
226 | amb | 212 | SortNodeListGeographically(OSMNodes); |
227 | |||
228 | /* Create the real segments and nodes */ | ||
229 | |||
230 | CreateRealNodes(OSMNodes,iteration); | ||
231 | |||
232 | amb | 209 | CreateRealSegments(OSMSegments,OSMWays); |
233 | |||
234 | amb | 104 | /* Fix the segment and node indexes */ |
235 | |||
236 | amb | 209 | IndexNodes(OSMNodes,OSMSegments); |
237 | amb | 104 | |
238 | IndexSegments(OSMSegments,OSMNodes); | ||
239 | |||
240 | amb | 229 | /* Output the results */ |
241 | |||
242 | printf("\nWrite Out Database Files\n========================\n\n"); | ||
243 | fflush(stdout); | ||
244 | |||
245 | amb | 89 | /* Write out the nodes */ |
246 | amb | 58 | |
247 | amb | 162 | SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem")); |
248 | amb | 95 | |
249 | amb | 226 | FreeNodeList(OSMNodes); |
250 | |||
251 | amb | 89 | /* Write out the segments */ |
252 | amb | 58 | |
253 | amb | 162 | SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem")); |
254 | amb | 58 | |
255 | amb | 226 | FreeSegmentList(OSMSegments); |
256 | |||
257 | amb | 89 | /* Write out the ways */ |
258 | amb | 58 | |
259 | amb | 162 | SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem")); |
260 | amb | 58 | |
261 | amb | 226 | FreeWayList(OSMWays); |
262 | |||
263 | amb | 2 | return(0); |
264 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |