本文整理汇总了C#中OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter类的典型用法代码示例。如果您正苦于以下问题:C# OsmRoutingInterpreter类的具体用法?C# OsmRoutingInterpreter怎么用?C# OsmRoutingInterpreter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OsmRoutingInterpreter类属于OsmSharp.Routing.Osm.Interpreter命名空间,在下文中一共展示了OsmRoutingInterpreter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCHDepthFirstEnumerator
public void TestCHDepthFirstEnumerator()
{
const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";
// creates a new interpreter.
var interpreter = new OsmRoutingInterpreter();
// do the data processing.
var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
Assembly.GetExecutingAssembly()
.GetManifestResourceStream(embeddedString)),
interpreter,
Vehicle.Car);
// add the downward edges.
original.AddDownwardEdges();
// enumerate using depth-first search.
CHDepthFirstEnumerator enumerator =
new CHDepthFirstEnumerator(original);
HashSet<uint> vertices = new HashSet<uint>(
enumerator.Select(x => x.VertexId));
for (uint vertexId = 1; vertexId < original.VertexCount + 1; vertexId++)
{
Assert.IsTrue(vertices.Contains(vertexId));
}
}
示例2: RoutingRegressionTest1
public void RoutingRegressionTest1()
{
var interpreter = new OsmRoutingInterpreter();
var tagsIndex = new TagsTableCollectionIndex();
// do the data processing.
var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
var basicRouter = new Dykstra();
var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);
// resolve the three points in question.
var point35 = new GeoCoordinate(51.01257, 4.000753);
var point35resolved = router.Resolve(Vehicle.Car, point35);
var point45 = new GeoCoordinate(51.01315, 3.999588);
var point45resolved = router.Resolve(Vehicle.Car, point45);
// route between 35 and 45.
var routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
// route between 35 and 45.
var routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
}
示例3: InstructionGenerationAFewTurns
public void InstructionGenerationAFewTurns()
{
// create new interpreter.
var interpreter = new OsmRoutingInterpreter();
// create the language generator.
var languageGenerator = new LanguageTestGenerator();
// calculate the route.
OsmSharpRoute route = this.Calculate(
new GeoCoordinate(51.089900970459, 3.44386267662048),
new GeoCoordinate(51.0862655639648, 3.44465517997742));
// generate the instructions.
var instructionGenerator = new InstructionGenerator();
List<Instruction> instructions =
instructionGenerator.Generate(route, interpreter, languageGenerator);
// test the results in the language generator.
Assert.AreEqual(6, instructions.Count);
Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[2].Text);
Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[3].Text);
Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[4].Text);
Assert.AreEqual("GeneratePoi:1", instructions[5].Text);
}
示例4: RoutingSerializationV2CHRoutingComparisonTest
public void RoutingSerializationV2CHRoutingComparisonTest()
{
const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";
// creates a new interpreter.
var interpreter = new OsmRoutingInterpreter();
// do the data processing.
var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
Assembly.GetExecutingAssembly()
.GetManifestResourceStream(embeddedString)),
interpreter,
Vehicle.Car);
// create serializer.
var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer();
// serialize/deserialize.
TagsCollectionBase metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
byte[] byteArray;
using (var stream = new MemoryStream())
{
try
{
routingSerializer.Serialize(stream, original, metaData);
byteArray = stream.ToArray();
}
catch (Exception)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
throw;
}
}
IBasicRouterDataSource<CHEdgeData> deserializedVersion =
routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));
// create reference router.
original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
Assembly.GetExecutingAssembly()
.GetManifestResourceStream(embeddedString)),
interpreter,
Vehicle.Car);
var basicRouterOriginal = new CHRouter();
Router referenceRouter = Router.CreateCHFrom(
original, basicRouterOriginal, interpreter);
// try to do some routing on the deserialized version.
var basicRouter = new CHRouter();
Router router = Router.CreateCHFrom(
deserializedVersion, basicRouter, interpreter);
//this.TestCompareAll(original, referenceRouter, router);
}
示例5: CHEdgeGraphFileStreamTarget
/// <summary>
///
/// </summary>
/// <param name="stream"></param>
/// <param name="vehicle"></param>
public CHEdgeGraphFileStreamTarget(Stream stream, Vehicle vehicle)
{
_graphStream = stream;
var tagsIndex = new TagsTableCollectionIndex();
var interpreter = new OsmRoutingInterpreter();
_graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
_graphTarget = new CHEdgeGraphOsmStreamTarget(
_graph, interpreter, tagsIndex, vehicle);
}
示例6: TestSerializedRouting
/// <summary>
/// Tests routing from a serialized routing file.
/// </summary>
/// <param name="name"></param>
/// <param name="stream"></param>
/// <param name="testCount"></param>
public static void TestSerializedRouting(string name, Stream stream, int testCount)
{
var vehicle = Vehicle.Car;
var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.
// read from the OSM-stream.
var reader = new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream);
var interpreter = new OsmRoutingInterpreter();
var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
data.DropVertexIndex();
var targetData = new LiveGraphOsmStreamTarget(data, interpreter, tagsIndex);
targetData.RegisterSource(reader);
targetData.Pull();
data.RebuildVertexIndex();
// creates the live edge router.
var router = new Dykstra();
var performanceInfo = new PerformanceInfoConsumer("LiveRouting");
performanceInfo.Start();
performanceInfo.Report("Routing {0} routes...", testCount);
var successCount = 0;
var totalCount = testCount;
var latestProgress = -1.0f;
while (testCount > 0)
{
var from = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;
var to = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;
var route = router.Calculate(data, interpreter, vehicle, from, to);
if (route != null)
{
successCount++;
}
testCount--;
// report progress.
var progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100);
if (progress != latestProgress)
{
OsmSharp.Logging.Log.TraceEvent("LiveRouting", TraceEventType.Information,
"Routing... {0}%", progress);
latestProgress = progress;
}
}
performanceInfo.Stop();
OsmSharp.Logging.Log.TraceEvent("LiveRouting", OsmSharp.Logging.TraceEventType.Information,
string.Format("{0}/{1} routes successfull!", successCount, totalCount));
}
示例7: Engine
private Engine()
{
if (string.IsNullOrWhiteSpace(PbfDataFilePath))
{
throw new NullReferenceException("PbfDataFilePath must be set.");
}
if (!File.Exists(PbfDataFilePath))
{
throw new NullReferenceException("PbfDataFilePath '" + PbfDataFilePath + "' does not exist.");
}
// keeps a memory-efficient version of the osm-tags.
var tagsIndex = new OsmTagsIndex();
// creates a routing interpreter. (used to translate osm-tags into a routable network)
var interpreter = new OsmRoutingInterpreter();
// create a routing datasource, keeps all processed osm routing data.
var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);
// load data into this routing datasource.
Stream osmPbfData = new FileInfo(PbfDataFilePath).OpenRead(); // for example moscow!
using (osmPbfData)
{
var targetData = new
SimpleWeighedDataGraphProcessingTarget(
osmData, interpreter, osmData.TagsIndex, VehicleEnum.Car);
// replace this with PBFdataProcessSource when having downloaded a PBF file.
var dataProcessorSource = new
PBFDataProcessorSource(osmPbfData);
// pre-process the data.
var stopwatch = new Stopwatch();
stopwatch.Start();
var sorter = new DataProcessorFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
stopwatch.Stop();
}
// create the router object: there all routing functions are available.
router = new Router<SimpleWeighedEdge>(
osmData, interpreter, new DykstraRoutingLive(osmData.TagsIndex));
}
示例8: CalculateTSP
/// <summary>
/// Calculates the TSP.
/// </summary>
/// <param name="dataStream"></param>
/// <param name="csvStream"></param>
/// <param name="pbf"></param>
/// <param name="vehicleEnum"></param>
/// <returns></returns>
private Route CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, Vehicle vehicleEnum)
{
// create the router.
OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
Router router = Router.CreateLiveFrom(
new XmlOsmStreamSource(dataStream), interpreter);
// read the source files.
const int latitudeIdx = 2;
const int longitudeIdx = 3;
string[][] pointStrings = DelimitedFileHandler.ReadDelimitedFileFromStream(
csvStream,
DelimiterType.DotCommaSeperated);
var points = new List<RouterPoint>();
int cnt = 10;
foreach (string[] line in pointStrings)
{
if (points.Count >= cnt)
{
break;
}
var latitudeString = (string)line[latitudeIdx];
var longitudeString = (string)line[longitudeIdx];
//string route_ud = (string)line[1];
double longitude = 0;
double latitude = 0;
if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out latitude))
{
var point = new GeoCoordinate(latitude, longitude);
RouterPoint resolved = router.Resolve(Vehicle.Car, point);
if (resolved != null && router.CheckConnectivity(Vehicle.Car, resolved, 100))
{
points.Add(resolved);
}
}
}
var tspSolver = new RouterTSPWrapper<RouterTSP>(
new RouterTSPAEXGenetic(), router, interpreter);
return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
}
示例9: TestSerialization
/// <summary>
/// Tests preprocessing data from a PBF file.
/// </summary>
/// <param name="name"></param>
/// <param name="pbfFile"></param>
public static void TestSerialization(string name, string pbfFile)
{
var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
var stream = testFile.OpenRead();
var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
source.RegisterSource(new PBFOsmStreamSource(stream));
var testOutputFile = new FileInfo(@"test.pedestrian.routing");
testOutputFile.Delete();
Stream writeStream = testOutputFile.OpenWrite();
var tagsIndex = new TagsTableCollectionIndex();
var interpreter = new OsmRoutingInterpreter();
var graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize");
performanceInfo.Start();
performanceInfo.Report("Pulling from {0}...", testFile.Name);
var data = CHEdgeGraphOsmStreamTarget.Preprocess(
source, new OsmRoutingInterpreter(), Vehicle.Car);
var metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
var routingSerializer = new CHEdgeFlatfileSerializer();
routingSerializer.Serialize(writeStream, data, metaData);
stream.Dispose();
writeStream.Dispose();
OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
performanceInfo.Stop();
performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Deserialize");
performanceInfo.Start();
performanceInfo.Report("Deserializing again...");
// open file again and read.
writeStream = testOutputFile.OpenRead();
var deserializedGraph = routingSerializer.Deserialize(writeStream);
performanceInfo.Stop();
}
示例10: SQLServerRoutingRegressionTests1
public void SQLServerRoutingRegressionTests1()
{
// the connectionstring.
string connectionString =
@"Server=windows8-test\sqlexpress;User Id=OsmSharp;Password=OsmSharp;Database=OsmData;";
// drop whatever data is there.
SqlConnection sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
SQLServer.SimpleSchema.SchemaTools.SQLServerSimpleSchemaTools.Remove(sqlConnection);
sqlConnection.Close();
// create the source from the osm file.
var xmlSource = new XmlDataProcessorSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"OsmSharp.Osm.Data.SQLServer.Unittests.Data.ukraine1.osm"));
// create the SQLServer processor target.
var testTarget = new SQLServerSimpleSchemaDataProcessorTarget(connectionString, true);
testTarget.RegisterSource(xmlSource); // register the source.
testTarget.Pull(); // pull the data from source to target.
var source = new SQLServerSimpleSchemaSource(
connectionString);
var tagsIndex = new OsmTagsIndex();
var interpreter = new OsmRoutingInterpreter();
var routingData = new OsmSourceRouterDataSource(
interpreter, tagsIndex, source, VehicleEnum.Car);
IRouter<RouterPoint> router = new Router<PreProcessedEdge>(routingData, interpreter,
new DykstraRoutingPreProcessed(routingData.TagsIndex));
OsmSharpRoute route;
RouterPoint point1 = router.Resolve(VehicleEnum.Car,
new GeoCoordinate(50.3150034243338, 34.8784106812928));
RouterPoint point2 = router.Resolve(VehicleEnum.Car,
new GeoCoordinate(50.3092549484347, 34.8894929841615));
route = router.Calculate(VehicleEnum.Car, point1, point2);
Assert.IsNotNull(route);
}
示例11: Engine
/// <summary>
/// Initializes a new instance of the <see cref="Engine"/> class.
/// </summary>
protected Engine()
{
// keeps a memory-efficient version of the osm-tags.
var tagsIndex = new OsmTagsIndex();
// creates a routing interpreter. (used to translate osm-tags into a routable network)
interpreter = new OsmRoutingInterpreter();
// create a routing datasource, keeps all processed osm routing data.
var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);
// load data into this routing datasource.
var fileSource = HostingEnvironment.MapPath("~/App_Data/Manchester.osm.pbf");
Stream osmXmlData = new FileInfo(fileSource).OpenRead(); // for example moscow!
using (osmXmlData)
{
var targetData = new SimpleWeighedDataGraphProcessingTarget(
osmData,
interpreter,
osmData.TagsIndex,
VehicleEnum.Car);
// replace this with PBFdataProcessSource when having downloaded a PBF file.
var dataProcessorSource = new
OsmSharp.Osm.Data.PBF.Raw.Processor.PBFDataProcessorSource(osmXmlData);
// pre-process the data.
var sorter = new DataProcessorFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
}
// create the router object: there all routing functions are available.
router = new Router<SimpleWeighedEdge>(
osmData,
interpreter,
new DykstraRoutingLive(osmData.TagsIndex));
}
示例12: RoutingRegressionTest1
public void RoutingRegressionTest1()
{
OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
SimpleTagsIndex tags_index = new SimpleTagsIndex();
// do the data processing.
DynamicGraphRouterDataSource<LiveEdge> memory_data =
new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
memory_data, interpreter, memory_data.TagsIndex);
XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
OsmStreamFilterSort sorter = new OsmStreamFilterSort();
sorter.RegisterSource(data_processor_source);
target_data.RegisterSource(sorter);
target_data.Pull();
IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);
// resolve the three points in question.
GeoCoordinate point35 = new GeoCoordinate(51.01257, 4.000753);
RouterPoint point35resolved = router.Resolve(Vehicle.Car, point35);
// GeoCoordinate point40 = new GeoCoordinate(51.01250, 4.000013);
// RouterPoint point40resolved = router.Resolve(Vehicle.Car, point40);
GeoCoordinate point45 = new GeoCoordinate(51.01315, 3.999588);
RouterPoint point45resolved = router.Resolve(Vehicle.Car, point45);
// route between 35 and 45.
Route routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
// GeoCoordinate point129 = new GeoCoordinate(51.01239, 3.999573);
// RouterPoint point129resolved = router.Resolve(Vehicle.Car, point129);
// route between 35 and 45.
Route routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
}
示例13: InstructionGenerationNoTurns
public void InstructionGenerationNoTurns()
{
// create new interpreter.
var interpreter = new OsmRoutingInterpreter();
// create the language generator.
var languageGenerator = new LanguageTestGenerator();
// calculate the route.
OsmSharpRoute route = this.Calculate(
new GeoCoordinate(51.09002, 3.44380),
new GeoCoordinate(51.089900970459, 3.44386267662048));
// generate the instructions.
var instructionGenerator = new InstructionGenerator();
List<Instruction> instructions =
instructionGenerator.Generate(route, interpreter, languageGenerator);
// test the results in the language generator.
Assert.AreEqual(2, instructions.Count);
Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
Assert.AreEqual("GeneratePoi:1", instructions[1].Text);
}
示例14: Main
static void Main(string[] args)
{
OsmSharp.Logging.Log.Enable();
OsmSharp.Logging.Log.RegisterListener(new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());
// read the source file.
var lines = OsmSharp.IO.DelimitedFiles.DelimitedFileHandler.ReadDelimitedFile(null,
new FileInfo("bicylestations.csv").OpenRead(), OsmSharp.IO.DelimitedFiles.DelimiterType.DotCommaSeperated, true);
// create router.
var interpreter = new OsmRoutingInterpreter();
var router = Router.CreateLiveFrom(new PBFOsmStreamSource(new FileInfo("antwerp.osm.pbf").OpenRead()), interpreter);
// resolve all points.
var resolvedPoints = new List<RouterPoint>();
foreach(var line in lines)
{
var latitude = double.Parse(line[0], System.Globalization.CultureInfo.InvariantCulture);
var longitude = double.Parse(line[1], System.Globalization.CultureInfo.InvariantCulture);
var refId = double.Parse(line[2], System.Globalization.CultureInfo.InvariantCulture);
var resolved = router.Resolve(Vehicle.Bicycle, new Math.Geo.GeoCoordinate(latitude, longitude));
if(resolved != null && router.CheckConnectivity(Vehicle.Bicycle, resolved, 100))
{ // point exists and is connected.
resolvedPoints.Add(resolved);
}
else
{ // report that the point could not be resolved.
Console.WriteLine("Point with ref {0} could not be resolved!", refId);
}
}
// calculate TSP.
var tspSolver = new RouterTSPWrapper<RouterTSP>(
new RouterTSPAEXGenetic(1000, 200), router, interpreter);
var route = tspSolver.CalculateTSP(Vehicle.Bicycle, resolvedPoints.ToArray());
route.SaveAsGpx(new FileInfo("output.gpx").OpenWrite());
}
示例15: TestCHEdgeDifferenceNonContracted
public void TestCHEdgeDifferenceNonContracted()
{
IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();
EdgeDifference edgeDifference = this.BuildEdgeDifference(interpreter);
Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
Assert.AreEqual(6, edgeDifference.Calculate(2));
Assert.AreEqual(0, edgeDifference.Calculate(3));
Assert.AreEqual(0, edgeDifference.Calculate(4));
Assert.AreEqual(0, edgeDifference.Calculate(5));
Assert.AreEqual(0, edgeDifference.Calculate(6));
Assert.AreEqual(3, edgeDifference.Calculate(7));
Assert.AreEqual(3, edgeDifference.Calculate(8));
Assert.AreEqual(0, edgeDifference.Calculate(9));
Assert.AreEqual(3, edgeDifference.Calculate(10));
Assert.AreEqual(3, edgeDifference.Calculate(11));
Assert.AreEqual(0, edgeDifference.Calculate(12));
Assert.AreEqual(0, edgeDifference.Calculate(13));
Assert.AreEqual(0, edgeDifference.Calculate(14));
Assert.AreEqual(0, edgeDifference.Calculate(15));
Assert.AreEqual(3, edgeDifference.Calculate(16));
Assert.AreEqual(0, edgeDifference.Calculate(17));
Assert.AreEqual(0, edgeDifference.Calculate(18));
Assert.AreEqual(0, edgeDifference.Calculate(19));
Assert.AreEqual(-1, edgeDifference.Calculate(20));
Assert.AreEqual(0, edgeDifference.Calculate(21));
Assert.AreEqual(0, edgeDifference.Calculate(22));
Assert.AreEqual(-1, edgeDifference.Calculate(23));
}