Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/visualiser.c
Parent Directory
|
Revision Log
Revision 780 -
(hide annotations)
(download)
(as text)
Sun Jun 5 18:19:50 2011 UTC (13 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 19657 byte(s)
Sun Jun 5 18:19:50 2011 UTC (13 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 19657 byte(s)
Replace int with appropriate defined types (mostly index_t, ll_bin_t and ll_bin2_t).
1 | amb | 184 | /*************************************** |
2 | Extract data from Routino. | ||
3 | |||
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | amb | 598 | This file Copyright 2008-2011 Andrew M. Bishop |
7 | amb | 184 | |
8 | This program is free software: you can redistribute it and/or modify | ||
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | ***************************************/ | ||
21 | |||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "types.h" | ||
28 | #include "visualiser.h" | ||
29 | #include "nodes.h" | ||
30 | #include "segments.h" | ||
31 | #include "ways.h" | ||
32 | amb | 623 | #include "relations.h" |
33 | amb | 184 | |
34 | |||
35 | amb | 760 | /* Limit types */ |
36 | |||
37 | amb | 184 | #define SPEED_LIMIT 1 |
38 | #define WEIGHT_LIMIT 2 | ||
39 | #define HEIGHT_LIMIT 3 | ||
40 | #define WIDTH_LIMIT 4 | ||
41 | #define LENGTH_LIMIT 5 | ||
42 | |||
43 | /* Local types */ | ||
44 | |||
45 | amb | 219 | typedef void (*callback_t)(index_t node,double latitude,double longitude); |
46 | amb | 184 | |
47 | /* Local variables */ | ||
48 | |||
49 | amb | 623 | static Nodes *OSMNodes; |
50 | static Segments *OSMSegments; | ||
51 | static Ways *OSMWays; | ||
52 | static Relations *OSMRelations; | ||
53 | amb | 184 | |
54 | amb | 219 | static double LatMin; |
55 | static double LatMax; | ||
56 | static double LonMin; | ||
57 | static double LonMax; | ||
58 | amb | 217 | |
59 | amb | 184 | static int limit_type=0; |
60 | |||
61 | /* Local functions */ | ||
62 | |||
63 | amb | 217 | static void find_all_nodes(Nodes *nodes,callback_t callback); |
64 | amb | 219 | static void output_junctions(index_t node,double latitude,double longitude); |
65 | static void output_super(index_t node,double latitude,double longitude); | ||
66 | static void output_oneway(index_t node,double latitude,double longitude); | ||
67 | amb | 623 | static void output_turnrestriction(index_t node,double latitude,double longitude); |
68 | amb | 219 | static void output_limits(index_t node,double latitude,double longitude); |
69 | amb | 184 | |
70 | |||
71 | /*++++++++++++++++++++++++++++++++++++++ | ||
72 | Output the data for junctions. | ||
73 | |||
74 | Nodes *nodes The set of nodes to use. | ||
75 | |||
76 | Segments *segments The set of segments to use. | ||
77 | |||
78 | Ways *ways The set of ways to use. | ||
79 | |||
80 | amb | 680 | Relations *relations The set of relations to use. |
81 | amb | 623 | |
82 | amb | 219 | double latmin The minimum latitude. |
83 | amb | 184 | |
84 | amb | 219 | double latmax The maximum latitude. |
85 | amb | 184 | |
86 | amb | 219 | double lonmin The minimum longitude. |
87 | amb | 184 | |
88 | amb | 219 | double lonmax The maximum longitude. |
89 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
90 | |||
91 | amb | 623 | void OutputJunctions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
92 | amb | 184 | { |
93 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
94 | |||
95 | OSMNodes=nodes; | ||
96 | OSMSegments=segments; | ||
97 | OSMWays=ways; | ||
98 | amb | 623 | OSMRelations=relations; |
99 | amb | 184 | |
100 | amb | 217 | LatMin=latmin; |
101 | LatMax=latmax; | ||
102 | LonMin=lonmin; | ||
103 | LonMax=lonmax; | ||
104 | |||
105 | amb | 184 | /* Iterate through the nodes and process them */ |
106 | |||
107 | amb | 217 | find_all_nodes(nodes,(callback_t)output_junctions); |
108 | amb | 184 | } |
109 | |||
110 | |||
111 | /*++++++++++++++++++++++++++++++++++++++ | ||
112 | amb | 680 | Process a single node as a junction (called as a callback). |
113 | amb | 184 | |
114 | index_t node The node to output. | ||
115 | |||
116 | amb | 219 | double latitude The latitude of the node. |
117 | amb | 184 | |
118 | amb | 219 | double longitude The longitude of the node. |
119 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
120 | |||
121 | amb | 219 | static void output_junctions(index_t node,double latitude,double longitude) |
122 | amb | 184 | { |
123 | Segment *segment; | ||
124 | Way *firstway; | ||
125 | int count=0,difference=0; | ||
126 | |||
127 | amb | 707 | segment=FirstSegment(OSMSegments,OSMNodes,node,1); |
128 | amb | 460 | firstway=LookupWay(OSMWays,segment->way,1); |
129 | amb | 184 | |
130 | do | ||
131 | { | ||
132 | amb | 460 | Way *way=LookupWay(OSMWays,segment->way,2); |
133 | amb | 184 | |
134 | if(IsNormalSegment(segment)) | ||
135 | count++; | ||
136 | |||
137 | amb | 201 | if(WaysCompare(firstway,way)) |
138 | amb | 184 | difference=1; |
139 | |||
140 | segment=NextSegment(OSMSegments,segment,node); | ||
141 | } | ||
142 | while(segment); | ||
143 | |||
144 | if(count!=2 || difference) | ||
145 | amb | 198 | printf("%.6f %.6f %d\n",radians_to_degrees(latitude),radians_to_degrees(longitude),count); |
146 | amb | 184 | } |
147 | |||
148 | |||
149 | /*++++++++++++++++++++++++++++++++++++++ | ||
150 | Output the data for super-nodes and super-segments. | ||
151 | |||
152 | Nodes *nodes The set of nodes to use. | ||
153 | |||
154 | Segments *segments The set of segments to use. | ||
155 | |||
156 | Ways *ways The set of ways to use. | ||
157 | |||
158 | amb | 680 | Relations *relations The set of relations to use. |
159 | amb | 623 | |
160 | amb | 219 | double latmin The minimum latitude. |
161 | amb | 184 | |
162 | amb | 219 | double latmax The maximum latitude. |
163 | amb | 184 | |
164 | amb | 219 | double lonmin The minimum longitude. |
165 | amb | 184 | |
166 | amb | 219 | double lonmax The maximum longitude. |
167 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
168 | |||
169 | amb | 623 | void OutputSuper(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
170 | amb | 184 | { |
171 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
172 | |||
173 | OSMNodes=nodes; | ||
174 | OSMSegments=segments; | ||
175 | OSMWays=ways; | ||
176 | amb | 623 | OSMRelations=relations; |
177 | amb | 184 | |
178 | amb | 217 | LatMin=latmin; |
179 | LatMax=latmax; | ||
180 | LonMin=lonmin; | ||
181 | LonMax=lonmax; | ||
182 | |||
183 | amb | 184 | /* Iterate through the nodes and process them */ |
184 | |||
185 | amb | 217 | find_all_nodes(nodes,(callback_t)output_super); |
186 | amb | 184 | } |
187 | |||
188 | |||
189 | /*++++++++++++++++++++++++++++++++++++++ | ||
190 | amb | 680 | Process a single node as a super-node (called as a callback). |
191 | amb | 184 | |
192 | index_t node The node to output. | ||
193 | |||
194 | amb | 219 | double latitude The latitude of the node. |
195 | amb | 184 | |
196 | amb | 219 | double longitude The longitude of the node. |
197 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
198 | |||
199 | amb | 219 | static void output_super(index_t node,double latitude,double longitude) |
200 | amb | 184 | { |
201 | Segment *segment; | ||
202 | |||
203 | amb | 598 | if(!IsSuperNode(LookupNode(OSMNodes,node,1))) |
204 | amb | 184 | return; |
205 | |||
206 | amb | 198 | printf("%.6f %.6f n\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); |
207 | amb | 188 | |
208 | amb | 707 | segment=FirstSegment(OSMSegments,OSMNodes,node,1); |
209 | amb | 184 | |
210 | do | ||
211 | { | ||
212 | if(IsSuperSegment(segment)) | ||
213 | { | ||
214 | index_t othernode=OtherNode(segment,node); | ||
215 | amb | 219 | double lat,lon; |
216 | amb | 184 | |
217 | amb | 217 | GetLatLong(OSMNodes,othernode,&lat,&lon); |
218 | amb | 184 | |
219 | amb | 217 | if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax)) |
220 | amb | 198 | printf("%.6f %.6f s\n",radians_to_degrees(lat),radians_to_degrees(lon)); |
221 | amb | 184 | } |
222 | |||
223 | segment=NextSegment(OSMSegments,segment,node); | ||
224 | } | ||
225 | while(segment); | ||
226 | } | ||
227 | |||
228 | |||
229 | /*++++++++++++++++++++++++++++++++++++++ | ||
230 | Output the data for one-way segments. | ||
231 | |||
232 | Nodes *nodes The set of nodes to use. | ||
233 | |||
234 | Segments *segments The set of segments to use. | ||
235 | |||
236 | Ways *ways The set of ways to use. | ||
237 | |||
238 | amb | 680 | Relations *relations The set of relations to use. |
239 | amb | 623 | |
240 | amb | 219 | double latmin The minimum latitude. |
241 | amb | 184 | |
242 | amb | 219 | double latmax The maximum latitude. |
243 | amb | 184 | |
244 | amb | 219 | double lonmin The minimum longitude. |
245 | amb | 184 | |
246 | amb | 219 | double lonmax The maximum longitude. |
247 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
248 | |||
249 | amb | 623 | void OutputOneway(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
250 | amb | 184 | { |
251 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
252 | |||
253 | OSMNodes=nodes; | ||
254 | OSMSegments=segments; | ||
255 | OSMWays=ways; | ||
256 | amb | 623 | OSMRelations=relations; |
257 | amb | 184 | |
258 | amb | 217 | LatMin=latmin; |
259 | LatMax=latmax; | ||
260 | LonMin=lonmin; | ||
261 | LonMax=lonmax; | ||
262 | |||
263 | amb | 184 | /* Iterate through the nodes and process them */ |
264 | |||
265 | amb | 217 | find_all_nodes(nodes,(callback_t)output_oneway); |
266 | amb | 184 | } |
267 | |||
268 | |||
269 | /*++++++++++++++++++++++++++++++++++++++ | ||
270 | amb | 680 | Process a single node and all connected one-way segments (called as a callback). |
271 | amb | 184 | |
272 | index_t node The node to output. | ||
273 | |||
274 | amb | 219 | double latitude The latitude of the node. |
275 | amb | 184 | |
276 | amb | 219 | double longitude The longitude of the node. |
277 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
278 | |||
279 | amb | 219 | static void output_oneway(index_t node,double latitude,double longitude) |
280 | amb | 184 | { |
281 | Segment *segment; | ||
282 | |||
283 | amb | 707 | segment=FirstSegment(OSMSegments,OSMNodes,node,1); |
284 | amb | 184 | |
285 | do | ||
286 | { | ||
287 | if(IsNormalSegment(segment)) | ||
288 | { | ||
289 | index_t othernode=OtherNode(segment,node); | ||
290 | |||
291 | if(node>othernode) | ||
292 | { | ||
293 | amb | 219 | double lat,lon; |
294 | amb | 184 | |
295 | GetLatLong(OSMNodes,othernode,&lat,&lon); | ||
296 | |||
297 | if(IsOnewayFrom(segment,node)) | ||
298 | amb | 198 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon)); |
299 | amb | 184 | else if(IsOnewayFrom(segment,othernode)) |
300 | amb | 198 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude)); |
301 | amb | 184 | } |
302 | } | ||
303 | |||
304 | segment=NextSegment(OSMSegments,segment,node); | ||
305 | } | ||
306 | while(segment); | ||
307 | } | ||
308 | |||
309 | |||
310 | /*++++++++++++++++++++++++++++++++++++++ | ||
311 | amb | 623 | Output the data for turn restrictions. |
312 | |||
313 | Nodes *nodes The set of nodes to use. | ||
314 | |||
315 | Segments *segments The set of segments to use. | ||
316 | |||
317 | Ways *ways The set of ways to use. | ||
318 | |||
319 | amb | 680 | Relations *relations The set of relations to use. |
320 | amb | 623 | |
321 | double latmin The minimum latitude. | ||
322 | |||
323 | double latmax The maximum latitude. | ||
324 | |||
325 | double lonmin The minimum longitude. | ||
326 | |||
327 | double lonmax The maximum longitude. | ||
328 | ++++++++++++++++++++++++++++++++++++++*/ | ||
329 | |||
330 | void OutputTurnRestrictions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) | ||
331 | { | ||
332 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
333 | |||
334 | OSMNodes=nodes; | ||
335 | OSMSegments=segments; | ||
336 | OSMWays=ways; | ||
337 | OSMRelations=relations; | ||
338 | |||
339 | LatMin=latmin; | ||
340 | LatMax=latmax; | ||
341 | LonMin=lonmin; | ||
342 | LonMax=lonmax; | ||
343 | |||
344 | /* Iterate through the nodes and process them */ | ||
345 | |||
346 | find_all_nodes(nodes,(callback_t)output_turnrestriction); | ||
347 | } | ||
348 | |||
349 | |||
350 | /*++++++++++++++++++++++++++++++++++++++ | ||
351 | amb | 680 | Process a single node as the 'via' node for a turn restriction (called as a callback). |
352 | amb | 623 | |
353 | index_t node The node to output. | ||
354 | |||
355 | double latitude The latitude of the node. | ||
356 | |||
357 | double longitude The longitude of the node. | ||
358 | ++++++++++++++++++++++++++++++++++++++*/ | ||
359 | |||
360 | static void output_turnrestriction(index_t node,double latitude,double longitude) | ||
361 | { | ||
362 | index_t turnrelation=NO_RELATION; | ||
363 | |||
364 | if(!IsTurnRestrictedNode(LookupNode(OSMNodes,node,1))) | ||
365 | return; | ||
366 | |||
367 | turnrelation=FindFirstTurnRelation1(OSMRelations,node); | ||
368 | |||
369 | do | ||
370 | { | ||
371 | TurnRelation *relation; | ||
372 | Segment *from_segment,*to_segment; | ||
373 | index_t from_node,to_node; | ||
374 | double from_lat,from_lon,to_lat,to_lon; | ||
375 | |||
376 | relation=LookupTurnRelation(OSMRelations,turnrelation,1); | ||
377 | |||
378 | from_segment=LookupSegment(OSMSegments,relation->from,1); | ||
379 | amb | 707 | to_segment =LookupSegment(OSMSegments,relation->to ,2); |
380 | amb | 623 | |
381 | from_node=OtherNode(from_segment,node); | ||
382 | to_node=OtherNode(to_segment,node); | ||
383 | |||
384 | GetLatLong(OSMNodes,from_node,&from_lat,&from_lon); | ||
385 | GetLatLong(OSMNodes,to_node,&to_lat,&to_lon); | ||
386 | |||
387 | printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",radians_to_degrees(from_lat),radians_to_degrees(from_lon), | ||
388 | radians_to_degrees(latitude),radians_to_degrees(longitude), | ||
389 | radians_to_degrees(to_lat),radians_to_degrees(to_lon)); | ||
390 | |||
391 | turnrelation=FindNextTurnRelation1(OSMRelations,turnrelation); | ||
392 | } | ||
393 | while(turnrelation!=NO_RELATION); | ||
394 | } | ||
395 | |||
396 | |||
397 | /*++++++++++++++++++++++++++++++++++++++ | ||
398 | amb | 184 | Output the data for speed limits. |
399 | |||
400 | Nodes *nodes The set of nodes to use. | ||
401 | |||
402 | Segments *segments The set of segments to use. | ||
403 | |||
404 | Ways *ways The set of ways to use. | ||
405 | |||
406 | amb | 680 | Relations *relations The set of relations to use. |
407 | amb | 623 | |
408 | amb | 219 | double latmin The minimum latitude. |
409 | amb | 184 | |
410 | amb | 219 | double latmax The maximum latitude. |
411 | amb | 184 | |
412 | amb | 219 | double lonmin The minimum longitude. |
413 | amb | 184 | |
414 | amb | 219 | double lonmax The maximum longitude. |
415 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
416 | |||
417 | amb | 623 | void OutputSpeedLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
418 | amb | 184 | { |
419 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
420 | |||
421 | OSMNodes=nodes; | ||
422 | OSMSegments=segments; | ||
423 | OSMWays=ways; | ||
424 | amb | 623 | OSMRelations=relations; |
425 | amb | 184 | |
426 | amb | 217 | LatMin=latmin; |
427 | LatMax=latmax; | ||
428 | LonMin=lonmin; | ||
429 | LonMax=lonmax; | ||
430 | |||
431 | amb | 184 | /* Iterate through the nodes and process them */ |
432 | |||
433 | limit_type=SPEED_LIMIT; | ||
434 | |||
435 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
436 | amb | 184 | } |
437 | |||
438 | |||
439 | /*++++++++++++++++++++++++++++++++++++++ | ||
440 | Output the data for weight limits. | ||
441 | |||
442 | Nodes *nodes The set of nodes to use. | ||
443 | |||
444 | Segments *segments The set of segments to use. | ||
445 | |||
446 | Ways *ways The set of ways to use. | ||
447 | |||
448 | amb | 680 | Relations *relations The set of relations to use. |
449 | amb | 623 | |
450 | amb | 219 | double latmin The minimum latitude. |
451 | amb | 184 | |
452 | amb | 219 | double latmax The maximum latitude. |
453 | amb | 184 | |
454 | amb | 219 | double lonmin The minimum longitude. |
455 | amb | 184 | |
456 | amb | 219 | double lonmax The maximum longitude. |
457 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
458 | |||
459 | amb | 623 | void OutputWeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
460 | amb | 184 | { |
461 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
462 | |||
463 | OSMNodes=nodes; | ||
464 | OSMSegments=segments; | ||
465 | OSMWays=ways; | ||
466 | amb | 623 | OSMRelations=relations; |
467 | amb | 184 | |
468 | amb | 217 | LatMin=latmin; |
469 | LatMax=latmax; | ||
470 | LonMin=lonmin; | ||
471 | LonMax=lonmax; | ||
472 | |||
473 | amb | 184 | /* Iterate through the nodes and process them */ |
474 | |||
475 | limit_type=WEIGHT_LIMIT; | ||
476 | |||
477 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
478 | amb | 184 | } |
479 | |||
480 | |||
481 | /*++++++++++++++++++++++++++++++++++++++ | ||
482 | Output the data for height limits. | ||
483 | |||
484 | Nodes *nodes The set of nodes to use. | ||
485 | |||
486 | Segments *segments The set of segments to use. | ||
487 | |||
488 | Ways *ways The set of ways to use. | ||
489 | |||
490 | amb | 680 | Relations *relations The set of relations to use. |
491 | amb | 623 | |
492 | amb | 219 | double latmin The minimum latitude. |
493 | amb | 184 | |
494 | amb | 219 | double latmax The maximum latitude. |
495 | amb | 184 | |
496 | amb | 219 | double lonmin The minimum longitude. |
497 | amb | 184 | |
498 | amb | 219 | double lonmax The maximum longitude. |
499 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
500 | |||
501 | amb | 623 | void OutputHeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
502 | amb | 184 | { |
503 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
504 | |||
505 | OSMNodes=nodes; | ||
506 | OSMSegments=segments; | ||
507 | OSMWays=ways; | ||
508 | amb | 623 | OSMRelations=relations; |
509 | amb | 184 | |
510 | amb | 217 | LatMin=latmin; |
511 | LatMax=latmax; | ||
512 | LonMin=lonmin; | ||
513 | LonMax=lonmax; | ||
514 | |||
515 | amb | 184 | /* Iterate through the nodes and process them */ |
516 | |||
517 | limit_type=HEIGHT_LIMIT; | ||
518 | |||
519 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
520 | amb | 184 | } |
521 | |||
522 | |||
523 | /*++++++++++++++++++++++++++++++++++++++ | ||
524 | Output the data for width limits. | ||
525 | |||
526 | Nodes *nodes The set of nodes to use. | ||
527 | |||
528 | Segments *segments The set of segments to use. | ||
529 | |||
530 | Ways *ways The set of ways to use. | ||
531 | |||
532 | amb | 680 | Relations *relations The set of relations to use. |
533 | amb | 623 | |
534 | amb | 219 | double latmin The minimum latitude. |
535 | amb | 184 | |
536 | amb | 219 | double latmax The maximum latitude. |
537 | amb | 184 | |
538 | amb | 219 | double lonmin The minimum longitude. |
539 | amb | 184 | |
540 | amb | 219 | double lonmax The maximum longitude. |
541 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
542 | |||
543 | amb | 623 | void OutputWidthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
544 | amb | 184 | { |
545 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
546 | |||
547 | OSMNodes=nodes; | ||
548 | OSMSegments=segments; | ||
549 | OSMWays=ways; | ||
550 | amb | 623 | OSMRelations=relations; |
551 | amb | 184 | |
552 | amb | 217 | LatMin=latmin; |
553 | LatMax=latmax; | ||
554 | LonMin=lonmin; | ||
555 | LonMax=lonmax; | ||
556 | |||
557 | amb | 184 | /* Iterate through the nodes and process them */ |
558 | |||
559 | limit_type=WIDTH_LIMIT; | ||
560 | |||
561 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
562 | amb | 184 | } |
563 | |||
564 | |||
565 | /*++++++++++++++++++++++++++++++++++++++ | ||
566 | Output the data for length limits. | ||
567 | |||
568 | Nodes *nodes The set of nodes to use. | ||
569 | |||
570 | Segments *segments The set of segments to use. | ||
571 | |||
572 | Ways *ways The set of ways to use. | ||
573 | |||
574 | amb | 680 | Relations *relations The set of relations to use. |
575 | amb | 623 | |
576 | amb | 219 | double latmin The minimum latitude. |
577 | amb | 184 | |
578 | amb | 219 | double latmax The maximum latitude. |
579 | amb | 184 | |
580 | amb | 219 | double lonmin The minimum longitude. |
581 | amb | 184 | |
582 | amb | 219 | double lonmax The maximum longitude. |
583 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
584 | |||
585 | amb | 623 | void OutputLengthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
586 | amb | 184 | { |
587 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
588 | |||
589 | OSMNodes=nodes; | ||
590 | OSMSegments=segments; | ||
591 | OSMWays=ways; | ||
592 | amb | 623 | OSMRelations=relations; |
593 | amb | 184 | |
594 | amb | 217 | LatMin=latmin; |
595 | LatMax=latmax; | ||
596 | LonMin=lonmin; | ||
597 | LonMax=lonmax; | ||
598 | |||
599 | amb | 184 | /* Iterate through the nodes and process them */ |
600 | |||
601 | limit_type=LENGTH_LIMIT; | ||
602 | |||
603 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
604 | amb | 184 | } |
605 | |||
606 | |||
607 | /*++++++++++++++++++++++++++++++++++++++ | ||
608 | amb | 680 | Process a single node as a speed, weight, height, length, width limit (called as a callback). |
609 | amb | 184 | |
610 | index_t node The node to output. | ||
611 | |||
612 | amb | 219 | double latitude The latitude of the node. |
613 | amb | 184 | |
614 | amb | 219 | double longitude The longitude of the node. |
615 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
616 | |||
617 | amb | 219 | static void output_limits(index_t node,double latitude,double longitude) |
618 | amb | 184 | { |
619 | amb | 760 | #define MAX_STORED 32 |
620 | Segment *segment,*segments[MAX_STORED]; | ||
621 | Way *ways[MAX_STORED]; | ||
622 | int limits[MAX_STORED]; | ||
623 | amb | 184 | int count=0; |
624 | int i,j,same=0; | ||
625 | |||
626 | amb | 707 | segment=FirstSegment(OSMSegments,OSMNodes,node,1); |
627 | amb | 184 | |
628 | do | ||
629 | { | ||
630 | amb | 760 | if(IsNormalSegment(segment) && count<MAX_STORED) |
631 | amb | 184 | { |
632 | amb | 460 | ways [count]=LookupWay(OSMWays,segment->way,1); |
633 | amb | 184 | segments[count]=segment; |
634 | |||
635 | switch(limit_type) | ||
636 | { | ||
637 | case SPEED_LIMIT: limits[count]=ways[count]->speed; break; | ||
638 | case WEIGHT_LIMIT: limits[count]=ways[count]->weight; break; | ||
639 | case HEIGHT_LIMIT: limits[count]=ways[count]->height; break; | ||
640 | case WIDTH_LIMIT: limits[count]=ways[count]->width; break; | ||
641 | case LENGTH_LIMIT: limits[count]=ways[count]->length; break; | ||
642 | } | ||
643 | |||
644 | amb | 217 | if(limits[count] || ways[count]->type<Way_Track) |
645 | count++; | ||
646 | amb | 184 | } |
647 | |||
648 | segment=NextSegment(OSMSegments,segment,node); | ||
649 | } | ||
650 | while(segment); | ||
651 | |||
652 | /* Nodes with only one limit are not interesting */ | ||
653 | |||
654 | if(count==1) | ||
655 | return; | ||
656 | |||
657 | /* Nodes with all segments the same limit is not interesting */ | ||
658 | |||
659 | same=0; | ||
660 | for(j=0;j<count;j++) | ||
661 | if(limits[0]==limits[j]) | ||
662 | same++; | ||
663 | |||
664 | if(same==count) | ||
665 | return; | ||
666 | |||
667 | /* Display the interesting speed limits */ | ||
668 | |||
669 | amb | 198 | printf("%.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); |
670 | amb | 184 | |
671 | for(i=0;i<count;i++) | ||
672 | { | ||
673 | same=0; | ||
674 | for(j=0;j<count;j++) | ||
675 | if(limits[i]==limits[j]) | ||
676 | same++; | ||
677 | |||
678 | if(count==2 || same!=(count-1)) | ||
679 | { | ||
680 | amb | 219 | double lat,lon; |
681 | amb | 184 | |
682 | GetLatLong(OSMNodes,OtherNode(segments[i],node),&lat,&lon); | ||
683 | |||
684 | switch(limit_type) | ||
685 | { | ||
686 | case SPEED_LIMIT: | ||
687 | amb | 219 | printf("%.6f %.6f %d\n",radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i])); |
688 | amb | 184 | break; |
689 | case WEIGHT_LIMIT: | ||
690 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i])); |
691 | amb | 184 | break; |
692 | case HEIGHT_LIMIT: | ||
693 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i])); |
694 | amb | 184 | break; |
695 | case WIDTH_LIMIT: | ||
696 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i])); |
697 | amb | 184 | break; |
698 | case LENGTH_LIMIT: | ||
699 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i])); |
700 | amb | 184 | break; |
701 | } | ||
702 | } | ||
703 | } | ||
704 | } | ||
705 | |||
706 | |||
707 | /*++++++++++++++++++++++++++++++++++++++ | ||
708 | A function to iterate through all nodes and call a callback function for each one. | ||
709 | |||
710 | amb | 681 | Nodes *nodes The set of nodes to use. |
711 | amb | 184 | |
712 | callback_t callback The callback function for each node. | ||
713 | ++++++++++++++++++++++++++++++++++++++*/ | ||
714 | |||
715 | amb | 217 | static void find_all_nodes(Nodes *nodes,callback_t callback) |
716 | amb | 184 | { |
717 | amb | 780 | ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->file.latzero; |
718 | ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->file.latzero; | ||
719 | ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->file.lonzero; | ||
720 | ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->file.lonzero; | ||
721 | ll_bin_t latb,lonb; | ||
722 | amb | 462 | index_t i,index1,index2; |
723 | amb | 184 | |
724 | /* Loop through all of the nodes. */ | ||
725 | |||
726 | for(latb=latminbin;latb<=latmaxbin;latb++) | ||
727 | for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) | ||
728 | { | ||
729 | amb | 780 | ll_bin2_t llbin=lonb*nodes->file.latbins+latb; |
730 | amb | 184 | |
731 | amb | 453 | if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins)) |
732 | amb | 184 | continue; |
733 | |||
734 | amb | 462 | index1=LookupNodeOffset(nodes,llbin); |
735 | index2=LookupNodeOffset(nodes,llbin+1); | ||
736 | |||
737 | for(i=index1;i<index2;i++) | ||
738 | amb | 184 | { |
739 | amb | 453 | Node *node=LookupNode(nodes,i,1); |
740 | amb | 184 | |
741 | amb | 453 | double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(node->latoffset)); |
742 | double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset)); | ||
743 | |||
744 | amb | 217 | if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax) |
745 | amb | 453 | (*callback)(i,lat,lon); |
746 | amb | 184 | } |
747 | } | ||
748 | } |
Properties
Name | Value |
---|---|
cvs:description | Functions for data visualisation. |