本文整理汇总了C#中OsmSharp.Osm.Xml.Streams.XmlOsmStreamSource类的典型用法代码示例。如果您正苦于以下问题:C# XmlOsmStreamSource类的具体用法?C# XmlOsmStreamSource怎么用?C# XmlOsmStreamSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlOsmStreamSource类属于OsmSharp.Osm.Xml.Streams命名空间,在下文中一共展示了XmlOsmStreamSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRouter
/// <summary>
/// Returns a new router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="embeddedName"></param>
/// <param name="contract"></param>
/// <returns></returns>
public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName, bool contract)
{
if (_data == null)
{
_data = new Dictionary<string, DynamicGraphRouterDataSource<CHEdgeData>>();
}
DynamicGraphRouterDataSource<CHEdgeData> data = null;
if (!_data.TryGetValue(embeddedName, out data))
{
var tagsIndex = new SimpleTagsIndex();
// do the data processing.
data =
new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
var targetData = new CHEdgeGraphOsmStreamTarget(
data, interpreter, tagsIndex, Vehicle.Car);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
"OsmSharp.Test.Unittests.{0}", embeddedName)));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
// do the pre-processing part.
var preProcessor = new CHPreProcessor(data,
new SparseOrdering(data), new DykstraWitnessCalculator());
preProcessor.Start();
_data[embeddedName] = data;
}
return Router.CreateCHFrom(data, new CHRouter(), interpreter);
}
示例2: BuildRouter
/// <summary>
/// Returns a new router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="embeddedName"></param>
/// <returns></returns>
public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName)
{
if (_data == null)
{
_data = new Dictionary<string, RouterDataSource<CHEdgeData>>();
}
RouterDataSource<CHEdgeData> data = null;
if (!_data.TryGetValue(embeddedName, out data))
{
var tagsIndex = new TagsIndex();
// do the data processing.
data = new RouterDataSource<CHEdgeData>(new DirectedGraph<CHEdgeData>(), tagsIndex);
var targetData = new CHEdgeGraphOsmStreamTarget(
data, interpreter, tagsIndex, Vehicle.Car);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
"OsmSharp.Test.Unittests.{0}", embeddedName)));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
_data[embeddedName] = data;
}
return Router.CreateCHFrom(data, new CHRouter(), interpreter);
}
示例3: 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);
}
示例4: BuildRouter
/// <summary>
/// Returns a new router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="embeddedName"></param>
/// <param name="contract"></param>
/// <returns></returns>
public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName, bool contract)
{
if (_data == null)
{
_data = new Dictionary<string, DynamicGraphRouterDataSource<LiveEdge>>();
}
DynamicGraphRouterDataSource<LiveEdge> data = null;
if (!_data.TryGetValue(embeddedName, out data))
{
var tagsIndex = new TagsTableCollectionIndex();
// do the data processing.
data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(
data, interpreter, tagsIndex, new Vehicle[] { Vehicle.Car }, false);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
"OsmSharp.Test.Unittests.{0}", embeddedName)));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
_data[embeddedName] = data;
}
return Router.CreateLiveFrom(data, new Dykstra(), interpreter);
}
示例5: GetHighways
public async Task<List<CompleteWay>> GetHighways(LatLng northEast, LatLng southWest)
{
var boundsString = string.Join(",", southWest.lat, southWest.lng, northEast.lat, northEast.lng);
var address = $"{OVERPASS_INTERPRETER_ADDRESS}?data=(way[\"highway\"]({boundsString});>;);out;";
using (var client = new HttpClient())
{
var response = await client.GetAsync(address);
var source = new XmlOsmStreamSource(await response.Content.ReadAsStreamAsync());
var completeSource = new OsmSimpleCompleteStreamSource(source);
return completeSource.OfType<CompleteWay>().ToList();
}
}
示例6: FixtureSetUp
public void FixtureSetUp()
{
// Arrange
const string connectionString = @"Server=TestDataWindows\SQLEXPRESS;Database=osmsharp;User Id=osmsharp;Password=osmsharp;";
var sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
var source = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.SQLServer.Data.ukraine1.osm"));
//var source = new PBFDataProcessorSource(new FileInfo("C:\\great-britain-latest.osm.pbf").OpenRead());
// Act
_testTarget = new SQLServerDDLChecksStreamTarget(connectionString);
_testTarget.RegisterSource(source);
_testTarget.Pull();
}
示例7: BuildRouter
/// <summary>
/// Returns a new router.
/// </summary>
/// <returns></returns>
public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName)
{
var tagsIndex = new TagsIndex();
// do the data processing.
var data = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
var targetData = new GraphOsmStreamTarget(
data, interpreter, tagsIndex, new Vehicle[] { Vehicle.Car }, false);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
"OsmSharp.Routing.Test.data.{0}", embeddedName)));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
return Router.CreateFrom(data, new Dykstra(), interpreter);
}
示例8: CreateRouter
/// <summary>
/// Creates a router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="manifestResourceName"></param>
/// <returns></returns>
protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
{
TagsIndex tagsIndex = new TagsIndex();
// do the data processing.
var memoryData =
new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
var targetData = new GraphOsmStreamTarget(
memoryData, interpreter, tagsIndex, null, false);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
IRoutingAlgorithm<Edge> basicRouter = new Dykstra();
return Router.CreateFrom(memoryData, basicRouter, interpreter);
}
示例9: CreateRouter
/// <summary>
/// Creates a router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="manifestResourceName"></param>
/// <returns></returns>
protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
{
SimpleTagsIndex tagsIndex = new SimpleTagsIndex();
// do the data processing.
DynamicGraphRouterDataSource<LiveEdge> memoryData =
new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
memoryData, interpreter, memoryData.TagsIndex);
XmlOsmStreamSource dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
OsmStreamFilterSort sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
target_data.RegisterSource(sorter);
target_data.Pull();
IBasicRouter<LiveEdge> basicRouter = new DykstraRoutingLive(memoryData.TagsIndex);
return Router.CreateLiveFrom(memoryData, basicRouter, interpreter);
}
示例10: BuildDykstraDataSource
/// <summary>
/// Builds a raw data source.
/// </summary>
/// <returns></returns>
public DynamicGraphRouterDataSource<LiveEdge> BuildDykstraDataSource(
IOsmRoutingInterpreter interpreter, string embeddedName)
{
var tagsIndex = new SimpleTagsIndex();
// do the data processing.
var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(
data, interpreter, data.TagsIndex);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
"OsmSharp.Test.Unittests.{0}", embeddedName)));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
return data;
}
示例11: Main
static void Main(string[] args)
{
// query to find all bicyle stations within the city of Antwerp.
var query = "node(51.18881185379808,4.370841979980469,51.244939510768184,4.454612731933594)[\"amenity\"=\"bicycle_rental\"];out;";
// create and execute the webrequest.
var request = WebRequest.Create(
"http://overpass.osm.rambler.ru/cgi/interpreter?data=" + query);
request.Method = "GET";
var requestStream = request.GetResponse().GetResponseStream(); // get the data.
// use an XML data processor source.
var source = new XmlOsmStreamSource(requestStream);
// pull the data from the stream and deserialize XML.
var osmEntities = new List<OsmGeo>(source);
var outputCsv = new List<string[]>();
for(int idx = 0; idx < osmEntities.Count; idx++)
{
var node = osmEntities[idx] as Node;
var refId = string.Empty;
var name = string.Empty;
if (node != null &&
node.Tags.TryGetValue("ref", out refId) &&
node.Tags.TryGetValue("name", out name))
{
var latitude = node.Coordinate.Latitude;
var longitude = node.Coordinate.Longitude;
outputCsv.Add(new string[] { latitude.ToInvariantString(), longitude.ToInvariantString(), refId, name });
}
if (!node.Tags.TryGetValue("ref", out refId))
{
Console.WriteLine("Node {0} has no ref.", node.Id.Value);
}
if (!node.Tags.TryGetValue("name", out name))
{
Console.WriteLine("Node {0} has no name.", node.Id.Value);
}
}
OsmSharp.IO.DelimitedFiles.DelimitedFileHandler.WriteDelimitedFile(null, outputCsv.ToArray(),
new StreamWriter(new FileInfo("bicylestations.csv").OpenWrite()), OsmSharp.IO.DelimitedFiles.DelimiterType.DotCommaSeperated);
}
示例12: XmlDataProcessorSourceReset
public void XmlDataProcessorSourceReset()
{
// generate the source.
var source = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"OsmSharp.Test.Unittests.api.osm"));
// pull the data out.
var target = new OsmStreamTargetEmpty();
target.RegisterSource(source);
target.Pull();
// reset the source.
if (source.CanReset)
{
source.Reset();
// pull the data again.
target.Pull();
}
}
示例13: 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);
}
示例14: CreateRouter
/// <summary>
/// Creates a router.
/// </summary>
/// <param name="interpreter"></param>
/// <param name="manifestResourceName"></param>
/// <returns></returns>
protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
{
TagsIndex tagsIndex = new TagsIndex();
// do the data processing.
var data = new RouterDataSource<CHEdgeData>(new DirectedGraph<CHEdgeData>(), tagsIndex);
var targetData = new CHEdgeGraphOsmStreamTarget(
data, interpreter, tagsIndex, Vehicle.Car);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
// do the pre-processing part.
var witnessCalculator = new DykstraWitnessCalculator();
var preProcessor = new CHPreprocessor(data,
new EdgeDifferenceContractedSearchSpace(data, witnessCalculator), witnessCalculator);
preProcessor.Start();
return Router.CreateCHFrom(data, new CHRouter(), interpreter);
}
示例15: GetHighwaysAroundATrace
public async Task<List<CompleteWay>> GetHighwaysAroundATrace(IEnumerable<Coordinate> coordinates)
{
var overpassQueryPostfix = @"way[highway](bn)-> .w;
node(w.w)-> .n;
(node._.n; way.w);
out qt; ";
var overpassQueryNodes = "";
foreach (var coordinate in coordinates)
{
// lat, lng
overpassQueryNodes += $"(._; node(around: 300, {coordinate.Y}, {coordinate.X}););\n";
}
using (var client = new HttpClient())
{
var response = await client.PostAsync(OVERPASS_INTERPRETER_ADDRESS, new StringContent(overpassQueryNodes + overpassQueryPostfix));
Trace.WriteLine(await response.Content.ReadAsStringAsync());
var source = new XmlOsmStreamSource(await response.Content.ReadAsStreamAsync());
var cache = new OsmDataCacheMemory();
var completeSource = new OsmSimpleCompleteStreamSource(source, cache);
var list = completeSource.OfType<CompleteWay>().ToList();
return list;
}
}