Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 203 - (show annotations) (download) (as text)
Thu Jun 25 17:46:46 2009 UTC (15 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 6093 byte(s)
Reduce the number of ways in the output by compacting them (sharing the same
information between identical ways).

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

Properties

Name Value
cvs:description Planet file splitter.