Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8315 for branches


Ignore:
Timestamp:
07/20/12 22:57:05 (12 years ago)
Author:
spimming
Message:

#1894: write result in gpx file for visualization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs

    r8314 r8315  
    11
    22using System;
     3using System.Xml;
    34using HeuristicLab.Algorithms.GraphRouting;
     5using HeuristicLab.Problems.RoutePlanning.Graph;
     6using HeuristicLab.Problems.RoutePlanning.Osm;
    47using HeuristicLab.Problems.RoutePlanning.Osm.Data;
    58namespace HeuristicLab.Problems.RoutePlanning.Test {
     
    2629      foreach (long i in result) System.Console.Write(i + "; ");
    2730      Console.WriteLine();
     31
     32      WriteGPXFile(graph, result);
     33
    2834      System.Console.Read();
    2935    }
     
    5258      System.Console.Read();
    5359    }
     60
     61    private static void WriteGPXFile(Graph.Graph graph, long[] route) {
     62      XmlWriterSettings settings = new XmlWriterSettings();
     63      settings.Indent = true;
     64      settings.IndentChars = ("   ");
     65
     66      using (XmlWriter writer = XmlWriter.Create("RoutePath.gpx", settings)) {
     67        writer.WriteStartElement("gpx", "http://www.topografix.com/GPX/1/0");
     68        writer.WriteAttributeString("version", "1.1");
     69        writer.WriteAttributeString("creator", "cloudia");
     70
     71        foreach (long nodeId in route) {
     72          Vertex<Node> node = graph.GetVertex(nodeId);
     73          writer.WriteStartElement("wpt");
     74          writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude));
     75          writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude));
     76          writer.WriteEndElement(); // wpt
     77        }
     78
     79        //writer.WriteStartElement("rte");
     80        //foreach (long nodeId in route) {
     81        //  Vertex<Node> node = graph.GetVertex(nodeId);
     82        //  writer.WriteStartElement("rtept");
     83        //  writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude));
     84        //  writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude));
     85        //  writer.WriteEndElement(); // rtept
     86        //}
     87        //writer.WriteEndElement(); // rte
     88
     89        //writer.WriteStartElement("trk");
     90        //writer.WriteElementString("name", "RoutePath");
     91        ////writer.WriteEndElement(); // name
     92        //writer.WriteStartElement("trkseq");
     93        //foreach (long nodeId in route) {
     94        //  Vertex<Node> node = graph.GetVertex(nodeId);
     95        //  writer.WriteStartElement("trkpt");
     96        //  writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude));
     97        //  writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude));
     98        //  writer.WriteEndElement(); // trkpt
     99        //}
     100        //writer.WriteEndElement(); // trkseq
     101        //writer.WriteEndElement(); // trk
     102
     103        writer.WriteEndElement(); // gpx
     104      }
     105    }
    54106  }
    55107}
Note: See TracChangeset for help on using the changeset viewer.