public void TestRelationMultipolygonAreaOneOuterOneInner()
        {
            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, 8, 5),
                Relation.Create(1,
                    new SimpleTagsCollection(
                        Tag.Create("type", "multipolygon")),
                    RelationMember.Create(1, "outer", OsmGeoType.Way),
                    RelationMember.Create(2, "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 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 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 SimpleTagsCollection(
                        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"));
        }
        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 Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // 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 TestMapCSSCanvasRendering()
        {
            // create the data source.
            MemoryDataSource source = new MemoryDataSource();

            // define the MapCSS file.
            string css = "canvas { " +
                "fill-color: green; " +
                "} ";

            // do the rendering.
            Bitmap rendering = this.Render(source, css);

            // check result.
            for (int x = 0; x < 100; x++)
            {
                for (int y = 0; y < 100; y++)
                {
                    Assert.AreEqual(SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.Green).Value,
                        rendering.GetPixel(x, y).ToArgb());
                }
            }
        }
 public void TestAddNodeNoId()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddNode(new Node());
 }
        public void TestRemoveWay()
        {
            Way testWay = new Way();
            testWay.Id = -1;
            var source = new MemoryDataSource();
            source.AddWay(testWay);

            // test if the way is actually there.
            Assert.AreEqual(testWay, source.GetWay(-1));

            // remove the way.
            source.RemoveWay(-1);

            // test if the way is actually gone.
            Assert.IsNull(source.GetWay(-1));
        }
        public void TestAddRelation()
        {
            Relation testRelation = new Relation();
            testRelation.Id = -1;
            var source = new MemoryDataSource();
            source.AddRelation(testRelation);

            // test if the relation is actually there.
            Assert.AreEqual(testRelation, source.GetRelation(-1));

            // test if the relation was not remove after getting it.
            Assert.AreEqual(testRelation, source.GetRelations(new List<long>() { -1 })[0]);

            // test if the relation is in the list of relations.
            Assert.AreEqual(testRelation, new List<Relation>(source.GetRelations())[0]);

            // test if the relation will be retrieved using a list of ids.
            List<long> ids = new List<long>();
            ids.Add(-1);
            IList<Relation> relations = source.GetRelations(ids);
            Assert.IsNotNull(relations);
            Assert.AreEqual(1, relations.Count);
            Assert.AreEqual(testRelation, relations[0]);
        }
        public void TestMapCSSSimpleEval()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                Tag.Create("width", "10")), 1, 2, 3, 1));

            // test closed way.
            string css = "way { " +
                "   width:  eval(\"tag('width')\"); " +
                "   color: green; " +
                "} ";

            // create the projection and scene objects.
            var mercator = new WebMercator();
            Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                                                                  new MapCSSDictionaryImageSource());
            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);
            Assert.IsInstanceOf<Line2D>(primitive);
            Line2D line = (primitive as Line2D);
            Assert.AreEqual(10, line.Width);
        }
        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]);
        }
        public void TestMapCSSWayRendering1()
        {
            // create the data source.
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 1, 1),
                Node.Create(2, -1, -1),
                Way.Create(1, new TagsCollection(Tag.Create("highway", "residential")), 1, 2));

            // create CSS.
            string css = "canvas { " +
                "fill-color: white; " +
                "}  "+
                "way { " +
                "   width: 2; " +
                "   color: black; " +
                "} ";

            // do the rendering.
            Bitmap rendering = this.Render(source, css);

            // check result.
            Assert.AreEqual(SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.White).Value,
                rendering.GetPixel(0, 99).ToArgb());
            Assert.AreEqual(SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.White).Value,
                rendering.GetPixel(99, 0).ToArgb());
            for (int x = 0; x < 100; x++)
            {
                Assert.AreEqual(SimpleColor.FromKnownColor(OsmSharp.UI.KnownColor.Black).Value,
                    rendering.GetPixel(x, x).ToArgb());
            }
        }
        /// <summary>
        /// Compares what is in the complete list against the objects in the reference source.
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        private void Compare(MemoryDataSource expected, List<CompleteOsmGeo> actual)
        {
            List<CompleteOsmGeo> exectedList = new List<CompleteOsmGeo>();
            foreach (Node node in expected.GetNodes())
            {
                CompleteNode completeNode = CompleteNode.CreateFrom(node);
                if (completeNode != null)
                {
                    exectedList.Add(completeNode);
                }
            }
            foreach (Way way in expected.GetWays())
            {
                CompleteWay completeWay = CompleteWay.CreateFrom(way, expected);
                if (completeWay != null)
                {
                    exectedList.Add(completeWay);
                }
            }
            foreach (Relation relation in expected.GetRelations())
            {
                CompleteRelation completeRelation = CompleteRelation.CreateFrom(relation, expected);
                if (completeRelation != null)
                {
                    exectedList.Add(completeRelation);
                }
            }

            ComparisonHelpers.CompareComplete(exectedList, actual);
        }
 public void TestAddWayNull()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddWay(null);
 }
 public void TestAddWayNoId()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddWay(new Way());
 }
        public void TestAddWayAndNodes()
        {
            Way testWay = new Way();
            testWay.Id = 1;
            testWay.Nodes = new List<long>();
            testWay.Nodes.Add(1);
            testWay.Nodes.Add(2);

            Node node1 = new Node();
            node1.Id = 1;
            node1.Longitude = 0;
            node1.Latitude = 0;
            Node node2 = new Node();
            node2.Id = 2;
            node2.Longitude = 0;
            node2.Latitude = 0;

            var source = new MemoryDataSource();
            source.AddWay(testWay);

            IList<Way> resultWays = source.GetWaysFor(node1);
            Assert.IsNotNull(resultWays);
            Assert.AreEqual(1, resultWays.Count);
            Assert.AreEqual(testWay, resultWays[0]);

            // test if the way is actually there.
            Assert.AreEqual(testWay, source.GetWay(1));

            // test if the way was not removed after getting it.
            Assert.AreEqual(testWay, source.GetWay(1));
        }
        public void TestAddWay()
        {
            Way testWay = new Way();
            testWay.Id = -1;
            var source = new MemoryDataSource();
            source.AddWay(testWay);

            // test if the way is actually there.
            Assert.AreEqual(testWay, source.GetWay(-1));

            // test if the way was not remove after getting it.
            Assert.AreEqual(testWay, source.GetWays(new List<long>() { -1 })[0]);

            // test if the way is in the list of ways.
            Assert.AreEqual(testWay, new List<Way>(source.GetWays())[0]);

            // test if the way will be retrieved using a list of ids.
            var ids = new List<long>();
            ids.Add(-1);
            IList<Way> ways = source.GetWays(ids);
            Assert.IsNotNull(ways);
            Assert.AreEqual(1, ways.Count);
            Assert.AreEqual(testWay, ways[0]);
        }
 public void TestAddRelationNull()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddRelation(null);
 }
 public void TestAddRelationNoId()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddRelation(new Relation());
 }
        public void TestAddRelationAndMembers()
        {
            Way testWay = new Way();
            testWay.Id = 1;
            testWay.Nodes = new List<long>();
            testWay.Nodes.Add(1);
            testWay.Nodes.Add(2);

            Node node1 = new Node();
            node1.Id = 1;
            node1.Longitude = 0;
            node1.Latitude = 0;
            Node node2 = new Node();
            node2.Id = 2;
            node2.Longitude = 0;
            node2.Latitude = 0;

            Relation relationAsMember = new Relation();
            relationAsMember.Id = 2;

            Relation relation = new Relation();
            relation.Id = 1;
            relation.Members = new List<RelationMember>();
            relation.Members.Add(new RelationMember()
            {
                MemberId = 1,
                MemberRole = "node",
                MemberType = OsmGeoType.Node
            });
            relation.Members.Add(new RelationMember()
            {
                MemberId = 2,
                MemberRole = "node",
                MemberType = OsmGeoType.Node
            });
            relation.Members.Add(new RelationMember()
            {
                MemberId = 1,
                MemberRole = "way",
                MemberType = OsmGeoType.Way
            });
            relation.Members.Add(new RelationMember()
            {
                MemberId = 2,
                MemberRole = "relation",
                MemberType = OsmGeoType.Relation
            });

            var source = new MemoryDataSource();
            source.AddRelation(relation);

            // test positive cases.
            IList<Relation> resultRelations = source.GetRelationsFor(node1);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(1, resultRelations.Count);
            Assert.AreEqual(relation, resultRelations[0]);
            resultRelations = source.GetRelationsFor(node2);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(1, resultRelations.Count);
            Assert.AreEqual(relation, resultRelations[0]);
            resultRelations = source.GetRelationsFor(testWay);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(1, resultRelations.Count);
            Assert.AreEqual(relation, resultRelations[0]);
            resultRelations = source.GetRelationsFor(relationAsMember);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(1, resultRelations.Count);
            Assert.AreEqual(relation, resultRelations[0]);

            // test negative cases.
            resultRelations = source.GetRelationsFor(OsmGeoType.Node, 10000);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(0, resultRelations.Count);
            resultRelations = source.GetRelationsFor(OsmGeoType.Way, 10000);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(0, resultRelations.Count);
            resultRelations = source.GetRelationsFor(OsmGeoType.Relation, 10000);
            Assert.IsNotNull(resultRelations);
            Assert.AreEqual(0, resultRelations.Count);
        }
        public void TestAddNodeNoLocation()
        {
            Node node = new Node();
            node.Id = 1;

            var dataSource = new MemoryDataSource();
            dataSource.AddNode(node);
        }
        /// <summary>
        /// Creates a new memory data source from all the data in the given osm-stream.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <returns></returns>
        public static MemoryDataSource CreateFrom(OsmStreamSource sourceStream)
        {
            // reset if possible.
            if (sourceStream.CanReset) { sourceStream.Reset(); }

            // enumerate all objects and add them to a new datasource.
            MemoryDataSource dataSource = new MemoryDataSource();
            foreach (var osmGeo in sourceStream)
            {
                if (osmGeo != null)
                {
                    switch(osmGeo.Type)
                    {
                        case OsmGeoType.Node:
                            dataSource.AddNode(osmGeo as Node);
                            break;
                        case OsmGeoType.Way:
                            dataSource.AddWay(osmGeo as Way);
                            break;
                        case OsmGeoType.Relation:
                            dataSource.AddRelation(osmGeo as Relation);
                            break;
                    }
                }
            }
            return dataSource;
        }
        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 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 SimpleTagsCollection();
            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 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 TestMapCSSClosedWay()
        {
            // tests map css interpretation of a closed way marked as an area.
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new SimpleTagsCollection(
                        Tag.Create("area", "yes")), 1, 2, 3, 1));

            // test closed way.
            string css = "way[area] { " +
                         "   fill-color: black; " +
                         "} ";

            // create the projection and scene objects.
            var mercator = new WebMercator();
            Scene2D scene = new Scene2DSimple();

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                new MapCSSDictionaryImageSource());
            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            List<IScene2DPrimitive> primitives = scene.Get(0);
            Assert.IsNotNull(primitives);
            Assert.AreEqual(1, primitives.Count);
            IScene2DPrimitive primitive = primitives[0];
            Assert.IsInstanceOf<Polygon2D>(primitive);
        }
        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 TestMapCSSArea()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, new TagsCollection(
                        Tag.Create("area", "yes")), 1, 2, 3, 1));

            // test closed way.
            string css = "area { " +
                    "   fill-color: black; " +
                    "} ";

            // create the projection and scene objects.
            var mercator = new WebMercator();
            Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the projection and scene objects.
            scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);

            // create the interpreter.
            MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
                new MapCSSDictionaryImageSource());
            interpreter.Translate(scene, mercator, source, source.GetWay(1));

            // test the scene contents.
            Assert.AreEqual(1, scene.Count);
            Primitive2D primitive = scene.Get(0);
            Assert.IsInstanceOf<Polygon2D>(primitive);
        }
        public void TestRemoveRelation()
        {
            Relation testRelation = new Relation();
            testRelation.Id = -1;
            var source = new MemoryDataSource();
            source.AddRelation(testRelation);

            // test if the relation is actually there.
            Assert.AreEqual(testRelation, source.GetRelation(-1));

            // remove the relation.
            source.RemoveRelation(-1);

            // test if the relation is actually gone.
            Assert.IsNull(source.GetRelation(-1));
        }
        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 Scene2DSimple();

            // 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 TestAddNodeNull()
 {
     var dataSource = new MemoryDataSource();
     dataSource.AddNode(null);
 }