public void TestBoundingBox() { var dataSource = new MemoryDataSource(); Node node = new Node(); node.Id = 1; node.Longitude = -2; node.Latitude = -1; dataSource.AddNode(node); node = new Node(); node.Id = 2; node.Longitude = 2; node.Latitude = 1; dataSource.AddNode(node); Assert.IsTrue(dataSource.HasBoundinBox); GeoCoordinateBox box = dataSource.BoundingBox; Assert.AreEqual(1, box.MaxLat); Assert.AreEqual(2, box.MaxLon); Assert.AreEqual(-1, box.MinLat); Assert.AreEqual(-2, box.MinLon); }
public void TestCanvasSettingsCSS() { // create CSS. string css = "canvas { " + "fill-color: green; " + "} "; // create 'test' objects. Node node1 = new Node(); node1.Id = 1; node1.Latitude = 1; node1.Longitude = 1; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 2; node2.Longitude = 2; Way way = new Way(); way.Id = 1; way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); // create the datasource. MemoryDataSource dataSource = new MemoryDataSource(); dataSource.AddNode(node1); dataSource.AddNode(node2); dataSource.AddWay(way); // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(css, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, dataSource, node1); interpreter.Translate(scene, mercator, dataSource, node2); interpreter.Translate(scene, mercator, dataSource, way); // test the scene contents. Assert.AreEqual(0, scene.Count); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Green).Value, scene.BackColor); }
public void TestAddNode() { Node testNode = new Node(); testNode.Id = -1; testNode.Latitude = 0; testNode.Longitude = 0; var source = new MemoryDataSource(); source.AddNode(testNode); // test if the node is actually there. Assert.AreEqual(testNode, source.GetNode(-1)); // test if the node was not remove after getting it. Assert.AreEqual(testNode, source.GetNodes(new List <long>() { -1 })[0]); // test if the node is in the list of nodes. Assert.AreEqual(testNode, new List <Node>(source.GetNodes())[0]); // test if the node will be retrieved using a list of ids. var ids = new List <long>(); ids.Add(-1); IList <Node> nodes = source.GetNodes(ids); Assert.IsNotNull(nodes); Assert.AreEqual(1, nodes.Count); Assert.AreEqual(testNode, nodes[0]); }
public void TestWayNaturalIsWaterArea() { Node node1 = new Node(); node1.Id = 1; node1.Latitude = 0; node1.Longitude = 0; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 1; node2.Longitude = 0; Node node3 = new Node(); node3.Id = 3; node3.Latitude = 0; node3.Longitude = 1; Way way = new Way(); way.Id = 1; way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); way.Nodes.Add(3); way.Nodes.Add(1); way.Tags = new TagsCollection(); way.Tags.Add("natural", "water"); MemoryDataSource source = new MemoryDataSource(); source.AddNode(node1); source.AddNode(node2); source.AddNode(node3); source.AddWay(way); // the use of natural=water implies an area-type. GeometryInterpreter interpreter = new SimpleGeometryInterpreter(); GeometryCollection geometries = interpreter.Interpret(way, source); Assert.IsNotNull(geometries); Assert.AreEqual(1, geometries.Count); Geometry geometry = geometries[0]; Assert.IsInstanceOf <LineairRing>(geometry); Assert.IsTrue(geometry.Attributes.ContainsKeyValue("natural", "water")); }
public void TestWayAreaIsYesArea() { var node1 = new Node(); node1.Id = 1; node1.Latitude = 0; node1.Longitude = 0; var node2 = new Node(); node2.Id = 2; node2.Latitude = 1; node2.Longitude = 0; var node3 = new Node(); node3.Id = 3; node3.Latitude = 0; node3.Longitude = 1; var way = new Way(); way.Id = 1; way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); way.Nodes.Add(3); way.Nodes.Add(1); way.Tags = new TagsCollection(); way.Tags.Add("area", "yes"); var source = new MemoryDataSource(); source.AddNode(node1); source.AddNode(node2); source.AddNode(node3); source.AddWay(way); // the use of natural=water implies an area-type. var interpreter = new SimpleFeatureInterpreter(); var features = interpreter.Interpret(way, source); Assert.IsNotNull(features); Assert.AreEqual(1, features.Count); var feature = features[0]; Assert.IsInstanceOf <LineairRing>(feature.Geometry); Assert.IsTrue(feature.Attributes.ContainsKeyValue("area", "yes")); }
public void TestEmptyCSS() { // create 'test' objects. Node node1 = new Node(); node1.Id = 1; node1.Latitude = 1; node1.Longitude = 1; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 2; node2.Longitude = 2; Way way = new Way(); way.Id = 1; way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); // create the datasource. MemoryDataSource dataSource = new MemoryDataSource(); dataSource.AddNode(node1); dataSource.AddNode(node2); dataSource.AddWay(way); // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2DSimple(); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(string.Empty, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, dataSource, node1); interpreter.Translate(scene, mercator, dataSource, node2); interpreter.Translate(scene, mercator, dataSource, way); // test the scene contents. Assert.AreEqual(0, scene.Count); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, scene.BackColor); }
public void TestAddNodeNoLocation() { Node node = new Node(); node.Id = 1; var dataSource = new MemoryDataSource(); dataSource.AddNode(node); }
public void TestAddNodeNoLocation() { var node = new Node(); node.Id = 1; var dataSource = new MemoryDataSource(); Assert.Catch <ArgumentException>(() => dataSource.AddNode(node)); }
public void TestRemoveNode() { Node testNode = new Node(); testNode.Id = -1; testNode.Latitude = 0; testNode.Longitude = 0; var source = new MemoryDataSource(); source.AddNode(testNode); // test if the node is actually there. Assert.AreEqual(testNode, source.GetNode(-1)); // remove the node. source.RemoveNode(-1); // test if the node is actually gone. Assert.IsNull(source.GetNode(-1)); }
public void TestAddNodeNoId() { var dataSource = new MemoryDataSource(); dataSource.AddNode(new Node()); }
public void TestGetBoundingBox() { var dataSource = new MemoryDataSource(); // test nodes. Node node = new Node(); node.Id = 1; node.Longitude = -2; node.Latitude = -1; dataSource.AddNode(node); node = new Node(); node.Id = 2; node.Longitude = 2; node.Latitude = 1; dataSource.AddNode(node); GeoCoordinateBox box = dataSource.BoundingBox; IList <OsmGeo> boxResults = dataSource.Get(box, null); Assert.IsNotNull(boxResults); Assert.AreEqual(1, boxResults.Count); boxResults = dataSource.Get(box.Resize(0.1), null); Assert.IsNotNull(boxResults); Assert.AreEqual(2, boxResults.Count); node = new Node(); node.Id = 3; node.Latitude = 10; node.Longitude = 10; dataSource.AddNode(node); node = new Node(); node.Id = 4; node.Latitude = -10; node.Longitude = -10; dataSource.AddNode(node); boxResults = dataSource.Get(box, null); Assert.IsNotNull(boxResults); Assert.AreEqual(1, boxResults.Count); boxResults = dataSource.Get(box.Resize(0.1), null); Assert.IsNotNull(boxResults); Assert.AreEqual(2, boxResults.Count); // test ways. Way positive = new Way(); positive.Id = 1; positive.Nodes = new List <long>(); positive.Nodes.Add(1); positive.Nodes.Add(2); dataSource.AddWay(positive); Way halfPositive = new Way(); halfPositive.Id = 2; halfPositive.Nodes = new List <long>(); halfPositive.Nodes.Add(1); halfPositive.Nodes.Add(3); dataSource.AddWay(halfPositive); Way negative = new Way(); negative.Id = 3; negative.Nodes = new List <long>(); negative.Nodes.Add(3); negative.Nodes.Add(4); dataSource.AddWay(negative); HashSet <OsmGeo> boxResultWithWays = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWays.Contains(positive)); Assert.IsTrue(boxResultWithWays.Contains(halfPositive)); Assert.IsFalse(boxResultWithWays.Contains(negative)); // test relations. Relation positiveRelation1 = new Relation(); positiveRelation1.Id = 1; positiveRelation1.Members = new List <RelationMember>(); positiveRelation1.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Node, MemberRole = "node" }); dataSource.AddRelation(positiveRelation1); Relation positiveRelation2 = new Relation(); positiveRelation2.Id = 2; positiveRelation2.Members = new List <RelationMember>(); positiveRelation2.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Way, MemberRole = "way" }); dataSource.AddRelation(positiveRelation2); Relation negativeRelation3 = new Relation(); negativeRelation3.Id = 3; negativeRelation3.Members = new List <RelationMember>(); negativeRelation3.Members.Add(new RelationMember() { MemberId = 3, MemberType = OsmGeoType.Way, MemberRole = "way" }); dataSource.AddRelation(positiveRelation2); HashSet <OsmGeo> boxResultWithWaysAndRelations = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(positiveRelation1)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(positiveRelation2)); Assert.IsFalse(boxResultWithWaysAndRelations.Contains(negativeRelation3)); // test recursive relations. Relation recusive1 = new Relation(); recusive1.Id = 10; recusive1.Members = new List <RelationMember>(); recusive1.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive1); Relation recusive2 = new Relation(); recusive2.Id = 11; recusive2.Members = new List <RelationMember>(); recusive2.Members.Add(new RelationMember() { MemberId = 10, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive2); Relation recusive3 = new Relation(); recusive3.Id = 12; recusive3.Members = new List <RelationMember>(); recusive3.Members.Add(new RelationMember() { MemberId = 11, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive3); boxResultWithWaysAndRelations = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive1)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive2)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive3)); }
public void TestAddNodeNull() { var dataSource = new MemoryDataSource(); dataSource.AddNode(null); }
public void TestAddNodeNoId() { var dataSource = new MemoryDataSource(); Assert.Catch <ArgumentException>(() => dataSource.AddNode(new Node())); }
public void TestAddNodeNull() { var dataSource = new MemoryDataSource(); Assert.Catch <ArgumentNullException>(() => dataSource.AddNode(null)); }
public void TestCanvasJOSMSettingsCSS() { // create CSS. string css = "canvas { " + "background-color: white; " + "default-points: true; " + // adds default points for every node (color: black, size: 2). "default-lines: true; " + // adds default lines for every way (color: red, width: 1). "} "; // create 'test' objects. Node node1 = new Node(); node1.Id = 1; node1.Latitude = 1; node1.Longitude = 1; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 2; node2.Longitude = 2; Way way = new Way(); way.Id = 1; way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); // create the datasource. MemoryDataSource dataSource = new MemoryDataSource(); dataSource.AddNode(node1); dataSource.AddNode(node2); dataSource.AddWay(way); // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(css, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, dataSource, node1); interpreter.Translate(scene, mercator, dataSource, node2); interpreter.Translate(scene, mercator, dataSource, way); // test the scene contents. Assert.AreEqual(3, scene.Count); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor); // test the scene point 1. Primitive2D primitive = scene.Get(0); Assert.IsNotNull(primitive); Assert.IsInstanceOf <Primitive2D>(primitive); Point2D pointObject = primitive as Point2D; Assert.AreEqual(2, pointObject.Size); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color); Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X); Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y); // test the scene point 2. primitive = scene.Get(1); Assert.IsNotNull(primitive); Assert.IsInstanceOf <Point2D>(primitive); pointObject = primitive as Point2D; Assert.AreEqual(2, pointObject.Size); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color); Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X); Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y); // test the scene line 2. primitive = scene.Get(2); Assert.IsNotNull(primitive); Assert.IsInstanceOf <Line2D>(primitive); Line2D line = primitive as Line2D; Assert.AreEqual(1, line.Width); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color); Assert.IsNotNull(line.X); Assert.IsNotNull(line.Y); Assert.AreEqual(2, line.X.Length); Assert.AreEqual(2, line.Y.Length); Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]); Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]); Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]); Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]); }