/// <summary> /// Tests a simple relation read/write operation. /// </summary> /// <param name="cache"></param> public void DoOsmDataCacheTestRelation(OsmDataCache cache) { Relation relation = Relation.Create(1, new TagsCollection( Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node)); // test invalid stuff. Assert.Throws <ArgumentNullException>(() => cache.AddRelation(null)); Assert.Throws <Exception>(() => cache.AddRelation(new Relation())); Assert.IsNull(cache.GetRelation(relation.Id.Value)); cache.AddRelation(relation); Assert.IsTrue(cache.ContainsRelation(relation.Id.Value)); Relation readRelation = cache.GetRelation(relation.Id.Value); Assert.IsNotNull(readRelation); Assert.AreEqual(1, readRelation.Id.Value); Assert.IsNotNull(relation.Tags); Assert.AreEqual(1, relation.Tags.Count); Assert.AreEqual("yes", relation.Tags["relation"]); Assert.IsTrue(cache.TryGetRelation(relation.Id.Value, out readRelation)); Assert.IsNotNull(readRelation); Assert.AreEqual(1, readRelation.Id.Value); Assert.IsNotNull(relation.Tags); Assert.AreEqual(1, relation.Tags.Count); Assert.AreEqual("yes", relation.Tags["relation"]); Assert.IsTrue(cache.RemoveRelation(relation.Id.Value)); Assert.IsFalse(cache.ContainsRelation(relation.Id.Value)); Assert.IsFalse(cache.RemoveRelation(relation.Id.Value)); }
public void TestRelationMultipolygonAreaOneOuterTwoPartialInners() { MemoryDataSource source = new MemoryDataSource( Node.Create(1, 0, 0), Node.Create(2, 0, 1), Node.Create(3, 1, 1), Node.Create(4, 1, 0), Node.Create(5, 0.25, 0.25), Node.Create(6, 0.25, 0.40), Node.Create(7, 0.40, 0.40), Node.Create(8, 0.40, 0.25), Way.Create(1, 1, 2, 3, 4, 1), Way.Create(2, 5, 6, 7), Way.Create(3, 7, 8, 5), Relation.Create(1, new TagsCollection( Tag.Create("type", "multipolygon")), RelationMember.Create(1, "outer", OsmGeoType.Way), RelationMember.Create(2, "inner", OsmGeoType.Way), RelationMember.Create(3, "inner", OsmGeoType.Way))); GeometryInterpreter interpreter = new SimpleGeometryInterpreter(); GeometryCollection geometries = interpreter.Interpret(source.GetRelation(1), source); Assert.IsNotNull(geometries); Assert.AreEqual(1, geometries.Count); Geometry geometry = geometries[0]; Assert.IsInstanceOf <Polygon>(geometry); Polygon polygon = geometry as Polygon; Assert.IsNotNull(polygon.Holes); Assert.AreEqual(1, polygon.Holes.Count()); Assert.IsTrue(geometry.Attributes.ContainsKeyValue("type", "multipolygon")); }
public void TestSimpleToCompleteRelation() { // execute List <OsmGeo> completeList = this.Filter(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, 1, 2, 3), Relation.Create(1, RelationMember.Create(1, "way", OsmGeoType.Way)) }); // verify. Assert.IsNotNull(completeList); Assert.AreEqual(5, completeList.Count); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is Node) && (x as Node).Latitude == 0 && (x as Node).Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is Node) && (x as Node).Latitude == 1 && (x as Node).Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 3 && (x is Node) && (x as Node).Latitude == 0 && (x as Node).Longitude == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is Way) && (x as Way).Nodes.Count == 3 && (x as Way).Nodes[0] == 1 && (x as Way).Nodes[1] == 2 && (x as Way).Nodes[2] == 3))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is Relation) && (x as Relation).Members.Count == 1))); }
public void TestSimpleToCompleteNestedRelationsReverseOrder() { // execute List <CompleteOsmGeo> completeList = this.PullToCompleteList(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, 1, 2, 3), Relation.Create(2, RelationMember.Create(1, "way", OsmGeoType.Way), RelationMember.Create(1, "relation", OsmGeoType.Relation)), Relation.Create(1, RelationMember.Create(1, "way", OsmGeoType.Way)) }); // verify. Assert.IsNotNull(completeList); Assert.AreEqual(6, completeList.Count); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 0 && (x as CompleteNode).Coordinate.Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 1 && (x as CompleteNode).Coordinate.Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 3 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 0 && (x as CompleteNode).Coordinate.Longitude == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteWay) && (x as CompleteWay).Nodes.Count == 3 && (x as CompleteWay).Nodes[0].Id == 1 && (x as CompleteWay).Nodes[0].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[0].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[1].Id == 2 && (x as CompleteWay).Nodes[1].Coordinate.Latitude == 1 && (x as CompleteWay).Nodes[1].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[2].Id == 3 && (x as CompleteWay).Nodes[2].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[2].Coordinate.Longitude == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteRelation) && (x as CompleteRelation).Members.Count == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is CompleteRelation) && (x as CompleteRelation).Members.Count == 2))); }
public void TestRelationMultipolygonAreaOneOuterTwoInners() { var source = new MemoryDataSource( Node.Create(1, 0, 0), Node.Create(2, 0, 1), Node.Create(3, 1, 1), Node.Create(4, 1, 0), Node.Create(5, 0.25, 0.25), Node.Create(6, 0.25, 0.40), Node.Create(7, 0.40, 0.40), Node.Create(8, 0.40, 0.25), Node.Create(9, 0.60, 0.25), Node.Create(10, 0.60, 0.40), Node.Create(11, 0.75, 0.40), Node.Create(12, 0.75, 0.25), Way.Create(1, 1, 2, 3, 4, 1), Way.Create(2, 5, 6, 7, 8, 5), Way.Create(3, 9, 10, 11, 12, 9), Relation.Create(1, new TagsCollection( Tag.Create("type", "multipolygon")), RelationMember.Create(1, "outer", OsmGeoType.Way), RelationMember.Create(2, "inner", OsmGeoType.Way), RelationMember.Create(3, "inner", OsmGeoType.Way))); var interpreter = new SimpleFeatureInterpreter(); var features = interpreter.Interpret(source.GetRelation(1), source); Assert.IsNotNull(features); Assert.AreEqual(1, features.Count); var feature = features[0]; Assert.IsInstanceOf <Polygon>(feature.Geometry); Polygon polygon = feature.Geometry as Polygon; Assert.IsNotNull(polygon.Holes); Assert.AreEqual(2, polygon.Holes.Count()); Assert.IsTrue(feature.Attributes.ContainsKeyValue("type", "multipolygon")); }
public void TestRelationMultipolygonAreaOneOuter() { // tests a multipolygon containing one 'outer' member. MemoryDataSource source = new MemoryDataSource( Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, 1, 2, 3, 1), Relation.Create(1, new TagsCollection( Tag.Create("type", "multipolygon")), RelationMember.Create(1, "outer", OsmGeoType.Way))); GeometryInterpreter interpreter = new SimpleGeometryInterpreter(); GeometryCollection geometries = interpreter.Interpret(source.GetRelation(1), source); Assert.IsNotNull(geometries); Assert.AreEqual(1, geometries.Count); Geometry geometry = geometries[0]; Assert.IsInstanceOf <LineairRing>(geometry); Assert.IsTrue(geometry.Attributes.ContainsKeyValue("type", "multipolygon")); }
/// <summary> /// Tests the clear functionality on the datacache. /// </summary> /// <param name="cache"></param> public void DoOsmDataCacheTestClear(OsmDataCache cache) { Node node = Node.Create(1, new TagsCollection( Tag.Create("node", "yes")), 1, 2); Way way = Way.Create(1, new TagsCollection( Tag.Create("way", "yes")), 1, 2); Relation relation = Relation.Create(1, new TagsCollection( Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node)); cache.AddNode(node); cache.AddWay(way); cache.AddRelation(relation); Assert.IsTrue(cache.ContainsNode(node.Id.Value)); Assert.IsTrue(cache.ContainsWay(way.Id.Value)); Assert.IsTrue(cache.ContainsRelation(relation.Id.Value)); cache.Clear(); Assert.IsFalse(cache.ContainsNode(node.Id.Value)); Assert.IsFalse(cache.ContainsWay(way.Id.Value)); Assert.IsFalse(cache.ContainsRelation(relation.Id.Value)); }
public void TestStyleOsmStreamRelationAreas() { List <OsmGeo> result = this.FilterUsingStyleInterpreter(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, 1, 2, 3), Relation.Create(1, new TagsCollection( Tag.Create("type", "multipolygon")), RelationMember.Create(1, "way", OsmGeoType.Way)) }.ToOsmStreamSource(), "area { " + " color: black; " + "} "); Assert.IsNotNull(result); Assert.AreEqual(5, result.Count); Assert.IsTrue(result.Any(x => x is Node && x.Id == 1 && (x as Node).Latitude == 0 && (x as Node).Longitude == 0)); Assert.IsTrue(result.Any(x => x is Node && x.Id == 2 && (x as Node).Latitude == 1 && (x as Node).Longitude == 0)); Assert.IsTrue(result.Any(x => x is Node && x.Id == 3 && (x as Node).Latitude == 0 && (x as Node).Longitude == 1)); Assert.IsTrue(result.Any(x => x is Way && x.Id == 1 && (x as Way).Nodes != null && (x as Way).Nodes.Count == 3 && (x as Way).Nodes[0] == 1 && (x as Way).Nodes[1] == 2 && (x as Way).Nodes[2] == 3)); Assert.IsTrue(result.Any(x => x is Relation && x.Id == 1 && (x as Relation).Members != null && (x as Relation).Members.Count == 1 && (x as Relation).Members[0].MemberId == 1)); result = this.FilterUsingStyleInterpreter(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Node.Create(4, 1, 1), Way.Create(1, 1, 2, 3), Way.Create(2, 1, 2, 4), Relation.Create(1, RelationMember.Create(1, "way", OsmGeoType.Way)), Relation.Create(2, new TagsCollection( Tag.Create("type", "boundary")), RelationMember.Create(2, "way", OsmGeoType.Way)) }.ToOsmStreamSource(), "area { " + " color: black; " + "} "); Assert.IsNotNull(result); Assert.AreEqual(5, result.Count); Assert.IsTrue(result.Any(x => x is Node && x.Id == 1 && (x as Node).Latitude == 0 && (x as Node).Longitude == 0)); Assert.IsTrue(result.Any(x => x is Node && x.Id == 2 && (x as Node).Latitude == 1 && (x as Node).Longitude == 0)); Assert.IsTrue(result.Any(x => x is Node && x.Id == 4 && (x as Node).Latitude == 1 && (x as Node).Longitude == 1)); Assert.IsTrue(result.Any(x => x is Way && x.Id == 2 && (x as Way).Nodes != null && (x as Way).Nodes.Count == 3 && (x as Way).Nodes[0] == 1 && (x as Way).Nodes[1] == 2 && (x as Way).Nodes[2] == 4)); Assert.IsTrue(result.Any(x => x is Relation && x.Id == 2 && (x as Relation).Members != null && (x as Relation).Members.Count == 1 && (x as Relation).Members[0].MemberId == 2)); }
public void TestSimpleToCompleteMultipleUsages() { // execute List <CompleteOsmGeo> completeList = this.PullToCompleteList(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Node.Create(4, 2, 0), Node.Create(5, 0, 2), Way.Create(1, 1, 2, 3), Way.Create(2, 1, 4, 5), Way.Create(3, 3, 2, 5), Way.Create(5, 10, 11, 12), Relation.Create(1, RelationMember.Create(1, "way", OsmGeoType.Way)), Relation.Create(2, RelationMember.Create(1, "way", OsmGeoType.Way), RelationMember.Create(1, "relation", OsmGeoType.Relation)), Relation.Create(3, RelationMember.Create(1, "node", OsmGeoType.Node), RelationMember.Create(2, "node", OsmGeoType.Node), RelationMember.Create(3, "node", OsmGeoType.Node)), Relation.Create(4, RelationMember.Create(10, "node", OsmGeoType.Node), RelationMember.Create(11, "node", OsmGeoType.Node), RelationMember.Create(12, "node", OsmGeoType.Node)) }); // verify. Assert.IsNotNull(completeList); Assert.AreEqual(11, completeList.Count); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 0 && (x as CompleteNode).Coordinate.Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 1 && (x as CompleteNode).Coordinate.Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 3 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 0 && (x as CompleteNode).Coordinate.Longitude == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 4 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 2 && (x as CompleteNode).Coordinate.Longitude == 0))); Assert.IsTrue(completeList.Any(x => (x.Id == 5 && (x is CompleteNode) && (x as CompleteNode).Coordinate.Latitude == 0 && (x as CompleteNode).Coordinate.Longitude == 2))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteWay) && (x as CompleteWay).Nodes.Count == 3 && (x as CompleteWay).Nodes[0].Id == 1 && (x as CompleteWay).Nodes[0].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[0].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[1].Id == 2 && (x as CompleteWay).Nodes[1].Coordinate.Latitude == 1 && (x as CompleteWay).Nodes[1].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[2].Id == 3 && (x as CompleteWay).Nodes[2].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[2].Coordinate.Longitude == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is CompleteWay) && (x as CompleteWay).Nodes.Count == 3 && (x as CompleteWay).Nodes[0].Id == 1 && (x as CompleteWay).Nodes[0].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[0].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[1].Id == 4 && (x as CompleteWay).Nodes[1].Coordinate.Latitude == 2 && (x as CompleteWay).Nodes[1].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[2].Id == 5 && (x as CompleteWay).Nodes[2].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[2].Coordinate.Longitude == 2))); Assert.IsTrue(completeList.Any(x => (x.Id == 3 && (x is CompleteWay) && (x as CompleteWay).Nodes.Count == 3 && (x as CompleteWay).Nodes[0].Id == 3 && (x as CompleteWay).Nodes[0].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[0].Coordinate.Longitude == 1 && (x as CompleteWay).Nodes[1].Id == 2 && (x as CompleteWay).Nodes[1].Coordinate.Latitude == 1 && (x as CompleteWay).Nodes[1].Coordinate.Longitude == 0 && (x as CompleteWay).Nodes[2].Id == 5 && (x as CompleteWay).Nodes[2].Coordinate.Latitude == 0 && (x as CompleteWay).Nodes[2].Coordinate.Longitude == 2))); Assert.IsFalse(completeList.Any(x => (x.Id == 5 && (x is CompleteWay)))); Assert.IsTrue(completeList.Any(x => (x.Id == 1 && (x is CompleteRelation) && (x as CompleteRelation).Members.Count == 1))); Assert.IsTrue(completeList.Any(x => (x.Id == 2 && (x is CompleteRelation) && (x as CompleteRelation).Members.Count == 2))); Assert.IsTrue(completeList.Any(x => (x.Id == 3 && (x is CompleteRelation) && (x as CompleteRelation).Members.Count == 3))); }
public void TestFilterSort() { // execute var filter = new OsmStreamFilterSort(); filter.RegisterSource(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, 1, 2, 3) }); var list = new List <OsmGeo>( filter); // verify. Assert.IsNotNull(list); Assert.AreEqual(4, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(2, list[1].Id); Assert.AreEqual(3, list[2].Id); Assert.AreEqual(1, list[3].Id); // reset. filter.Reset(); list = new List <OsmGeo>( filter); // verify. Assert.IsNotNull(list); Assert.AreEqual(4, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(2, list[1].Id); Assert.AreEqual(3, list[2].Id); Assert.AreEqual(1, list[3].Id); // execute filter = new OsmStreamFilterSort(); filter.RegisterSource(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Way.Create(1, 1, 2, 3), Node.Create(3, 0, 1) }); list = new List <OsmGeo>( filter); // verify. Assert.IsNotNull(list); Assert.AreEqual(4, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(2, list[1].Id); Assert.AreEqual(3, list[2].Id); Assert.AreEqual(1, list[3].Id); // execute filter = new OsmStreamFilterSort(); filter.RegisterSource(new OsmGeo[] { Node.Create(1, 0, 0), Node.Create(2, 1, 0), Way.Create(1, 1, 2, 3), Relation.Create(1, new TagsCollection( Tag.Create("type", "multipolygon")), RelationMember.Create(1, "outer", OsmGeoType.Way)), Node.Create(3, 0, 1) }); list = new List <OsmGeo>( filter); // verify. Assert.IsNotNull(list); Assert.AreEqual(5, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(2, list[1].Id); Assert.AreEqual(3, list[2].Id); Assert.AreEqual(1, list[3].Id); Assert.AreEqual(1, list[4].Id); // reset. filter.Reset(); list = new List <OsmGeo>( filter); // verify. Assert.IsNotNull(list); Assert.AreEqual(5, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(2, list[1].Id); Assert.AreEqual(3, list[2].Id); Assert.AreEqual(1, list[3].Id); Assert.AreEqual(1, list[4].Id); }