Ejemplo n.º 1
0
        public void TestCalculateBounds()
        {
            Ring r = new Ring();
            r.Points.Add(new Point(0.5,0));
            r.Points.Add(new Point(0,0.5));
            r.Points.Add(new Point(0.5,1));
            r.Points.Add(new Point(1,0.5));
            r.Close();

            Assert.AreEqual(new Rectangle(0,0,1,1), r.CalculateBounds());
        }
Ejemplo n.º 2
0
        public void TestCalculateArea()
        {
            Ring r = new Ring();
            r.Points.Add(new Point(0,0));
            r.Points.Add(new Point(0,1));
            r.Points.Add(new Point(1,1));
            r.Points.Add(new Point(1,0));
            r.Close();

            Assert.AreEqual(1, r.CalculateArea());
        }
Ejemplo n.º 3
0
        public void TestClose()
        {
            Ring r = new Ring();
            r.Points.Add(new Point(0,0));
            r.Points.Add(new Point(0,1));
            r.Points.Add(new Point(1,1));
            r.Points.Add(new Point(1,0));

            Assert.IsFalse(r.IsClosed);

            r.Close();

            Assert.IsTrue(r.IsClosed);
        }
Ejemplo n.º 4
0
        public void TestCreateFromPolygon()
        {
            Polygon p = new Polygon();
            Ring r1 = new Ring();
            r1.Points.Add(new Point(0,0));
            r1.Points.Add(new Point(0, 5));
            r1.Points.Add(new Point(5,6));
            r1.Points.Add(new Point(5,0));
            r1.Close();
            p.Rings.Add(r1);

            Assert.AreEqual("POLYGON((0 0,0 5,5 6,5 0,0 0))", WellKnownText.CreateFromPolygon(p));

            // add hole
            Ring r2 = new Ring();
            r2.Points.Add(new Point(1.1,1.1));
            r2.Points.Add(new Point(1.6,1.1));
            r2.Points.Add(new Point(1.4,1.4));
            r2.Points.Add(new Point(1.1,1.6));
            r2.Close();
            p.Rings.Add(r2);

            Assert.AreEqual("POLYGON((0 0,0 5,5 6,5 0,0 0),(1.1 1.1,1.6 1.1,1.4 1.4,1.1 1.6,1.1 1.1))",
                            WellKnownText.CreateFromPolygon(p));

            // add another poly
            Ring r3 = new Ring();
            r3.Points.Add(new Point(10,10));
            r3.Points.Add(new Point(10,15));
            r3.Points.Add(new Point(15,15));
            r3.Points.Add(new Point(15,10));
            r3.Close();
            p.Rings.Add(r3);

            Assert.AreEqual("MULTIPOLYGON(((0 0,0 5,5 6,5 0,0 0),(1.1 1.1,1.6 1.1,1.4 1.4,1.1 1.6,1.1 1.1)),((10 10,10 15,15 15,15 10,10 10)))",
                            WellKnownText.CreateFromPolygon(p));
        }
Ejemplo n.º 5
0
        public void TestNotIsClockwise()
        {
            Ring r = new Ring();
            r.Points.Add(new Point(0,0));
            r.Points.Add(new Point(1,0));
            r.Points.Add(new Point(1,1));
            r.Points.Add(new Point(0,1));
            r.Close();

            Assert.IsFalse(r.IsClockwise);
        }
Ejemplo n.º 6
0
        public Ring Simplify(double tolerance)
        {
            Ring r = new Ring();
            r.points = new List<Point>(this.points);

            if (r.IsClosed)
            {
                r.points.RemoveAt(r.Points.Count-1);
            }

            r.points = Simplificator.Simplify(r.points, tolerance, true);

            r.Close();

            return r;
        }
Ejemplo n.º 7
0
        public void TestSimpleFeatureSourceSerialization()
        {
            Map m = new Map();
            Layer l = new Layer();

            SimpleFeatureSource sfs = new SimpleFeatureSource(FeatureType.Polygon);
            Polygon p = new Polygon();

            Ring r = new Ring();
            r.Points.Add(new Point(0,0));
            r.Points.Add(new Point(0,5));
            r.Points.Add(new Point(5,5));
            r.Points.Add(new Point(5,0));
            r.Close();
            p.Rings.Add(r);

            Ring hole = new Ring();
            hole.Points.Add(new Point(1,1));
            hole.Points.Add(new Point(2,1));
            hole.Points.Add(new Point(2,2));
            hole.Points.Add(new Point(2,1));
            hole.Close();
            p.Rings.Add(hole);

            sfs.Features.Add(p);

            l.Data = sfs;
            m.Layers.Add(l);

            MapSerializer ms = new MapSerializer();
            string s = MapSerializer.Serialize(m);

            Map m2 = ms.Deserialize(new MemoryStream(UTF8Encoding.UTF8.GetBytes((s))));

            Assert.AreEqual(1, m2.Layers.Count);
            Assert.AreEqual(1, (m2.Layers[0].Data as SimpleFeatureSource).Features.Count);
            Assert.AreEqual(2, ((m2.Layers[0].Data as SimpleFeatureSource).Features[0] as Polygon).Rings.Count);
        }