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/visualiser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1322 - (show annotations) (download) (as text)
Fri May 17 17:28:12 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 30497 byte(s)
Limit the error log outputs to the geographical ones and make the strings HTML
safe.

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

Properties

Name Value
cvs:description Functions for data visualisation.