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 1057 -
(hide annotations)
(download)
(as text)
Sun Aug 12 14:09:12 2012 UTC (12 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 24361 byte(s)
Sun Aug 12 14:09:12 2012 UTC (12 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 24361 byte(s)
Fix for highway type visualiser (was missing one-way segments).
1 | amb | 184 | /*************************************** |
2 | Extract data from Routino. | ||
3 | |||
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | amb | 955 | This file Copyright 2008-2012 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 "nodes.h" | ||
29 | #include "segments.h" | ||
30 | #include "ways.h" | ||
31 | amb | 623 | #include "relations.h" |
32 | amb | 184 | |
33 | amb | 955 | #include "visualiser.h" |
34 | amb | 184 | |
35 | amb | 955 | |
36 | amb | 934 | /*+ The maximum number of segments per node (used to size temporary storage). +*/ |
37 | #define MAX_SEG_PER_NODE 32 | ||
38 | |||
39 | amb | 760 | /* Limit types */ |
40 | |||
41 | amb | 184 | #define SPEED_LIMIT 1 |
42 | #define WEIGHT_LIMIT 2 | ||
43 | #define HEIGHT_LIMIT 3 | ||
44 | #define WIDTH_LIMIT 4 | ||
45 | #define LENGTH_LIMIT 5 | ||
46 | |||
47 | /* Local types */ | ||
48 | |||
49 | amb | 219 | typedef void (*callback_t)(index_t node,double latitude,double longitude); |
50 | amb | 184 | |
51 | /* Local variables */ | ||
52 | |||
53 | amb | 623 | static Nodes *OSMNodes; |
54 | static Segments *OSMSegments; | ||
55 | static Ways *OSMWays; | ||
56 | static Relations *OSMRelations; | ||
57 | amb | 184 | |
58 | amb | 219 | static double LatMin; |
59 | static double LatMax; | ||
60 | static double LonMin; | ||
61 | static double LonMax; | ||
62 | amb | 217 | |
63 | amb | 184 | static int limit_type=0; |
64 | amb | 1003 | static Highway highways=Way_Count; |
65 | amb | 1002 | static Transports transports=Transports_None; |
66 | amb | 184 | |
67 | /* Local functions */ | ||
68 | |||
69 | amb | 217 | static void find_all_nodes(Nodes *nodes,callback_t callback); |
70 | amb | 219 | static void output_junctions(index_t node,double latitude,double longitude); |
71 | static void output_super(index_t node,double latitude,double longitude); | ||
72 | static void output_oneway(index_t node,double latitude,double longitude); | ||
73 | amb | 1003 | static void output_highway(index_t node,double latitude,double longitude); |
74 | amb | 1002 | static void output_transport(index_t node,double latitude,double longitude); |
75 | amb | 623 | static void output_turnrestriction(index_t node,double latitude,double longitude); |
76 | amb | 219 | static void output_limits(index_t node,double latitude,double longitude); |
77 | amb | 184 | |
78 | |||
79 | /*++++++++++++++++++++++++++++++++++++++ | ||
80 | Output the data for junctions. | ||
81 | |||
82 | Nodes *nodes The set of nodes to use. | ||
83 | |||
84 | Segments *segments The set of segments to use. | ||
85 | |||
86 | Ways *ways The set of ways to use. | ||
87 | |||
88 | amb | 680 | Relations *relations The set of relations to use. |
89 | amb | 623 | |
90 | amb | 219 | double latmin The minimum latitude. |
91 | amb | 184 | |
92 | amb | 219 | double latmax The maximum latitude. |
93 | amb | 184 | |
94 | amb | 219 | double lonmin The minimum longitude. |
95 | amb | 184 | |
96 | amb | 219 | double lonmax The maximum longitude. |
97 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
98 | |||
99 | amb | 623 | void OutputJunctions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
100 | amb | 184 | { |
101 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
102 | |||
103 | OSMNodes=nodes; | ||
104 | OSMSegments=segments; | ||
105 | OSMWays=ways; | ||
106 | amb | 623 | OSMRelations=relations; |
107 | amb | 184 | |
108 | amb | 217 | LatMin=latmin; |
109 | LatMax=latmax; | ||
110 | LonMin=lonmin; | ||
111 | LonMax=lonmax; | ||
112 | |||
113 | amb | 184 | /* Iterate through the nodes and process them */ |
114 | |||
115 | amb | 217 | find_all_nodes(nodes,(callback_t)output_junctions); |
116 | amb | 184 | } |
117 | |||
118 | |||
119 | /*++++++++++++++++++++++++++++++++++++++ | ||
120 | amb | 680 | Process a single node as a junction (called as a callback). |
121 | amb | 184 | |
122 | index_t node The node to output. | ||
123 | |||
124 | amb | 219 | double latitude The latitude of the node. |
125 | amb | 184 | |
126 | amb | 219 | double longitude The longitude of the node. |
127 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
128 | |||
129 | amb | 219 | static void output_junctions(index_t node,double latitude,double longitude) |
130 | amb | 184 | { |
131 | amb | 885 | Node *nodep=LookupNode(OSMNodes,node,1); |
132 | amb | 184 | Segment *segment; |
133 | Way *firstway; | ||
134 | int count=0,difference=0; | ||
135 | |||
136 | amb | 885 | segment=FirstSegment(OSMSegments,nodep,1); |
137 | amb | 460 | firstway=LookupWay(OSMWays,segment->way,1); |
138 | amb | 184 | |
139 | do | ||
140 | { | ||
141 | amb | 460 | Way *way=LookupWay(OSMWays,segment->way,2); |
142 | amb | 184 | |
143 | if(IsNormalSegment(segment)) | ||
144 | count++; | ||
145 | |||
146 | amb | 201 | if(WaysCompare(firstway,way)) |
147 | amb | 184 | difference=1; |
148 | |||
149 | segment=NextSegment(OSMSegments,segment,node); | ||
150 | } | ||
151 | while(segment); | ||
152 | |||
153 | if(count!=2 || difference) | ||
154 | amb | 198 | printf("%.6f %.6f %d\n",radians_to_degrees(latitude),radians_to_degrees(longitude),count); |
155 | amb | 184 | } |
156 | |||
157 | |||
158 | /*++++++++++++++++++++++++++++++++++++++ | ||
159 | Output the data for super-nodes and super-segments. | ||
160 | |||
161 | Nodes *nodes The set of nodes to use. | ||
162 | |||
163 | Segments *segments The set of segments to use. | ||
164 | |||
165 | Ways *ways The set of ways to use. | ||
166 | |||
167 | amb | 680 | Relations *relations The set of relations to use. |
168 | amb | 623 | |
169 | amb | 219 | double latmin The minimum latitude. |
170 | amb | 184 | |
171 | amb | 219 | double latmax The maximum latitude. |
172 | amb | 184 | |
173 | amb | 219 | double lonmin The minimum longitude. |
174 | amb | 184 | |
175 | amb | 219 | double lonmax The maximum longitude. |
176 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
177 | |||
178 | amb | 623 | void OutputSuper(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
179 | amb | 184 | { |
180 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
181 | |||
182 | OSMNodes=nodes; | ||
183 | OSMSegments=segments; | ||
184 | OSMWays=ways; | ||
185 | amb | 623 | OSMRelations=relations; |
186 | amb | 184 | |
187 | amb | 217 | LatMin=latmin; |
188 | LatMax=latmax; | ||
189 | LonMin=lonmin; | ||
190 | LonMax=lonmax; | ||
191 | |||
192 | amb | 184 | /* Iterate through the nodes and process them */ |
193 | |||
194 | amb | 217 | find_all_nodes(nodes,(callback_t)output_super); |
195 | amb | 184 | } |
196 | |||
197 | |||
198 | /*++++++++++++++++++++++++++++++++++++++ | ||
199 | amb | 680 | Process a single node as a super-node (called as a callback). |
200 | amb | 184 | |
201 | index_t node The node to output. | ||
202 | |||
203 | amb | 219 | double latitude The latitude of the node. |
204 | amb | 184 | |
205 | amb | 219 | double longitude The longitude of the node. |
206 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
207 | |||
208 | amb | 219 | static void output_super(index_t node,double latitude,double longitude) |
209 | amb | 184 | { |
210 | amb | 885 | Node *nodep=LookupNode(OSMNodes,node,1); |
211 | amb | 184 | Segment *segment; |
212 | |||
213 | amb | 885 | if(!IsSuperNode(nodep)) |
214 | amb | 184 | return; |
215 | |||
216 | amb | 198 | printf("%.6f %.6f n\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); |
217 | amb | 188 | |
218 | amb | 885 | segment=FirstSegment(OSMSegments,nodep,1); |
219 | amb | 184 | |
220 | do | ||
221 | { | ||
222 | if(IsSuperSegment(segment)) | ||
223 | { | ||
224 | index_t othernode=OtherNode(segment,node); | ||
225 | amb | 219 | double lat,lon; |
226 | amb | 184 | |
227 | amb | 217 | GetLatLong(OSMNodes,othernode,&lat,&lon); |
228 | amb | 184 | |
229 | amb | 217 | if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax)) |
230 | amb | 198 | printf("%.6f %.6f s\n",radians_to_degrees(lat),radians_to_degrees(lon)); |
231 | amb | 184 | } |
232 | |||
233 | segment=NextSegment(OSMSegments,segment,node); | ||
234 | } | ||
235 | while(segment); | ||
236 | } | ||
237 | |||
238 | |||
239 | /*++++++++++++++++++++++++++++++++++++++ | ||
240 | Output the data for one-way segments. | ||
241 | |||
242 | Nodes *nodes The set of nodes to use. | ||
243 | |||
244 | Segments *segments The set of segments to use. | ||
245 | |||
246 | Ways *ways The set of ways to use. | ||
247 | |||
248 | amb | 680 | Relations *relations The set of relations to use. |
249 | amb | 623 | |
250 | amb | 219 | double latmin The minimum latitude. |
251 | amb | 184 | |
252 | amb | 219 | double latmax The maximum latitude. |
253 | amb | 184 | |
254 | amb | 219 | double lonmin The minimum longitude. |
255 | amb | 184 | |
256 | amb | 219 | double lonmax The maximum longitude. |
257 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
258 | |||
259 | amb | 623 | void OutputOneway(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
260 | amb | 184 | { |
261 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
262 | |||
263 | OSMNodes=nodes; | ||
264 | OSMSegments=segments; | ||
265 | OSMWays=ways; | ||
266 | amb | 623 | OSMRelations=relations; |
267 | amb | 184 | |
268 | amb | 217 | LatMin=latmin; |
269 | LatMax=latmax; | ||
270 | LonMin=lonmin; | ||
271 | LonMax=lonmax; | ||
272 | |||
273 | amb | 184 | /* Iterate through the nodes and process them */ |
274 | |||
275 | amb | 217 | find_all_nodes(nodes,(callback_t)output_oneway); |
276 | amb | 184 | } |
277 | |||
278 | |||
279 | /*++++++++++++++++++++++++++++++++++++++ | ||
280 | amb | 680 | Process a single node and all connected one-way segments (called as a callback). |
281 | amb | 184 | |
282 | index_t node The node to output. | ||
283 | |||
284 | amb | 219 | double latitude The latitude of the node. |
285 | amb | 184 | |
286 | amb | 219 | double longitude The longitude of the node. |
287 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
288 | |||
289 | amb | 219 | static void output_oneway(index_t node,double latitude,double longitude) |
290 | amb | 184 | { |
291 | amb | 885 | Node *nodep=LookupNode(OSMNodes,node,1); |
292 | amb | 184 | Segment *segment; |
293 | |||
294 | amb | 885 | segment=FirstSegment(OSMSegments,nodep,1); |
295 | amb | 184 | |
296 | do | ||
297 | { | ||
298 | if(IsNormalSegment(segment)) | ||
299 | { | ||
300 | index_t othernode=OtherNode(segment,node); | ||
301 | |||
302 | if(node>othernode) | ||
303 | { | ||
304 | amb | 219 | double lat,lon; |
305 | amb | 184 | |
306 | GetLatLong(OSMNodes,othernode,&lat,&lon); | ||
307 | |||
308 | if(IsOnewayFrom(segment,node)) | ||
309 | amb | 198 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon)); |
310 | amb | 184 | else if(IsOnewayFrom(segment,othernode)) |
311 | amb | 198 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude)); |
312 | amb | 184 | } |
313 | } | ||
314 | |||
315 | segment=NextSegment(OSMSegments,segment,node); | ||
316 | } | ||
317 | while(segment); | ||
318 | } | ||
319 | |||
320 | |||
321 | /*++++++++++++++++++++++++++++++++++++++ | ||
322 | amb | 1003 | Output the data for segments of a particular highway type. |
323 | |||
324 | Nodes *nodes The set of nodes to use. | ||
325 | |||
326 | Segments *segments The set of segments to use. | ||
327 | |||
328 | Ways *ways The set of ways to use. | ||
329 | |||
330 | Relations *relations The set of relations to use. | ||
331 | |||
332 | double latmin The minimum latitude. | ||
333 | |||
334 | double latmax The maximum latitude. | ||
335 | |||
336 | double lonmin The minimum longitude. | ||
337 | |||
338 | double lonmax The maximum longitude. | ||
339 | |||
340 | Highway highway The type of highway. | ||
341 | ++++++++++++++++++++++++++++++++++++++*/ | ||
342 | |||
343 | void OutputHighway(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Highway highway) | ||
344 | { | ||
345 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
346 | |||
347 | OSMNodes=nodes; | ||
348 | OSMSegments=segments; | ||
349 | OSMWays=ways; | ||
350 | OSMRelations=relations; | ||
351 | |||
352 | LatMin=latmin; | ||
353 | LatMax=latmax; | ||
354 | LonMin=lonmin; | ||
355 | LonMax=lonmax; | ||
356 | |||
357 | /* Iterate through the nodes and process them */ | ||
358 | |||
359 | highways=highway; | ||
360 | |||
361 | find_all_nodes(nodes,(callback_t)output_highway); | ||
362 | } | ||
363 | |||
364 | |||
365 | /*++++++++++++++++++++++++++++++++++++++ | ||
366 | Process a single node and all connected one-way segments (called as a callback). | ||
367 | |||
368 | index_t node The node to output. | ||
369 | |||
370 | double latitude The latitude of the node. | ||
371 | |||
372 | double longitude The longitude of the node. | ||
373 | ++++++++++++++++++++++++++++++++++++++*/ | ||
374 | |||
375 | static void output_highway(index_t node,double latitude,double longitude) | ||
376 | { | ||
377 | Node *nodep=LookupNode(OSMNodes,node,1); | ||
378 | Segment *segment; | ||
379 | |||
380 | segment=FirstSegment(OSMSegments,nodep,1); | ||
381 | |||
382 | do | ||
383 | { | ||
384 | if(IsNormalSegment(segment)) | ||
385 | { | ||
386 | index_t othernode=OtherNode(segment,node); | ||
387 | |||
388 | if(node>othernode) | ||
389 | { | ||
390 | Way *way=LookupWay(OSMWays,segment->way,1); | ||
391 | |||
392 | amb | 1057 | if(HIGHWAY(way->type)==highways) |
393 | amb | 1003 | { |
394 | double lat,lon; | ||
395 | |||
396 | GetLatLong(OSMNodes,othernode,&lat,&lon); | ||
397 | |||
398 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon)); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | segment=NextSegment(OSMSegments,segment,node); | ||
404 | } | ||
405 | while(segment); | ||
406 | } | ||
407 | |||
408 | |||
409 | /*++++++++++++++++++++++++++++++++++++++ | ||
410 | amb | 1002 | Output the data for segments allowed for a paticular type of traffic. |
411 | |||
412 | Nodes *nodes The set of nodes to use. | ||
413 | |||
414 | Segments *segments The set of segments to use. | ||
415 | |||
416 | Ways *ways The set of ways to use. | ||
417 | |||
418 | Relations *relations The set of relations to use. | ||
419 | |||
420 | double latmin The minimum latitude. | ||
421 | |||
422 | double latmax The maximum latitude. | ||
423 | |||
424 | double lonmin The minimum longitude. | ||
425 | |||
426 | double lonmax The maximum longitude. | ||
427 | |||
428 | Transport transport The type of transport. | ||
429 | ++++++++++++++++++++++++++++++++++++++*/ | ||
430 | |||
431 | void OutputTransport(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Transport transport) | ||
432 | { | ||
433 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
434 | |||
435 | OSMNodes=nodes; | ||
436 | OSMSegments=segments; | ||
437 | OSMWays=ways; | ||
438 | OSMRelations=relations; | ||
439 | |||
440 | LatMin=latmin; | ||
441 | LatMax=latmax; | ||
442 | LonMin=lonmin; | ||
443 | LonMax=lonmax; | ||
444 | |||
445 | /* Iterate through the nodes and process them */ | ||
446 | |||
447 | transports=TRANSPORTS(transport); | ||
448 | |||
449 | find_all_nodes(nodes,(callback_t)output_transport); | ||
450 | } | ||
451 | |||
452 | |||
453 | /*++++++++++++++++++++++++++++++++++++++ | ||
454 | Process a single node and all connected one-way segments (called as a callback). | ||
455 | |||
456 | index_t node The node to output. | ||
457 | |||
458 | double latitude The latitude of the node. | ||
459 | |||
460 | double longitude The longitude of the node. | ||
461 | ++++++++++++++++++++++++++++++++++++++*/ | ||
462 | |||
463 | static void output_transport(index_t node,double latitude,double longitude) | ||
464 | { | ||
465 | Node *nodep=LookupNode(OSMNodes,node,1); | ||
466 | Segment *segment; | ||
467 | |||
468 | segment=FirstSegment(OSMSegments,nodep,1); | ||
469 | |||
470 | do | ||
471 | { | ||
472 | if(IsNormalSegment(segment)) | ||
473 | { | ||
474 | index_t othernode=OtherNode(segment,node); | ||
475 | |||
476 | if(node>othernode) | ||
477 | { | ||
478 | Way *way=LookupWay(OSMWays,segment->way,1); | ||
479 | |||
480 | if(way->allow&transports) | ||
481 | { | ||
482 | double lat,lon; | ||
483 | |||
484 | GetLatLong(OSMNodes,othernode,&lat,&lon); | ||
485 | |||
486 | printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon)); | ||
487 | } | ||
488 | } | ||
489 | } | ||
490 | |||
491 | segment=NextSegment(OSMSegments,segment,node); | ||
492 | } | ||
493 | while(segment); | ||
494 | } | ||
495 | |||
496 | |||
497 | /*++++++++++++++++++++++++++++++++++++++ | ||
498 | amb | 623 | Output the data for turn restrictions. |
499 | |||
500 | Nodes *nodes The set of nodes to use. | ||
501 | |||
502 | Segments *segments The set of segments to use. | ||
503 | |||
504 | Ways *ways The set of ways to use. | ||
505 | |||
506 | amb | 680 | Relations *relations The set of relations to use. |
507 | amb | 623 | |
508 | double latmin The minimum latitude. | ||
509 | |||
510 | double latmax The maximum latitude. | ||
511 | |||
512 | double lonmin The minimum longitude. | ||
513 | |||
514 | double lonmax The maximum longitude. | ||
515 | ++++++++++++++++++++++++++++++++++++++*/ | ||
516 | |||
517 | void OutputTurnRestrictions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) | ||
518 | { | ||
519 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
520 | |||
521 | OSMNodes=nodes; | ||
522 | OSMSegments=segments; | ||
523 | OSMWays=ways; | ||
524 | OSMRelations=relations; | ||
525 | |||
526 | LatMin=latmin; | ||
527 | LatMax=latmax; | ||
528 | LonMin=lonmin; | ||
529 | LonMax=lonmax; | ||
530 | |||
531 | /* Iterate through the nodes and process them */ | ||
532 | |||
533 | find_all_nodes(nodes,(callback_t)output_turnrestriction); | ||
534 | } | ||
535 | |||
536 | |||
537 | /*++++++++++++++++++++++++++++++++++++++ | ||
538 | amb | 680 | Process a single node as the 'via' node for a turn restriction (called as a callback). |
539 | amb | 623 | |
540 | index_t node The node to output. | ||
541 | |||
542 | double latitude The latitude of the node. | ||
543 | |||
544 | double longitude The longitude of the node. | ||
545 | ++++++++++++++++++++++++++++++++++++++*/ | ||
546 | |||
547 | static void output_turnrestriction(index_t node,double latitude,double longitude) | ||
548 | { | ||
549 | amb | 885 | Node *nodep=LookupNode(OSMNodes,node,1); |
550 | amb | 623 | index_t turnrelation=NO_RELATION; |
551 | |||
552 | amb | 885 | if(!IsTurnRestrictedNode(nodep)) |
553 | amb | 623 | return; |
554 | |||
555 | turnrelation=FindFirstTurnRelation1(OSMRelations,node); | ||
556 | |||
557 | do | ||
558 | { | ||
559 | TurnRelation *relation; | ||
560 | Segment *from_segment,*to_segment; | ||
561 | index_t from_node,to_node; | ||
562 | double from_lat,from_lon,to_lat,to_lon; | ||
563 | |||
564 | relation=LookupTurnRelation(OSMRelations,turnrelation,1); | ||
565 | |||
566 | from_segment=LookupSegment(OSMSegments,relation->from,1); | ||
567 | amb | 707 | to_segment =LookupSegment(OSMSegments,relation->to ,2); |
568 | amb | 623 | |
569 | from_node=OtherNode(from_segment,node); | ||
570 | to_node=OtherNode(to_segment,node); | ||
571 | |||
572 | GetLatLong(OSMNodes,from_node,&from_lat,&from_lon); | ||
573 | GetLatLong(OSMNodes,to_node,&to_lat,&to_lon); | ||
574 | |||
575 | printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",radians_to_degrees(from_lat),radians_to_degrees(from_lon), | ||
576 | radians_to_degrees(latitude),radians_to_degrees(longitude), | ||
577 | radians_to_degrees(to_lat),radians_to_degrees(to_lon)); | ||
578 | |||
579 | turnrelation=FindNextTurnRelation1(OSMRelations,turnrelation); | ||
580 | } | ||
581 | while(turnrelation!=NO_RELATION); | ||
582 | } | ||
583 | |||
584 | |||
585 | /*++++++++++++++++++++++++++++++++++++++ | ||
586 | amb | 184 | Output the data for speed limits. |
587 | |||
588 | Nodes *nodes The set of nodes to use. | ||
589 | |||
590 | Segments *segments The set of segments to use. | ||
591 | |||
592 | Ways *ways The set of ways to use. | ||
593 | |||
594 | amb | 680 | Relations *relations The set of relations to use. |
595 | amb | 623 | |
596 | amb | 219 | double latmin The minimum latitude. |
597 | amb | 184 | |
598 | amb | 219 | double latmax The maximum latitude. |
599 | amb | 184 | |
600 | amb | 219 | double lonmin The minimum longitude. |
601 | amb | 184 | |
602 | amb | 219 | double lonmax The maximum longitude. |
603 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
604 | |||
605 | amb | 623 | void OutputSpeedLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
606 | amb | 184 | { |
607 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
608 | |||
609 | OSMNodes=nodes; | ||
610 | OSMSegments=segments; | ||
611 | OSMWays=ways; | ||
612 | amb | 623 | OSMRelations=relations; |
613 | amb | 184 | |
614 | amb | 217 | LatMin=latmin; |
615 | LatMax=latmax; | ||
616 | LonMin=lonmin; | ||
617 | LonMax=lonmax; | ||
618 | |||
619 | amb | 184 | /* Iterate through the nodes and process them */ |
620 | |||
621 | limit_type=SPEED_LIMIT; | ||
622 | |||
623 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
624 | amb | 184 | } |
625 | |||
626 | |||
627 | /*++++++++++++++++++++++++++++++++++++++ | ||
628 | Output the data for weight limits. | ||
629 | |||
630 | Nodes *nodes The set of nodes to use. | ||
631 | |||
632 | Segments *segments The set of segments to use. | ||
633 | |||
634 | Ways *ways The set of ways to use. | ||
635 | |||
636 | amb | 680 | Relations *relations The set of relations to use. |
637 | amb | 623 | |
638 | amb | 219 | double latmin The minimum latitude. |
639 | amb | 184 | |
640 | amb | 219 | double latmax The maximum latitude. |
641 | amb | 184 | |
642 | amb | 219 | double lonmin The minimum longitude. |
643 | amb | 184 | |
644 | amb | 219 | double lonmax The maximum longitude. |
645 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
646 | |||
647 | amb | 623 | void OutputWeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
648 | amb | 184 | { |
649 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
650 | |||
651 | OSMNodes=nodes; | ||
652 | OSMSegments=segments; | ||
653 | OSMWays=ways; | ||
654 | amb | 623 | OSMRelations=relations; |
655 | amb | 184 | |
656 | amb | 217 | LatMin=latmin; |
657 | LatMax=latmax; | ||
658 | LonMin=lonmin; | ||
659 | LonMax=lonmax; | ||
660 | |||
661 | amb | 184 | /* Iterate through the nodes and process them */ |
662 | |||
663 | limit_type=WEIGHT_LIMIT; | ||
664 | |||
665 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
666 | amb | 184 | } |
667 | |||
668 | |||
669 | /*++++++++++++++++++++++++++++++++++++++ | ||
670 | Output the data for height limits. | ||
671 | |||
672 | Nodes *nodes The set of nodes to use. | ||
673 | |||
674 | Segments *segments The set of segments to use. | ||
675 | |||
676 | Ways *ways The set of ways to use. | ||
677 | |||
678 | amb | 680 | Relations *relations The set of relations to use. |
679 | amb | 623 | |
680 | amb | 219 | double latmin The minimum latitude. |
681 | amb | 184 | |
682 | amb | 219 | double latmax The maximum latitude. |
683 | amb | 184 | |
684 | amb | 219 | double lonmin The minimum longitude. |
685 | amb | 184 | |
686 | amb | 219 | double lonmax The maximum longitude. |
687 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
688 | |||
689 | amb | 623 | void OutputHeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
690 | amb | 184 | { |
691 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
692 | |||
693 | OSMNodes=nodes; | ||
694 | OSMSegments=segments; | ||
695 | OSMWays=ways; | ||
696 | amb | 623 | OSMRelations=relations; |
697 | amb | 184 | |
698 | amb | 217 | LatMin=latmin; |
699 | LatMax=latmax; | ||
700 | LonMin=lonmin; | ||
701 | LonMax=lonmax; | ||
702 | |||
703 | amb | 184 | /* Iterate through the nodes and process them */ |
704 | |||
705 | limit_type=HEIGHT_LIMIT; | ||
706 | |||
707 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
708 | amb | 184 | } |
709 | |||
710 | |||
711 | /*++++++++++++++++++++++++++++++++++++++ | ||
712 | Output the data for width limits. | ||
713 | |||
714 | Nodes *nodes The set of nodes to use. | ||
715 | |||
716 | Segments *segments The set of segments to use. | ||
717 | |||
718 | Ways *ways The set of ways to use. | ||
719 | |||
720 | amb | 680 | Relations *relations The set of relations to use. |
721 | amb | 623 | |
722 | amb | 219 | double latmin The minimum latitude. |
723 | amb | 184 | |
724 | amb | 219 | double latmax The maximum latitude. |
725 | amb | 184 | |
726 | amb | 219 | double lonmin The minimum longitude. |
727 | amb | 184 | |
728 | amb | 219 | double lonmax The maximum longitude. |
729 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
730 | |||
731 | amb | 623 | void OutputWidthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
732 | amb | 184 | { |
733 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
734 | |||
735 | OSMNodes=nodes; | ||
736 | OSMSegments=segments; | ||
737 | OSMWays=ways; | ||
738 | amb | 623 | OSMRelations=relations; |
739 | amb | 184 | |
740 | amb | 217 | LatMin=latmin; |
741 | LatMax=latmax; | ||
742 | LonMin=lonmin; | ||
743 | LonMax=lonmax; | ||
744 | |||
745 | amb | 184 | /* Iterate through the nodes and process them */ |
746 | |||
747 | limit_type=WIDTH_LIMIT; | ||
748 | |||
749 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
750 | amb | 184 | } |
751 | |||
752 | |||
753 | /*++++++++++++++++++++++++++++++++++++++ | ||
754 | Output the data for length limits. | ||
755 | |||
756 | Nodes *nodes The set of nodes to use. | ||
757 | |||
758 | Segments *segments The set of segments to use. | ||
759 | |||
760 | Ways *ways The set of ways to use. | ||
761 | |||
762 | amb | 680 | Relations *relations The set of relations to use. |
763 | amb | 623 | |
764 | amb | 219 | double latmin The minimum latitude. |
765 | amb | 184 | |
766 | amb | 219 | double latmax The maximum latitude. |
767 | amb | 184 | |
768 | amb | 219 | double lonmin The minimum longitude. |
769 | amb | 184 | |
770 | amb | 219 | double lonmax The maximum longitude. |
771 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
772 | |||
773 | amb | 623 | void OutputLengthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax) |
774 | amb | 184 | { |
775 | /* Use local variables so that the callback doesn't need to pass them backwards and forwards */ | ||
776 | |||
777 | OSMNodes=nodes; | ||
778 | OSMSegments=segments; | ||
779 | OSMWays=ways; | ||
780 | amb | 623 | OSMRelations=relations; |
781 | amb | 184 | |
782 | amb | 217 | LatMin=latmin; |
783 | LatMax=latmax; | ||
784 | LonMin=lonmin; | ||
785 | LonMax=lonmax; | ||
786 | |||
787 | amb | 184 | /* Iterate through the nodes and process them */ |
788 | |||
789 | limit_type=LENGTH_LIMIT; | ||
790 | |||
791 | amb | 217 | find_all_nodes(nodes,(callback_t)output_limits); |
792 | amb | 184 | } |
793 | |||
794 | |||
795 | /*++++++++++++++++++++++++++++++++++++++ | ||
796 | amb | 680 | Process a single node as a speed, weight, height, length, width limit (called as a callback). |
797 | amb | 184 | |
798 | index_t node The node to output. | ||
799 | |||
800 | amb | 219 | double latitude The latitude of the node. |
801 | amb | 184 | |
802 | amb | 219 | double longitude The longitude of the node. |
803 | amb | 184 | ++++++++++++++++++++++++++++++++++++++*/ |
804 | |||
805 | amb | 219 | static void output_limits(index_t node,double latitude,double longitude) |
806 | amb | 184 | { |
807 | amb | 885 | Node *nodep=LookupNode(OSMNodes,node,1); |
808 | amb | 934 | Segment *segment,segments[MAX_SEG_PER_NODE]; |
809 | int limits[MAX_SEG_PER_NODE]; | ||
810 | amb | 184 | int count=0; |
811 | int i,j,same=0; | ||
812 | |||
813 | amb | 885 | segment=FirstSegment(OSMSegments,nodep,1); |
814 | amb | 184 | |
815 | do | ||
816 | { | ||
817 | amb | 934 | if(IsNormalSegment(segment) && count<MAX_SEG_PER_NODE) |
818 | amb | 184 | { |
819 | amb | 934 | Way *way=LookupWay(OSMWays,segment->way,1); |
820 | amb | 184 | |
821 | amb | 934 | segments[count]=*segment; |
822 | |||
823 | amb | 184 | switch(limit_type) |
824 | { | ||
825 | amb | 934 | case SPEED_LIMIT: limits[count]=way->speed; break; |
826 | case WEIGHT_LIMIT: limits[count]=way->weight; break; | ||
827 | case HEIGHT_LIMIT: limits[count]=way->height; break; | ||
828 | case WIDTH_LIMIT: limits[count]=way->width; break; | ||
829 | case LENGTH_LIMIT: limits[count]=way->length; break; | ||
830 | amb | 184 | } |
831 | |||
832 | amb | 934 | if(limits[count] || HIGHWAY(way->type)<Way_Track) |
833 | amb | 217 | count++; |
834 | amb | 184 | } |
835 | |||
836 | segment=NextSegment(OSMSegments,segment,node); | ||
837 | } | ||
838 | while(segment); | ||
839 | |||
840 | /* Nodes with only one limit are not interesting */ | ||
841 | |||
842 | if(count==1) | ||
843 | return; | ||
844 | |||
845 | amb | 934 | /* Nodes with all segments the same limit are not interesting */ |
846 | amb | 184 | |
847 | same=0; | ||
848 | for(j=0;j<count;j++) | ||
849 | if(limits[0]==limits[j]) | ||
850 | same++; | ||
851 | |||
852 | if(same==count) | ||
853 | return; | ||
854 | |||
855 | amb | 934 | /* Display the interesting limits */ |
856 | amb | 184 | |
857 | amb | 198 | printf("%.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); |
858 | amb | 184 | |
859 | for(i=0;i<count;i++) | ||
860 | { | ||
861 | same=0; | ||
862 | for(j=0;j<count;j++) | ||
863 | if(limits[i]==limits[j]) | ||
864 | same++; | ||
865 | |||
866 | if(count==2 || same!=(count-1)) | ||
867 | { | ||
868 | amb | 219 | double lat,lon; |
869 | amb | 184 | |
870 | amb | 934 | GetLatLong(OSMNodes,OtherNode(&segments[i],node),&lat,&lon); |
871 | amb | 184 | |
872 | switch(limit_type) | ||
873 | { | ||
874 | case SPEED_LIMIT: | ||
875 | amb | 219 | printf("%.6f %.6f %d\n",radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i])); |
876 | amb | 184 | break; |
877 | case WEIGHT_LIMIT: | ||
878 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i])); |
879 | amb | 184 | break; |
880 | case HEIGHT_LIMIT: | ||
881 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i])); |
882 | amb | 184 | break; |
883 | case WIDTH_LIMIT: | ||
884 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i])); |
885 | amb | 184 | break; |
886 | case LENGTH_LIMIT: | ||
887 | amb | 198 | printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i])); |
888 | amb | 184 | break; |
889 | } | ||
890 | } | ||
891 | } | ||
892 | } | ||
893 | |||
894 | |||
895 | /*++++++++++++++++++++++++++++++++++++++ | ||
896 | A function to iterate through all nodes and call a callback function for each one. | ||
897 | |||
898 | amb | 681 | Nodes *nodes The set of nodes to use. |
899 | amb | 184 | |
900 | callback_t callback The callback function for each node. | ||
901 | ++++++++++++++++++++++++++++++++++++++*/ | ||
902 | |||
903 | amb | 217 | static void find_all_nodes(Nodes *nodes,callback_t callback) |
904 | amb | 184 | { |
905 | amb | 780 | ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->file.latzero; |
906 | ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->file.latzero; | ||
907 | ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->file.lonzero; | ||
908 | ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->file.lonzero; | ||
909 | ll_bin_t latb,lonb; | ||
910 | amb | 462 | index_t i,index1,index2; |
911 | amb | 184 | |
912 | /* Loop through all of the nodes. */ | ||
913 | |||
914 | for(latb=latminbin;latb<=latmaxbin;latb++) | ||
915 | for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) | ||
916 | { | ||
917 | amb | 780 | ll_bin2_t llbin=lonb*nodes->file.latbins+latb; |
918 | amb | 184 | |
919 | amb | 453 | if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins)) |
920 | amb | 184 | continue; |
921 | |||
922 | amb | 462 | index1=LookupNodeOffset(nodes,llbin); |
923 | index2=LookupNodeOffset(nodes,llbin+1); | ||
924 | |||
925 | for(i=index1;i<index2;i++) | ||
926 | amb | 184 | { |
927 | amb | 453 | Node *node=LookupNode(nodes,i,1); |
928 | amb | 184 | |
929 | amb | 453 | double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(node->latoffset)); |
930 | double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset)); | ||
931 | |||
932 | amb | 217 | if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax) |
933 | amb | 453 | (*callback)(i,lat,lon); |
934 | amb | 184 | } |
935 | } | ||
936 | } |
Properties
Name | Value |
---|---|
cvs:description | Functions for data visualisation. |