static void Main(string[] args) { Download.ToFile("http://files.itinero.tech/data/OSM/planet/europe/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf").Wait(); // build routerdb from raw OSM data. // check this for more info on RouterDb's: https://github.com/itinero/routing/wiki/RouterDb var routerDb = new RouterDb(); using (var sourceStream = File.OpenRead("luxembourg-latest.osm.pbf")) { routerDb.LoadOsmData(sourceStream, Vehicle.Car); } // create coder. var coder = new Coder(routerDb, new OsmCoderProfile()); // build a line location from a shortest path. // REMARK: this functionality is NOT part of the OpenLR-spec, just a convenient way to build a line location. var line = coder.BuildLine(new Itinero.LocalGeo.Coordinate(49.67218282319583f, 6.142280101776122f), new Itinero.LocalGeo.Coordinate(49.67776489459803f, 6.1342549324035645f)); // encode this location. var encoded = coder.Encode(line); Console.WriteLine(encoded); // decode this location. var decodedLine = coder.Decode(encoded) as ReferencedLine; #if DEBUG Console.ReadLine(); #endif }
static void EncodeDecodeRoute(Coder coder, Coordinate coordinate1, Coordinate coordinate2) { // build referenced line and calculate shortest path. Route route; var referencedLine = coder.BuildLine(coordinate1, coordinate2, out route); // encode. var encoded = coder.Encode(referencedLine); // decodee. var decodedReferencedLine = coder.Decode(encoded) as ReferencedLine; }
/// <summary> /// Tests encoding/decoding a route. /// </summary> public static void TestEncodeDecoderRoute(Coder coder, Coordinate[] points) { var referencedLine = coder.BuildLine(points); var referencedLineJson = referencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var encoded = coder.Encode(referencedLine); var decodedReferencedLine = coder.Decode(encoded) as ReferencedLine; var decodedReferencedLineJson = decodedReferencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var distance = DiscreteHausdorffDistance.Distance(referencedLine.ToLineString(coder.Router.Db), decodedReferencedLine.ToLineString(coder.Router.Db)); Assert.IsTrue(distance < .1); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.Write("Loading Luxembourg ... "); var routerDb = new RouterDb(); using (var sourceStream = File.OpenRead( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../luxembourg-latest.osm.pbf"))) { routerDb.LoadOsmData(sourceStream, Vehicle.Car); } Console.WriteLine("done"); // create coder. var coder = new Coder(routerDb, new OsmCoderProfile()); Console.WriteLine("Building a line location, and encoding it."); // build a line location from a shortest path. var line = coder.BuildLine( new Itinero.LocalGeo.Coordinate( 49.67218282319583f, 6.142280101776122f), new Itinero.LocalGeo.Coordinate( 49.67776489459803f, 6.1342549324035645f)); Console.WriteLine("original line: {0} --> {1}", line.StartLocation, line.EndLocation); // encode this location. var encoded = coder.Encode(line); Console.WriteLine("encoded line: {0}", encoded); // decode this location. var decodedLine = coder.Decode(encoded) as ReferencedLine; Console.WriteLine("decoded line: {0} --> {1}", decodedLine.StartLocation, decodedLine.EndLocation); }
/// <summary> /// Tests encoding/decoding a route. /// </summary> public static void TestEncodeDecoderRoute(Coder coder, Coordinate[] points) { var referencedLine = coder.BuildLine(points); var referencedLineJson = referencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); float positiveOffset, negativeOffset; RouterPoint source, target; var path = referencedLine.BuildPathFromLine(coder.Router.Db, out source, out positiveOffset, out target, out negativeOffset); var route = coder.Router.BuildRoute(coder.Profile.Profile, coder.Router.GetDefaultWeightHandler(coder.Profile.Profile), source, target, path); var encoded = coder.Encode(referencedLine); var decodedReferencedLine = coder.Decode(encoded) as ReferencedLine; var decodedReferencedLineJson = decodedReferencedLine.ToFeatures(coder.Router.Db).ToGeoJson(); var distance = DiscreteHausdorffDistance.Distance(referencedLine.ToLineString(coder.Router.Db), decodedReferencedLine.ToLineString(coder.Router.Db)); Assert.IsTrue(distance < .1); }