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 162 -
(hide annotations)
(download)
(as text)
Thu Apr 23 17:37:04 2009 UTC (15 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 5985 byte(s)
Thu Apr 23 17:37:04 2009 UTC (15 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 5985 byte(s)
Move the filename generation to a new function.
1 | amb | 2 | /*************************************** |
2 | amb | 162 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.35 2009-04-23 17:37:04 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 | 96 | #include "types.h" |
30 | amb | 109 | #include "functions.h" |
31 | #include "nodesx.h" | ||
32 | #include "segmentsx.h" | ||
33 | #include "waysx.h" | ||
34 | #include "superx.h" | ||
35 | amb | 82 | #include "profiles.h" |
36 | amb | 2 | |
37 | |||
38 | int main(int argc,char** argv) | ||
39 | { | ||
40 | amb | 97 | NodesX *OSMNodes; |
41 | SegmentsX *OSMSegments,*SuperSegments=NULL; | ||
42 | WaysX *OSMWays; | ||
43 | amb | 58 | int iteration=0,quit=0; |
44 | amb | 150 | int max_iterations=10; |
45 | amb | 162 | char *dirname=NULL,*prefix=NULL; |
46 | amb | 82 | Profile profile; |
47 | amb | 75 | int i; |
48 | amb | 26 | |
49 | amb | 82 | /* Fill in the default profile. */ |
50 | amb | 31 | |
51 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
52 | amb | 75 | |
53 | amb | 82 | profile.allow=Allow_ALL; |
54 | amb | 75 | |
55 | amb | 82 | for(i=1;i<Way_Unknown;i++) |
56 | profile.highways[i]=1; | ||
57 | |||
58 | for(i=1;i<Way_Unknown;i++) | ||
59 | profile.speed[i]=0; /* Not used by planetsplitter */ | ||
60 | |||
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 | 82 | profile.highways[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 | 89 | printf("\nParsing OSM Data\n================\n\n"); fflush(stdout); |
116 | amb | 2 | |
117 | amb | 97 | ParseXML(stdin,OSMNodes,OSMSegments,OSMWays,&profile); |
118 | amb | 80 | |
119 | amb | 89 | printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout); |
120 | amb | 8 | |
121 | amb | 89 | /* Sort the ways */ |
122 | amb | 80 | |
123 | amb | 97 | SortWayList(OSMWays); |
124 | amb | 87 | |
125 | amb | 89 | /* Sort the segments */ |
126 | amb | 87 | |
127 | amb | 97 | SortSegmentList(OSMSegments); |
128 | amb | 84 | |
129 | amb | 89 | /* Remove bad segments */ |
130 | amb | 84 | |
131 | amb | 97 | RemoveBadSegments(OSMSegments); |
132 | amb | 87 | |
133 | amb | 97 | SortSegmentList(OSMSegments); |
134 | amb | 87 | |
135 | amb | 89 | /* Remove non-way nodes */ |
136 | amb | 41 | |
137 | amb | 97 | RemoveNonHighwayNodes(OSMNodes,OSMSegments); |
138 | amb | 41 | |
139 | amb | 97 | SortNodeList(OSMNodes); |
140 | amb | 41 | |
141 | amb | 89 | /* Measure the segments */ |
142 | amb | 66 | |
143 | amb | 97 | MeasureSegments(OSMSegments,OSMNodes); |
144 | amb | 66 | |
145 | |||
146 | amb | 58 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
147 | |||
148 | do | ||
149 | { | ||
150 | amb | 80 | printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout); |
151 | |||
152 | amb | 90 | if(iteration==0) |
153 | { | ||
154 | /* Select the super-nodes */ | ||
155 | amb | 58 | |
156 | amb | 97 | ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays,iteration); |
157 | amb | 58 | |
158 | amb | 90 | /* Select the super-segments */ |
159 | amb | 58 | |
160 | amb | 97 | SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,iteration); |
161 | amb | 90 | } |
162 | else | ||
163 | { | ||
164 | amb | 97 | SegmentsX *SuperSegments2; |
165 | amb | 58 | |
166 | amb | 90 | /* Select the super-nodes */ |
167 | |||
168 | amb | 97 | ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays,iteration); |
169 | amb | 90 | |
170 | /* Select the super-segments */ | ||
171 | |||
172 | amb | 97 | SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays,iteration); |
173 | amb | 90 | |
174 | amb | 104 | if(SuperSegments->number==SuperSegments2->number) |
175 | quit=1; | ||
176 | |||
177 | amb | 97 | FreeSegmentList(SuperSegments); |
178 | amb | 90 | |
179 | amb | 97 | SuperSegments=SuperSegments2; |
180 | amb | 90 | } |
181 | |||
182 | amb | 66 | /* Sort the super-segments */ |
183 | amb | 58 | |
184 | amb | 97 | SortSegmentList(SuperSegments); |
185 | amb | 58 | |
186 | amb | 89 | iteration++; |
187 | amb | 58 | |
188 | amb | 89 | if(iteration>max_iterations) |
189 | quit=1; | ||
190 | } | ||
191 | while(!quit); | ||
192 | amb | 58 | |
193 | amb | 104 | printf("\n"); fflush(stdout); |
194 | amb | 58 | |
195 | amb | 104 | /* Mark the super-nodes */ |
196 | amb | 66 | |
197 | amb | 104 | MarkSuperNodes(OSMNodes,iteration); |
198 | amb | 66 | |
199 | amb | 104 | /* Merge the super-segments */ |
200 | |||
201 | MergeSuperSegments(OSMSegments,SuperSegments); | ||
202 | |||
203 | amb | 97 | FreeSegmentList(SuperSegments); |
204 | amb | 58 | |
205 | amb | 90 | /* Sort the segments */ |
206 | amb | 58 | |
207 | amb | 97 | SortSegmentList(OSMSegments); |
208 | amb | 90 | |
209 | amb | 104 | /* Rotate segments so that node1<node2 */ |
210 | amb | 90 | |
211 | amb | 104 | RotateSegments(OSMSegments,OSMNodes); |
212 | amb | 90 | |
213 | amb | 104 | /* Sort the segments */ |
214 | |||
215 | SortSegmentList(OSMSegments); | ||
216 | |||
217 | /* Remove duplicated segments */ | ||
218 | |||
219 | DeduplicateSegments(OSMSegments,OSMNodes,OSMWays); | ||
220 | |||
221 | /* Sort the segments */ | ||
222 | |||
223 | SortSegmentList(OSMSegments); | ||
224 | |||
225 | /* Fix the segment and node indexes */ | ||
226 | |||
227 | IndexNodes(OSMNodes,OSMSegments); | ||
228 | |||
229 | IndexSegments(OSMSegments,OSMNodes); | ||
230 | |||
231 | amb | 89 | /* Write out the nodes */ |
232 | amb | 58 | |
233 | amb | 162 | SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem")); |
234 | amb | 95 | |
235 | amb | 89 | /* Write out the segments */ |
236 | amb | 58 | |
237 | amb | 162 | SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem")); |
238 | amb | 58 | |
239 | amb | 89 | /* Write out the ways */ |
240 | amb | 58 | |
241 | amb | 162 | SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem")); |
242 | amb | 58 | |
243 | amb | 2 | return(0); |
244 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |