Routino SVN Repository Browser

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

ViewVC logotype

Contents of /branches/destination-access/src/visualiser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1957 - (show annotations) (download) (as text)
Fri Sep 21 17:29:51 2018 UTC (6 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 34792 byte(s)
Merge from trunk.  Also update tagging for 'destination' access.

1 /***************************************
2 Extract data from Routino.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015, 2017 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
34 #include "typesx.h"
35
36 #include "visualiser.h"
37
38
39 /* Limit types */
40
41 #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 typedef void (*callback_t)(index_t node,double latitude,double longitude);
50
51 /* Local variables (intialised by entry-point function before later use) */
52
53 static Nodes *OSMNodes;
54 static Segments *OSMSegments;
55 static Ways *OSMWays;
56 static Relations *OSMRelations;
57
58 static double LatMin;
59 static double LatMax;
60 static double LonMin;
61 static double LonMax;
62
63 static int limit_type=0;
64 static Highway highways=Highway_None;
65 static Transports transports=Transports_None;
66 static Properties properties=Properties_None;
67 static highway_t waytype=0;
68
69 /* Local functions */
70
71 static void find_all_nodes(Nodes *nodes,callback_t callback);
72
73 static void output_junctions(index_t node,double latitude,double longitude);
74 static void output_super(index_t node,double latitude,double longitude);
75 static void output_waytype(index_t node,double latitude,double longitude);
76 static void output_highway(index_t node,double latitude,double longitude);
77 static void output_transport(index_t node,double latitude,double longitude);
78 static void output_destination(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 (--data=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 and output all those that are junctions (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("node%"Pindex_t" %.6f %.6f %d\n",node,radians_to_degrees(latitude),radians_to_degrees(longitude),count);
161 }
162
163
164 /*++++++++++++++++++++++++++++++++++++++
165 Output the data for super-nodes and super-segments (--data=super).
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 and output all that are super-nodes and all connected super-segments (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("node%"Pindex_t" %.6f %.6f\n",node,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("segment%"Pindex_t" %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),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 segments of special highway types (--data=waytype-oneway etc).
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 highway_t mask A bit mask that must match the highway type.
265 ++++++++++++++++++++++++++++++++++++++*/
266
267 void OutputWaytype(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,highway_t mask)
268 {
269 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
270
271 OSMNodes=nodes;
272 OSMSegments=segments;
273 OSMWays=ways;
274 OSMRelations=relations;
275
276 LatMin=latmin;
277 LatMax=latmax;
278 LonMin=lonmin;
279 LonMax=lonmax;
280
281 /* Iterate through the nodes and process them */
282
283 waytype=mask;
284
285 find_all_nodes(nodes,(callback_t)output_waytype);
286 }
287
288
289 /*++++++++++++++++++++++++++++++++++++++
290 Process a single node and output all connected segments of a particular special highway type (called as a callback).
291
292 index_t node The node to output.
293
294 double latitude The latitude of the node.
295
296 double longitude The longitude of the node.
297 ++++++++++++++++++++++++++++++++++++++*/
298
299 static void output_waytype(index_t node,double latitude,double longitude)
300 {
301 Node *nodep=LookupNode(OSMNodes,node,1);
302 Segment *segmentp;
303
304 segmentp=FirstSegment(OSMSegments,nodep,1);
305
306 do
307 {
308 if(IsNormalSegment(segmentp))
309 {
310 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
311
312 if(wayp->type&waytype)
313 {
314 index_t othernode=OtherNode(segmentp,node);
315 double lat,lon;
316
317 GetLatLong(OSMNodes,othernode,NULL,&lat,&lon);
318
319 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
320 {
321 if(IsOnewayFrom(segmentp,node))
322 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
323 else if(IsOnewayFrom(segmentp,othernode))
324 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude));
325 }
326 }
327 }
328
329 segmentp=NextSegment(OSMSegments,segmentp,node);
330 }
331 while(segmentp);
332 }
333
334
335 /*++++++++++++++++++++++++++++++++++++++
336 Output the data for segments of a particular highway type (--data=highway-primary etc).
337
338 Nodes *nodes The set of nodes to use.
339
340 Segments *segments The set of segments to use.
341
342 Ways *ways The set of ways to use.
343
344 Relations *relations The set of relations to use.
345
346 double latmin The minimum latitude.
347
348 double latmax The maximum latitude.
349
350 double lonmin The minimum longitude.
351
352 double lonmax The maximum longitude.
353
354 Highway highway The type of highway.
355 ++++++++++++++++++++++++++++++++++++++*/
356
357 void OutputHighway(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Highway highway)
358 {
359 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
360
361 OSMNodes=nodes;
362 OSMSegments=segments;
363 OSMWays=ways;
364 OSMRelations=relations;
365
366 LatMin=latmin;
367 LatMax=latmax;
368 LonMin=lonmin;
369 LonMax=lonmax;
370
371 /* Iterate through the nodes and process them */
372
373 highways=highway;
374
375 find_all_nodes(nodes,(callback_t)output_highway);
376 }
377
378
379 /*++++++++++++++++++++++++++++++++++++++
380 Process a single node and output all connected segments that are of a particular highway type (called as a callback).
381
382 index_t node The node to output.
383
384 double latitude The latitude of the node.
385
386 double longitude The longitude of the node.
387 ++++++++++++++++++++++++++++++++++++++*/
388
389 static void output_highway(index_t node,double latitude,double longitude)
390 {
391 Node *nodep=LookupNode(OSMNodes,node,1);
392 Segment *segmentp;
393
394 segmentp=FirstSegment(OSMSegments,nodep,1);
395
396 do
397 {
398 if(IsNormalSegment(segmentp))
399 {
400 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
401
402 if(HIGHWAY(wayp->type)==highways)
403 {
404 index_t othernode=OtherNode(segmentp,node);
405 double lat,lon;
406
407 GetLatLong(OSMNodes,othernode,NULL,&lat,&lon);
408
409 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
410 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
411 }
412 }
413
414 segmentp=NextSegment(OSMSegments,segmentp,node);
415 }
416 while(segmentp);
417 }
418
419
420 /*++++++++++++++++++++++++++++++++++++++
421 Output the data for segments allowed for a particular type of traffic (--data=transport-motorcar etc).
422
423 Nodes *nodes The set of nodes to use.
424
425 Segments *segments The set of segments to use.
426
427 Ways *ways The set of ways to use.
428
429 Relations *relations The set of relations to use.
430
431 double latmin The minimum latitude.
432
433 double latmax The maximum latitude.
434
435 double lonmin The minimum longitude.
436
437 double lonmax The maximum longitude.
438
439 Transport transport The type of transport.
440 ++++++++++++++++++++++++++++++++++++++*/
441
442 void OutputTransport(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Transport transport)
443 {
444 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
445
446 OSMNodes=nodes;
447 OSMSegments=segments;
448 OSMWays=ways;
449 OSMRelations=relations;
450
451 LatMin=latmin;
452 LatMax=latmax;
453 LonMin=lonmin;
454 LonMax=lonmax;
455
456 /* Iterate through the nodes and process them */
457
458 transports=TRANSPORTS(transport);
459
460 find_all_nodes(nodes,(callback_t)output_transport);
461 }
462
463
464 /*++++++++++++++++++++++++++++++++++++++
465 Process a single node and output all connected segments for a particular traffic type (called as a callback).
466
467 index_t node The node to output.
468
469 double latitude The latitude of the node.
470
471 double longitude The longitude of the node.
472 ++++++++++++++++++++++++++++++++++++++*/
473
474 static void output_transport(index_t node,double latitude,double longitude)
475 {
476 Node *nodep=LookupNode(OSMNodes,node,1);
477 Segment *segmentp;
478
479 segmentp=FirstSegment(OSMSegments,nodep,1);
480
481 do
482 {
483 if(IsNormalSegment(segmentp))
484 {
485 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
486
487 if(wayp->allow&transports)
488 {
489 index_t othernode=OtherNode(segmentp,node);
490 double lat,lon;
491
492 GetLatLong(OSMNodes,othernode,NULL,&lat,&lon);
493
494 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
495 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
496 }
497 }
498
499 segmentp=NextSegment(OSMSegments,segmentp,node);
500 }
501 while(segmentp);
502 }
503
504
505 /*++++++++++++++++++++++++++++++++++++++
506 Output the data for segments allowed for a particular type of traffic for destinations only (--data=transport-destination-motorcar etc).
507
508 Nodes *nodes The set of nodes to use.
509
510 Segments *segments The set of segments to use.
511
512 Ways *ways The set of ways to use.
513
514 Relations *relations The set of relations to use.
515
516 double latmin The minimum latitude.
517
518 double latmax The maximum latitude.
519
520 double lonmin The minimum longitude.
521
522 double lonmax The maximum longitude.
523
524 Transport transport The type of transport.
525 ++++++++++++++++++++++++++++++++++++++*/
526
527 void OutputDestination(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Transport transport)
528 {
529 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
530
531 OSMNodes=nodes;
532 OSMSegments=segments;
533 OSMWays=ways;
534 OSMRelations=relations;
535
536 LatMin=latmin;
537 LatMax=latmax;
538 LonMin=lonmin;
539 LonMax=lonmax;
540
541 /* Iterate through the nodes and process them */
542
543 transports=TRANSPORTS(transport);
544
545 find_all_nodes(nodes,(callback_t)output_destination);
546 }
547
548
549 /*++++++++++++++++++++++++++++++++++++++
550 Process a single node and output all connected segments that are destination only for a particular traffic type (called as a callback).
551
552 index_t node The node to output.
553
554 double latitude The latitude of the node.
555
556 double longitude The longitude of the node.
557 ++++++++++++++++++++++++++++++++++++++*/
558
559 static void output_destination(index_t node,double latitude,double longitude)
560 {
561 Node *nodep=LookupNode(OSMNodes,node,1);
562 Segment *segmentp;
563
564 segmentp=FirstSegment(OSMSegments,nodep,1);
565
566 do
567 {
568 if(IsNormalSegment(segmentp))
569 {
570 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
571
572 if(wayp->destination&transports)
573 {
574 index_t othernode=OtherNode(segmentp,node);
575 double lat,lon;
576
577 GetLatLong(OSMNodes,othernode,NULL,&lat,&lon);
578
579 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
580 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
581 }
582 }
583
584 segmentp=NextSegment(OSMSegments,segmentp,node);
585 }
586 while(segmentp);
587 }
588
589
590 /*++++++++++++++++++++++++++++++++++++++
591 Output the data for nodes disallowed for a particular type of traffic (--data=barrier).
592
593 Nodes *nodes The set of nodes to use.
594
595 Segments *segments The set of segments to use.
596
597 Ways *ways The set of ways to use.
598
599 Relations *relations The set of relations to use.
600
601 double latmin The minimum latitude.
602
603 double latmax The maximum latitude.
604
605 double lonmin The minimum longitude.
606
607 double lonmax The maximum longitude.
608
609 Transport transport The type of transport.
610 ++++++++++++++++++++++++++++++++++++++*/
611
612 void OutputBarrier(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Transport transport)
613 {
614 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
615
616 OSMNodes=nodes;
617 OSMSegments=segments;
618 OSMWays=ways;
619 OSMRelations=relations;
620
621 LatMin=latmin;
622 LatMax=latmax;
623 LonMin=lonmin;
624 LonMax=lonmax;
625
626 /* Iterate through the nodes and process them */
627
628 transports=TRANSPORTS(transport);
629
630 find_all_nodes(nodes,(callback_t)output_barrier);
631 }
632
633
634 /*++++++++++++++++++++++++++++++++++++++
635 Process a single node and output those that are barriers (called as a callback).
636
637 index_t node The node to output.
638
639 double latitude The latitude of the node.
640
641 double longitude The longitude of the node.
642 ++++++++++++++++++++++++++++++++++++++*/
643
644 static void output_barrier(index_t node,double latitude,double longitude)
645 {
646 Node *nodep=LookupNode(OSMNodes,node,1);
647
648 if(!(nodep->allow&transports))
649 printf("node%"Pindex_t" %.6f %.6f\n",node,radians_to_degrees(latitude),radians_to_degrees(longitude));
650 }
651
652
653 /*++++++++++++++++++++++++++++++++++++++
654 Output the data for turn restrictions (--data=turns).
655
656 Nodes *nodes The set of nodes to use.
657
658 Segments *segments The set of segments to use.
659
660 Ways *ways The set of ways to use.
661
662 Relations *relations The set of relations to use.
663
664 double latmin The minimum latitude.
665
666 double latmax The maximum latitude.
667
668 double lonmin The minimum longitude.
669
670 double lonmax The maximum longitude.
671 ++++++++++++++++++++++++++++++++++++++*/
672
673 void OutputTurnRestrictions(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
674 {
675 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
676
677 OSMNodes=nodes;
678 OSMSegments=segments;
679 OSMWays=ways;
680 OSMRelations=relations;
681
682 LatMin=latmin;
683 LatMax=latmax;
684 LonMin=lonmin;
685 LonMax=lonmax;
686
687 /* Iterate through the nodes and process them */
688
689 find_all_nodes(nodes,(callback_t)output_turnrestriction);
690 }
691
692
693 /*++++++++++++++++++++++++++++++++++++++
694 Process a single node and output those that are 'via' nodes for a turn restriction and the associated segments (called as a callback).
695
696 index_t node The node to output.
697
698 double latitude The latitude of the node.
699
700 double longitude The longitude of the node.
701 ++++++++++++++++++++++++++++++++++++++*/
702
703 static void output_turnrestriction(index_t node,double latitude,double longitude)
704 {
705 Node *nodep=LookupNode(OSMNodes,node,1);
706 index_t turnrelation=NO_RELATION;
707
708 if(!IsTurnRestrictedNode(nodep))
709 return;
710
711 turnrelation=FindFirstTurnRelation1(OSMRelations,node);
712
713 do
714 {
715 TurnRelation *relation;
716 Segment *from_segmentp,*to_segmentp;
717 index_t from_node,to_node;
718 double from_lat,from_lon,to_lat,to_lon;
719
720 relation=LookupTurnRelation(OSMRelations,turnrelation,1);
721
722 from_segmentp=LookupSegment(OSMSegments,relation->from,1);
723 to_segmentp =LookupSegment(OSMSegments,relation->to ,2);
724
725 from_node=OtherNode(from_segmentp,node);
726 to_node =OtherNode(to_segmentp ,node);
727
728 GetLatLong(OSMNodes,from_node,NULL,&from_lat,&from_lon);
729 GetLatLong(OSMNodes,to_node ,NULL,&to_lat ,&to_lon);
730
731 printf("turn-relation%"Pindex_t" %.6f %.6f %.6f %.6f %.6f %.6f\n",
732 turnrelation,
733 radians_to_degrees(from_lat),radians_to_degrees(from_lon),
734 radians_to_degrees(latitude),radians_to_degrees(longitude),
735 radians_to_degrees(to_lat),radians_to_degrees(to_lon));
736
737 turnrelation=FindNextTurnRelation1(OSMRelations,turnrelation);
738 }
739 while(turnrelation!=NO_RELATION);
740 }
741
742
743 /*++++++++++++++++++++++++++++++++++++++
744 Output the data for speed limits (--data=speed).
745
746 Nodes *nodes The set of nodes to use.
747
748 Segments *segments The set of segments to use.
749
750 Ways *ways The set of ways to use.
751
752 Relations *relations The set of relations to use.
753
754 double latmin The minimum latitude.
755
756 double latmax The maximum latitude.
757
758 double lonmin The minimum longitude.
759
760 double lonmax The maximum longitude.
761 ++++++++++++++++++++++++++++++++++++++*/
762
763 void OutputSpeedLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
764 {
765 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
766
767 OSMNodes=nodes;
768 OSMSegments=segments;
769 OSMWays=ways;
770 OSMRelations=relations;
771
772 LatMin=latmin;
773 LatMax=latmax;
774 LonMin=lonmin;
775 LonMax=lonmax;
776
777 /* Iterate through the nodes and process them */
778
779 limit_type=SPEED_LIMIT;
780
781 find_all_nodes(nodes,(callback_t)output_limits);
782 }
783
784
785 /*++++++++++++++++++++++++++++++++++++++
786 Output the data for weight limits (--data=weight).
787
788 Nodes *nodes The set of nodes to use.
789
790 Segments *segments The set of segments to use.
791
792 Ways *ways The set of ways to use.
793
794 Relations *relations The set of relations to use.
795
796 double latmin The minimum latitude.
797
798 double latmax The maximum latitude.
799
800 double lonmin The minimum longitude.
801
802 double lonmax The maximum longitude.
803 ++++++++++++++++++++++++++++++++++++++*/
804
805 void OutputWeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
806 {
807 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
808
809 OSMNodes=nodes;
810 OSMSegments=segments;
811 OSMWays=ways;
812 OSMRelations=relations;
813
814 LatMin=latmin;
815 LatMax=latmax;
816 LonMin=lonmin;
817 LonMax=lonmax;
818
819 /* Iterate through the nodes and process them */
820
821 limit_type=WEIGHT_LIMIT;
822
823 find_all_nodes(nodes,(callback_t)output_limits);
824 }
825
826
827 /*++++++++++++++++++++++++++++++++++++++
828 Output the data for height limits (--data=height).
829
830 Nodes *nodes The set of nodes to use.
831
832 Segments *segments The set of segments to use.
833
834 Ways *ways The set of ways to use.
835
836 Relations *relations The set of relations to use.
837
838 double latmin The minimum latitude.
839
840 double latmax The maximum latitude.
841
842 double lonmin The minimum longitude.
843
844 double lonmax The maximum longitude.
845 ++++++++++++++++++++++++++++++++++++++*/
846
847 void OutputHeightLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
848 {
849 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
850
851 OSMNodes=nodes;
852 OSMSegments=segments;
853 OSMWays=ways;
854 OSMRelations=relations;
855
856 LatMin=latmin;
857 LatMax=latmax;
858 LonMin=lonmin;
859 LonMax=lonmax;
860
861 /* Iterate through the nodes and process them */
862
863 limit_type=HEIGHT_LIMIT;
864
865 find_all_nodes(nodes,(callback_t)output_limits);
866 }
867
868
869 /*++++++++++++++++++++++++++++++++++++++
870 Output the data for width limits (--data=width).
871
872 Nodes *nodes The set of nodes to use.
873
874 Segments *segments The set of segments to use.
875
876 Ways *ways The set of ways to use.
877
878 Relations *relations The set of relations to use.
879
880 double latmin The minimum latitude.
881
882 double latmax The maximum latitude.
883
884 double lonmin The minimum longitude.
885
886 double lonmax The maximum longitude.
887 ++++++++++++++++++++++++++++++++++++++*/
888
889 void OutputWidthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
890 {
891 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
892
893 OSMNodes=nodes;
894 OSMSegments=segments;
895 OSMWays=ways;
896 OSMRelations=relations;
897
898 LatMin=latmin;
899 LatMax=latmax;
900 LonMin=lonmin;
901 LonMax=lonmax;
902
903 /* Iterate through the nodes and process them */
904
905 limit_type=WIDTH_LIMIT;
906
907 find_all_nodes(nodes,(callback_t)output_limits);
908 }
909
910
911 /*++++++++++++++++++++++++++++++++++++++
912 Output the data for length limits (--data=length).
913
914 Nodes *nodes The set of nodes to use.
915
916 Segments *segments The set of segments to use.
917
918 Ways *ways The set of ways to use.
919
920 Relations *relations The set of relations to use.
921
922 double latmin The minimum latitude.
923
924 double latmax The maximum latitude.
925
926 double lonmin The minimum longitude.
927
928 double lonmax The maximum longitude.
929 ++++++++++++++++++++++++++++++++++++++*/
930
931 void OutputLengthLimits(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax)
932 {
933 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
934
935 OSMNodes=nodes;
936 OSMSegments=segments;
937 OSMWays=ways;
938 OSMRelations=relations;
939
940 LatMin=latmin;
941 LatMax=latmax;
942 LonMin=lonmin;
943 LonMax=lonmax;
944
945 /* Iterate through the nodes and process them */
946
947 limit_type=LENGTH_LIMIT;
948
949 find_all_nodes(nodes,(callback_t)output_limits);
950 }
951
952
953 /*++++++++++++++++++++++++++++++++++++++
954 Process a single node and output those and connected segments that have a speed, weight, height, width or length limit change (called as a callback).
955
956 index_t node The node to output.
957
958 double latitude The latitude of the node.
959
960 double longitude The longitude of the node.
961 ++++++++++++++++++++++++++++++++++++++*/
962
963 static void output_limits(index_t node,double latitude,double longitude)
964 {
965 Node *nodep=LookupNode(OSMNodes,node,1);
966 Segment *segmentp,segmentps[MAX_SEG_PER_NODE];
967 index_t segments[MAX_SEG_PER_NODE];
968 int limits[MAX_SEG_PER_NODE];
969 int count=0;
970 int i,j,same=0;
971
972 segmentp=FirstSegment(OSMSegments,nodep,1);
973
974 do
975 {
976 if(IsNormalSegment(segmentp) && count<MAX_SEG_PER_NODE)
977 {
978 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
979
980 segmentps[count]=*segmentp;
981 segments [count]=IndexSegment(OSMSegments,segmentp);
982
983 switch(limit_type)
984 {
985 case SPEED_LIMIT: limits[count]=wayp->speed; break;
986 case WEIGHT_LIMIT: limits[count]=wayp->weight; break;
987 case HEIGHT_LIMIT: limits[count]=wayp->height; break;
988 case WIDTH_LIMIT: limits[count]=wayp->width; break;
989 case LENGTH_LIMIT: limits[count]=wayp->length; break;
990 default: limits[count]=0; break;
991 }
992
993 if(limits[count] || HIGHWAY(wayp->type)<Highway_Track)
994 count++;
995 }
996
997 segmentp=NextSegment(OSMSegments,segmentp,node);
998 }
999 while(segmentp);
1000
1001 /* Nodes with one or fewer limits are not interesting */
1002
1003 if(count<=1)
1004 return;
1005
1006 /* Nodes with all segments the same limit are not interesting */
1007
1008 same=0;
1009 for(j=0;j<count;j++)
1010 if(limits[0]==limits[j])
1011 same++;
1012
1013 if(same==count)
1014 return;
1015
1016 /* Display the interesting limits */
1017
1018 printf("node%"Pindex_t" %.6f %.6f\n",node,radians_to_degrees(latitude),radians_to_degrees(longitude));
1019
1020 for(i=0;i<count;i++)
1021 {
1022 same=0;
1023 for(j=0;j<count;j++)
1024 if(limits[i]==limits[j])
1025 same++;
1026
1027 if(count==2 || same!=(count-1))
1028 {
1029 double lat,lon;
1030
1031 GetLatLong(OSMNodes,OtherNode(&segmentps[i],node),NULL,&lat,&lon);
1032
1033 switch(limit_type)
1034 {
1035 case SPEED_LIMIT:
1036 printf("segment%"Pindex_t" %.6f %.6f %d\n",segments[i],radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i]));
1037 break;
1038 case WEIGHT_LIMIT:
1039 printf("segment%"Pindex_t" %.6f %.6f %.1f\n",segments[i],radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i]));
1040 break;
1041 case HEIGHT_LIMIT:
1042 printf("segment%"Pindex_t" %.6f %.6f %.1f\n",segments[i],radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i]));
1043 break;
1044 case WIDTH_LIMIT:
1045 printf("segment%"Pindex_t" %.6f %.6f %.1f\n",segments[i],radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i]));
1046 break;
1047 case LENGTH_LIMIT:
1048 printf("segment%"Pindex_t" %.6f %.6f %.1f\n",segments[i],radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i]));
1049 break;
1050 }
1051 }
1052 }
1053 }
1054
1055
1056 /*++++++++++++++++++++++++++++++++++++++
1057 Output the data for segments that have a particular property (--data=property-paved etc).
1058
1059 Nodes *nodes The set of nodes to use.
1060
1061 Segments *segments The set of segments to use.
1062
1063 Ways *ways The set of ways to use.
1064
1065 Relations *relations The set of relations to use.
1066
1067 double latmin The minimum latitude.
1068
1069 double latmax The maximum latitude.
1070
1071 double lonmin The minimum longitude.
1072
1073 double lonmax The maximum longitude.
1074
1075 Property property The type of property.
1076 ++++++++++++++++++++++++++++++++++++++*/
1077
1078 void OutputProperty(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,double latmin,double latmax,double lonmin,double lonmax,Property property)
1079 {
1080 /* Use local variables so that the callback doesn't need to pass them backwards and forwards */
1081
1082 OSMNodes=nodes;
1083 OSMSegments=segments;
1084 OSMWays=ways;
1085 OSMRelations=relations;
1086
1087 LatMin=latmin;
1088 LatMax=latmax;
1089 LonMin=lonmin;
1090 LonMax=lonmax;
1091
1092 /* Iterate through the nodes and process them */
1093
1094 properties=PROPERTIES(property);
1095
1096 find_all_nodes(nodes,(callback_t)output_property);
1097 }
1098
1099
1100 /*++++++++++++++++++++++++++++++++++++++
1101 Process a single node and output all connected segments with a particular property (called as a callback).
1102
1103 index_t node The node to output.
1104
1105 double latitude The latitude of the node.
1106
1107 double longitude The longitude of the node.
1108 ++++++++++++++++++++++++++++++++++++++*/
1109
1110 static void output_property(index_t node,double latitude,double longitude)
1111 {
1112 Node *nodep=LookupNode(OSMNodes,node,1);
1113 Segment *segmentp;
1114
1115 segmentp=FirstSegment(OSMSegments,nodep,1);
1116
1117 do
1118 {
1119 if(IsNormalSegment(segmentp))
1120 {
1121 Way *wayp=LookupWay(OSMWays,segmentp->way,1);
1122
1123 if(wayp->props&properties)
1124 {
1125 index_t othernode=OtherNode(segmentp,node);
1126 double lat,lon;
1127
1128 GetLatLong(OSMNodes,othernode,NULL,&lat,&lon);
1129
1130 if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax))
1131 printf("segment%"Pindex_t" %.6f %.6f %.6f %.6f\n",IndexSegment(OSMSegments,segmentp),radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon));
1132 }
1133 }
1134
1135 segmentp=NextSegment(OSMSegments,segmentp,node);
1136 }
1137 while(segmentp);
1138 }
1139
1140
1141 /*++++++++++++++++++++++++++++++++++++++
1142 A function to iterate through all nodes and call a callback function for each one.
1143
1144 Nodes *nodes The set of nodes to use.
1145
1146 callback_t callback The callback function for each node.
1147 ++++++++++++++++++++++++++++++++++++++*/
1148
1149 static void find_all_nodes(Nodes *nodes,callback_t callback)
1150 {
1151 ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(LatMin))-nodes->file.latzero;
1152 ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(LatMax))-nodes->file.latzero;
1153 ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(LonMin))-nodes->file.lonzero;
1154 ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(LonMax))-nodes->file.lonzero;
1155 ll_bin_t latb,lonb;
1156 index_t i,index1,index2;
1157
1158 /* Loop through all of the nodes. */
1159
1160 if(latminbin<0) latminbin=0;
1161 if(latmaxbin>nodes->file.latbins) latmaxbin=nodes->file.latbins-1;
1162
1163 if(lonminbin<0) lonminbin=0;
1164 if(lonmaxbin>nodes->file.lonbins) lonmaxbin=nodes->file.lonbins-1;
1165
1166 for(latb=latminbin;latb<=latmaxbin;latb++)
1167 for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
1168 {
1169 ll_bin2_t llbin=lonb*nodes->file.latbins+latb;
1170
1171 if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins))
1172 continue;
1173
1174 index1=LookupNodeOffset(nodes,llbin);
1175 index2=LookupNodeOffset(nodes,llbin+1);
1176
1177 for(i=index1;i<index2;i++)
1178 {
1179 Node *nodep=LookupNode(nodes,i,1);
1180
1181 double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(nodep->latoffset));
1182 double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(nodep->lonoffset));
1183
1184 if(lat>LatMin && lat<LatMax && lon>LonMin && lon<LonMax)
1185 (*callback)(i,lat,lon);
1186 }
1187 }
1188 }
1189
1190
1191 /*++++++++++++++++++++++++++++++++++++++
1192 Output the data for error logs within the region (--data=errorlogs).
1193
1194 ErrorLogs *errorlogs The set of error logs to use.
1195
1196 double latmin The minimum latitude.
1197
1198 double latmax The maximum latitude.
1199
1200 double lonmin The minimum longitude.
1201
1202 double lonmax The maximum longitude.
1203 ++++++++++++++++++++++++++++++++++++++*/
1204
1205 void OutputErrorLog(ErrorLogs *errorlogs,double latmin,double latmax,double lonmin,double lonmax)
1206 {
1207 ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-errorlogs->file.latzero;
1208 ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-errorlogs->file.latzero;
1209 ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-errorlogs->file.lonzero;
1210 ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-errorlogs->file.lonzero;
1211 ll_bin_t latb,lonb;
1212 index_t i,index1,index2;
1213
1214 /* Loop through all of the error logs. */
1215
1216 for(latb=latminbin;latb<=latmaxbin;latb++)
1217 for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
1218 {
1219 ll_bin2_t llbin=lonb*errorlogs->file.latbins+latb;
1220
1221 if(llbin<0 || llbin>(errorlogs->file.latbins*errorlogs->file.lonbins))
1222 continue;
1223
1224 index1=LookupErrorLogOffset(errorlogs,llbin);
1225 index2=LookupErrorLogOffset(errorlogs,llbin+1);
1226
1227 if(index2>errorlogs->file.number_geo)
1228 index2=errorlogs->file.number_geo;
1229
1230 for(i=index1;i<index2;i++)
1231 {
1232 ErrorLog *errorlogp=LookupErrorLog(errorlogs,i,1);
1233
1234 double lat=latlong_to_radians(bin_to_latlong(errorlogs->file.latzero+latb)+off_to_latlong(errorlogp->latoffset));
1235 double lon=latlong_to_radians(bin_to_latlong(errorlogs->file.lonzero+lonb)+off_to_latlong(errorlogp->lonoffset));
1236
1237 if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax)
1238 printf("errorlog%"Pindex_t" %.6f %.6f\n",i,radians_to_degrees(lat),radians_to_degrees(lon));
1239 }
1240 }
1241 }

Properties

Name Value
cvs:description Functions for data visualisation.