/// <summary> /// Tests read/write and actual data file. /// </summary> protected void TestReadWriteData() { this.NotifyEmptyExpected(); // empty test database. // create the target and pull the data from the test-file into the sqlite database. OsmStreamTarget target = this.CreateDataStreamTarget(); PBFOsmStreamSource source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf")); target.RegisterSource(source); target.Pull(); IDataSourceReadOnly dataSource = this.CreateDataSource(); MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source); foreach (Node node in memorySource.GetNodes()) { Node dbNode = dataSource.GetNode(node.Id.Value); this.CompareNodes(node, dbNode); } foreach (Way way in memorySource.GetWays()) { Way dbWay = dataSource.GetWay(way.Id.Value); this.CompareWays(way, dbWay); } foreach (Relation relation in memorySource.GetRelations()) { Relation dbRelation = dataSource.GetRelation(relation.Id.Value); this.CompareRelations(relation, dbRelation); } }
public void AddLayerOsm(Stream stream, Stream cssStream) { if (stream == null) { return; } // Create the MapCSS image source, which is used as image source for areas of the map var imageSource = new MapCSSDictionaryImageSource(); // Load mapcss style interpreter. var mapCSSInterpreter = new MapCSSInterpreter(cssStream, imageSource); // Load data from pbf file into a memory data source var input = new PBFOsmStreamSource(stream); //var filter = new OsmStreamFilterBoundingBox(mapView.MapBoundingBox); //filter.RegisterSource(input); //var source = MemoryDataSource.CreateFromPBFStream(input); var source = MemoryDataSource.CreateFrom(input); //var source = new MemoryDataSource(); // If there is allready a layer with map, close it if (layerMap != null) { layerMap.Close(); } tileUrl = ""; // Add new map layer layerMap = map?.AddLayerOsm(source, mapCSSInterpreter); }
public static RenderingInstance Build(OsmStreamSource streamSource, StyleInterpreter interpreter) { var instance = new RenderingInstance(); MemoryDataSource dataSource = MemoryDataSource.CreateFrom(streamSource); instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection)); return(instance); }
/// <summary> /// Tests writing data and getting ways using it's nodes. /// </summary> protected void TestGetWaysForNode() { this.NotifyEmptyExpected(); // empty test database. // create the target and pull the data from the test-file into the sqlite database. OsmStreamTarget target = this.CreateDataStreamTarget(); target.Initialize(); PBFOsmStreamSource source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf")); IDataSourceReadOnly dataSource = this.CreateDataSource(); source.Initialize(); while (source.MoveNext()) { switch (source.Current().Type) { case OsmGeoType.Way: Way way = (source.Current() as Way); target.AddWay(way); target.Flush(); if (way.Nodes != null) { foreach (long nodeId in way.Nodes) { IList <Way> ways = dataSource.GetWaysFor(nodeId); Assert.IsNotNull(ways); Assert.IsTrue(ways.Count > 0); List <Way> foundWays = new List <Way>(ways.Where <Way>(x => x.Id == way.Id)); Assert.AreEqual(1, foundWays.Count); } } break; } } MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source); foreach (Way way in memorySource.GetWays()) { if (way.Nodes != null) { foreach (long nodeId in way.Nodes) { IList <Way> ways = dataSource.GetWaysFor(nodeId); Assert.IsNotNull(ways); Assert.IsTrue(ways.Count > 0); List <Way> foundWays = new List <Way>(ways.Where <Way>(x => x.Id == way.Id)); Assert.AreEqual(1, foundWays.Count); } } } }
/// <summary> /// Test simple to complete conversion on the given resource. /// </summary> /// <param name="embeddedResource"></param> private void TestSimpleToCompleteOn(string embeddedResource) { var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResource)); // fill the memory data source with source-data. var referenceSource = MemoryDataSource.CreateFrom(dataProcessorSource); // pull the complete objects. dataProcessorSource.Reset(); var list = this.PullToCompleteList(dataProcessorSource); // compare the two. this.Compare(referenceSource, list); }
/// <summary> /// Builds a rendering instance for a mapCSS file. /// </summary> /// <param name="streamSource"></param> /// <param name="mapCSSFile"></param> /// <returns></returns> public static RenderingInstance BuildForMapCSS(OsmStreamSource streamSource, Stream mapCSSFile) { var instance = new RenderingInstance(); // load data into memory. var dataSource = MemoryDataSource.CreateFrom(streamSource); // create mapCSS interpreter. var interpreter = new MapCSSInterpreter(mapCSSFile, new MapCSSDictionaryImageSource()); // add layer to map. instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection)); return(instance); }
/// <summary> /// Tests a few boundingbox queries. /// </summary> protected void TestBoundingBoxQueries() { this.NotifyEmptyExpected(); // empty test database. // create the target and pull the data from the test-file into the sqlite database. OsmStreamTarget target = this.CreateDataStreamTarget(); PBFOsmStreamSource source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf")); target.RegisterSource(source); target.Pull(); IDataSourceReadOnly dataSource = this.CreateDataSource(); MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source); // get reference data and compare to the real thing! GeoCoordinateBox box = memorySource.BoundingBox; IList <OsmGeo> referenceBoxData = memorySource.Get(box, null); IList <OsmGeo> boxData = dataSource.Get(box, null); this.CompareResults(referenceBoxData, boxData); // increase box size and compare again. box = memorySource.BoundingBox.Resize(0.1); referenceBoxData = memorySource.Get(box, null); boxData = dataSource.Get(box, null); this.CompareResults(referenceBoxData, boxData); // descrese box size and compare again. box = memorySource.BoundingBox.Scale(0.5); referenceBoxData = memorySource.Get(box, null); boxData = dataSource.Get(box, null); this.CompareResults(referenceBoxData, boxData); // descrese box size and compare again. box = memorySource.BoundingBox.Scale(0.25); referenceBoxData = memorySource.Get(box, null); boxData = dataSource.Get(box, null); this.CompareResults(referenceBoxData, boxData); // descrese box size and compare again. box = memorySource.BoundingBox.Scale(0.1); referenceBoxData = memorySource.Get(box, null); boxData = dataSource.Get(box, null); this.CompareResults(referenceBoxData, boxData); }
private void button_Click(object sender, RoutedEventArgs e) { //initialize map. var map = new OsmSharp.UI.Map.Map(new WebMercator()); // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); // initialize mapcss interpreter. var mapCssInterpreter = new MapCSSInterpreter(File.OpenRead("data\\opencyclemap.mapcss"), imageSource); var source = new XmlOsmStreamSource(File.OpenRead("data\\test.osm")); var testLayer = new LayerOsm(MemoryDataSource.CreateFrom(source), mapCssInterpreter, new WebMercator()); // map.AddLayer(testLayer); map.AddLayerTile(@"http://b.tile.openstreetmap.org/{z}/{x}/{y}.png"); // map.BackColor = SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.Black).Value; MapControl.SuspendNotifyMapViewChanged(); // set control properties. MapControl.MapZoom = 14; MapControl.Map = map; MapControl.MapCenter = testLayer.Envelope.Center; // MapControl.MapCenter = new GeoCoordinate(51.2667, 4.7914); // wechel var l = new MapLayerWrapper(new WebMercator()); //l.AddPoint(testLayer.Envelope.Center, 20, SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.Black).Value); MapControl.AddLayer(l, 100); MapControl.ResumeNotifyMapViewChanged(); }
public void Scene2DSimpleSerializeDeserializeTest() { // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); // load mapcss style interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"), imageSource); // initialize the data source. var xmlSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.test.osm")); IEnumerable <OsmGeo> dataSource = xmlSource; MemoryDataSource source = MemoryDataSource.CreateFrom(xmlSource); // get data. var scene = new Scene2DSimple(); var projection = new WebMercator(); GeoCoordinateBox box = null; foreach (var osmGeo in dataSource) { CompleteOsmGeo completeOsmGeo = null; switch (osmGeo.Type) { case OsmGeoType.Node: completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node); break; case OsmGeoType.Way: completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way, source); break; case OsmGeoType.Relation: completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation, source); break; } // update box. if (completeOsmGeo != null) { if (box == null) { box = completeOsmGeo.BoundingBox; } else if (completeOsmGeo.BoundingBox != null) { box = box + completeOsmGeo.BoundingBox; } } // translate each object into scene object. mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo); } // create the stream. var stream = new MemoryStream(); scene.Serialize(stream, false); // deserialize the stream. IScene2DPrimitivesSource sceneSource = Scene2DSimple.Deserialize(stream, false); if (box != null) { // query both and get the same results. int counter = 100; var rand = new Random(); while (counter > 0) { var queryBox = new GeoCoordinateBox( box.GenerateRandomIn(rand), box.GenerateRandomIn(rand)); var zoomFactor = (float)projection.ToZoomFactor(15); View2D testView = View2D.CreateFromBounds( projection.LatitudeToY(queryBox.MaxLat), projection.LongitudeToX(queryBox.MinLon), projection.LatitudeToY(queryBox.MinLat), projection.LongitudeToX(queryBox.MaxLon)); var testScene = new Scene2DSimple(); sceneSource.Get(testScene, testView, zoomFactor); // var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor)); // var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor)); //Assert.AreEqual(resultReference.Count, resultIndex.Count); //foreach (var data in resultIndex) //{ // Assert.IsTrue(resultReference.Contains(data)); //} //foreach (var data in resultReference) //{ // Assert.IsTrue(resultIndex.Contains(data)); //} counter--; } } }
/// <summary> /// Tests writing data and getting relations using it's members. /// </summary> protected void TestGetRelationsForMember() { this.NotifyEmptyExpected(); // empty test database. // create the target and pull the data from the test-file into the sqlite database. OsmStreamTarget target = this.CreateDataStreamTarget(); target.Initialize(); PBFOsmStreamSource source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf")); IDataSourceReadOnly dataSource = this.CreateDataSource(); source.Initialize(); while (source.MoveNext()) { switch (source.Current().Type) { case OsmGeoType.Relation: Relation relation = (source.Current() as Relation); target.AddRelation(relation); target.Flush(); if (relation.Members != null) { foreach (var member in relation.Members) { OsmGeoType type = OsmGeoType.Node; switch (member.MemberType.Value) { case OsmGeoType.Node: type = OsmGeoType.Node; break; case OsmGeoType.Way: type = OsmGeoType.Way; break; case OsmGeoType.Relation: type = OsmGeoType.Relation; break; } IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value); Assert.IsNotNull(relations); Assert.IsTrue(relations.Count > 0); List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id)); Assert.AreEqual(1, foundRelations.Count); } } break; } } MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source); foreach (Relation relation in memorySource.GetRelations()) { if (relation.Members != null) { foreach (var member in relation.Members) { OsmGeoType type = OsmGeoType.Node; switch (member.MemberType.Value) { case OsmGeoType.Node: type = OsmGeoType.Node; break; case OsmGeoType.Way: type = OsmGeoType.Way; break; case OsmGeoType.Relation: type = OsmGeoType.Relation; break; } IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value); Assert.IsNotNull(relations); Assert.IsTrue(relations.Count > 0); List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id)); Assert.AreEqual(1, foundRelations.Count); } } break; } }