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 224 -
(hide annotations)
(download)
(as text)
Thu Jul 9 18:56:50 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 6076 byte(s)
Thu Jul 9 18:56:50 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 6076 byte(s)
Separate the sorting of Ways from compacting of Ways.
1 | amb | 2 | /*************************************** |
2 | amb | 224 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.45 2009-07-09 18:56:50 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 | 2 | |
39 | |||
40 | int main(int argc,char** argv) | ||
41 | { | ||
42 | amb | 97 | NodesX *OSMNodes; |
43 | SegmentsX *OSMSegments,*SuperSegments=NULL; | ||
44 | WaysX *OSMWays; | ||
45 | amb | 58 | int iteration=0,quit=0; |
46 | amb | 150 | int max_iterations=10; |
47 | amb | 162 | char *dirname=NULL,*prefix=NULL; |
48 | amb | 220 | Profile profile={0}; |
49 | amb | 75 | int i; |
50 | amb | 26 | |
51 | amb | 82 | /* Fill in the default profile. */ |
52 | amb | 31 | |
53 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
54 | amb | 75 | |
55 | amb | 82 | profile.allow=Allow_ALL; |
56 | amb | 75 | |
57 | amb | 82 | for(i=1;i<Way_Unknown;i++) |
58 | amb | 166 | profile.highway[i]=1; |
59 | amb | 82 | |
60 | profile.oneway=1; /* Not used by planetsplitter */ | ||
61 | |||
62 | /* Parse the command line arguments */ | ||
63 | |||
64 | amb | 60 | while(--argc>=1) |
65 | { | ||
66 | amb | 101 | if(!strcmp(argv[argc],"--help")) |
67 | amb | 75 | goto usage; |
68 | amb | 101 | else if(!strncmp(argv[argc],"--dir=",6)) |
69 | dirname=&argv[argc][6]; | ||
70 | else if(!strncmp(argv[argc],"--prefix=",9)) | ||
71 | prefix=&argv[argc][9]; | ||
72 | else if(!strncmp(argv[argc],"--max-iterations=",17)) | ||
73 | max_iterations=atoi(&argv[argc][17]); | ||
74 | else if(!strncmp(argv[argc],"--transport=",12)) | ||
75 | amb | 82 | { |
76 | amb | 101 | profile.transport=TransportType(&argv[argc][12]); |
77 | amb | 82 | profile.allow=1<<(profile.transport-1); |
78 | } | ||
79 | amb | 101 | else if(!strncmp(argv[argc],"--not-highway=",14)) |
80 | amb | 75 | { |
81 | amb | 101 | Highway highway=HighwayType(&argv[argc][14]); |
82 | amb | 166 | profile.highway[highway]=0; |
83 | amb | 75 | } |
84 | amb | 60 | else |
85 | { | ||
86 | amb | 75 | usage: |
87 | |||
88 | fprintf(stderr,"Usage: planetsplitter\n" | ||
89 | amb | 150 | " [--help]\n" |
90 | amb | 101 | " [--dir=<name>] [--prefix=<name>]\n" |
91 | " [--max-iterations=<number>]\n" | ||
92 | " [--transport=<transport>]\n" | ||
93 | " [--not-highway=<highway> ...]\n" | ||
94 | amb | 75 | "\n" |
95 | amb | 82 | "<transport> defaults to all but can be set to:\n" |
96 | amb | 75 | "%s" |
97 | "\n" | ||
98 | amb | 82 | "<highway> can be selected from:\n" |
99 | amb | 75 | "%s", |
100 | TransportList(),HighwayList()); | ||
101 | |||
102 | amb | 60 | return(1); |
103 | } | ||
104 | } | ||
105 | amb | 26 | |
106 | amb | 89 | /* Create new variables */ |
107 | amb | 82 | |
108 | amb | 97 | OSMNodes=NewNodeList(); |
109 | OSMSegments=NewSegmentList(); | ||
110 | OSMWays=NewWayList(); | ||
111 | amb | 26 | |
112 | amb | 89 | /* Parse the file */ |
113 | amb | 2 | |
114 | amb | 89 | printf("\nParsing OSM Data\n================\n\n"); fflush(stdout); |
115 | amb | 2 | |
116 | amb | 97 | ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile); |
117 | amb | 80 | |
118 | amb | 89 | printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout); |
119 | amb | 8 | |
120 | amb | 89 | /* Sort the ways */ |
121 | amb | 80 | |
122 | amb | 97 | SortWayList(OSMWays); |
123 | amb | 87 | |
124 | amb | 89 | /* Sort the segments */ |
125 | amb | 87 | |
126 | amb | 97 | SortSegmentList(OSMSegments); |
127 | amb | 84 | |
128 | amb | 195 | /* Sort the nodes */ |
129 | |||
130 | SortNodeList(OSMNodes); | ||
131 | |||
132 | amb | 224 | /* Compact the ways */ |
133 | |||
134 | CompactWays(OSMWays); | ||
135 | |||
136 | amb | 89 | /* Remove bad segments */ |
137 | amb | 84 | |
138 | amb | 204 | RemoveBadSegments(OSMNodes,OSMSegments); |
139 | amb | 87 | |
140 | amb | 97 | SortSegmentList(OSMSegments); |
141 | amb | 87 | |
142 | amb | 89 | /* Remove non-way nodes */ |
143 | amb | 41 | |
144 | amb | 97 | RemoveNonHighwayNodes(OSMNodes,OSMSegments); |
145 | amb | 41 | |
146 | amb | 97 | SortNodeList(OSMNodes); |
147 | amb | 41 | |
148 | amb | 89 | /* Measure the segments */ |
149 | amb | 66 | |
150 | amb | 97 | MeasureSegments(OSMSegments,OSMNodes); |
151 | amb | 66 | |
152 | |||
153 | amb | 58 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
154 | |||
155 | do | ||
156 | { | ||
157 | amb | 80 | printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout); |
158 | |||
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 | 89 | iteration++; |
194 | amb | 58 | |
195 | amb | 89 | if(iteration>max_iterations) |
196 | quit=1; | ||
197 | } | ||
198 | while(!quit); | ||
199 | amb | 58 | |
200 | amb | 104 | printf("\n"); fflush(stdout); |
201 | amb | 58 | |
202 | amb | 104 | /* Merge the super-segments */ |
203 | |||
204 | MergeSuperSegments(OSMSegments,SuperSegments); | ||
205 | |||
206 | amb | 97 | FreeSegmentList(SuperSegments); |
207 | amb | 58 | |
208 | amb | 97 | SortSegmentList(OSMSegments); |
209 | amb | 90 | |
210 | amb | 104 | /* Rotate segments so that node1<node2 */ |
211 | amb | 90 | |
212 | amb | 212 | RotateSegments(OSMSegments); |
213 | amb | 90 | |
214 | amb | 104 | SortSegmentList(OSMSegments); |
215 | |||
216 | /* Remove duplicated segments */ | ||
217 | |||
218 | amb | 212 | DeduplicateSegments(OSMSegments,OSMWays); |
219 | amb | 104 | |
220 | SortSegmentList(OSMSegments); | ||
221 | |||
222 | amb | 212 | /* Sort the node list geographically */ |
223 | amb | 209 | |
224 | amb | 212 | SortNodeListGeographically(OSMNodes); |
225 | |||
226 | /* Create the real segments and nodes */ | ||
227 | |||
228 | CreateRealNodes(OSMNodes,iteration); | ||
229 | |||
230 | amb | 209 | CreateRealSegments(OSMSegments,OSMWays); |
231 | |||
232 | amb | 104 | /* Fix the segment and node indexes */ |
233 | |||
234 | amb | 209 | IndexNodes(OSMNodes,OSMSegments); |
235 | amb | 104 | |
236 | IndexSegments(OSMSegments,OSMNodes); | ||
237 | |||
238 | amb | 89 | /* Write out the nodes */ |
239 | amb | 58 | |
240 | amb | 162 | SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem")); |
241 | amb | 95 | |
242 | amb | 89 | /* Write out the segments */ |
243 | amb | 58 | |
244 | amb | 162 | SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem")); |
245 | amb | 58 | |
246 | amb | 89 | /* Write out the ways */ |
247 | amb | 58 | |
248 | amb | 162 | SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem")); |
249 | amb | 58 | |
250 | amb | 2 | return(0); |
251 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |