source: subversion/applications/rendering/gosmore/osmunda.cpp @ 19932

Last change on this file since 19932 was 10088, checked in by nic, 11 years ago

Added osmunda. Checking OSM data for routing problem by reading GPX files.

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#include <stdio.h>
2#include <unistd.h>
3#include <libxml/xmlreader.h>
4#include <sys/mman.h>
5#include "libgosm.h"
6
7int main (void)
8{
9  xmlTextReaderPtr xml = xmlReaderForFd (STDIN_FILENO, "", NULL, 0);
10  FILE *file = fopen ("gosmore.pak", "r");
11  if (!xml || !file || fseek (file, 0, SEEK_END) != 0 ||
12        !GosmInit (mmap (NULL, ftell (file), PROT_READ, MAP_SHARED,
13                              fileno (file), 0), ftell (file))) {
14    fprintf (stderr, "Unable to open gosmore.pak\n");
15    return 1;
16  }
17                             
18 
19  int ptCnt = 0;
20  printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
21  "<gpx\n"
22  " version=\"1.0\"\n"
23  " creator=\"osmunda\"\n"
24  " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
25  " xmlns=\"http://www.topografix.com/GPX/1/0\"\n"
26  " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/\">\n");
27  while (xmlTextReaderRead (xml)) {
28    char *name = (char *) BAD_CAST xmlTextReaderName (xml);
29    if (xmlTextReaderNodeType (xml) == XML_READER_TYPE_ELEMENT) {
30      while (stricmp (name, "trkpt") == 0 &&
31             xmlTextReaderMoveToNextAttribute (xml)) {
32        char *aname = (char *) BAD_CAST xmlTextReaderName (xml);
33        char *avalue = (char *) BAD_CAST xmlTextReaderValue (xml);
34        if (stricmp (aname, "lat") == 0) tlat = Latitude (atof (avalue));
35        if (stricmp (aname, "lon") == 0) tlon = Longitude (atof (avalue));
36        xmlFree (aname);
37        xmlFree (avalue);
38      }
39    }
40    if (xmlTextReaderNodeType (xml) == XML_READER_TYPE_END_ELEMENT) {
41      if (stricmp (name, "trkpt") == 0) {
42        if (ptCnt++ > 0) {
43          int vehicle[] = { bicycleR, motorcarR, footR }, i;
44          for (i = 0; i < sizeof (vehicle) / sizeof (vehicle[0]); i++) {
45            Route (TRUE, 0, 0, /*tlon - flon, tlat - flat,*/ bicycleR, 0);
46            //routeNode *itr;
47            //for (itr = shortest; itr->shortest; itr = itr->shortest) {}
48            if (routeHeapSize > 0 && (!shortest || !shortest->shortest ||
49                !shortest->shortest->shortest)) break;
50          }
51          if (i == sizeof (vehicle) / sizeof (vehicle[0])) {
52//                fprintf (stderr, "%d\n", shortest->best);
53            printf ("<trk>\n<trkseg>\n<trkpt lat=\"%.5lf\" "
54              "lon=\"%.5lf\"/>\n<trkpt lat=\"%.5lf\" lon=\"%.5lf\"/>\n"
55              "</trkseg>\n</trk>\n", LatInverse (flat), LonInverse (flon),
56              LatInverse (tlat), LonInverse (tlon));
57          }
58        }
59        flat = tlat;
60        flon = tlon;
61      }
62      if (stricmp (name, "trk") == 0) ptCnt = 0; // Gap in track
63    }
64    xmlFree (name);
65  }
66  printf ("</gpx>\n");
67  return 0;
68}
Note: See TracBrowser for help on using the repository browser.