Example #1
0
        public void CanWritePolygonWithInnerRing()
        {
            var ring1 = new List <Pnt3D>
            {
                new Pnt3D(0, 0, 9),
                new Pnt3D(0, 100, 8),
                new Pnt3D(100, 100, 5),
                new Pnt3D(100, 20, 9)
            };

            RingGroup polygon = CreatePoly(ring1);

            polygon.AddInteriorRing(new Linestring(new[]
            {
                new Pnt3D(25, 50, 0),
                new Pnt3D(50, 50, 0),
                new Pnt3D(50, 75, 0),
                new Pnt3D(25, 75, 0),
                new Pnt3D(25, 50, 0)
            }
                                                   ));

            WkbGeomWriter writer = new WkbGeomWriter();

            byte[] bytes = writer.WritePolygon(polygon);

            WkbGeomReader reader       = new WkbGeomReader();
            RingGroup     deserialized = reader.ReadPolygon(new MemoryStream(bytes));

            Assert.IsTrue(deserialized.Equals(polygon));
        }
Example #2
0
        public void CanWriteAndReadMultiPolygonWithInnerRing()
        {
            var ring1 = new List <Pnt3D>
            {
                new Pnt3D(0, 0, 9),
                new Pnt3D(0, 100, 8),
                new Pnt3D(100, 100, 5),
                new Pnt3D(100, 20, 9)
            };

            var disjoint = new List <Pnt3D>();

            disjoint.Add(new Pnt3D(140, -10, 0));
            disjoint.Add(new Pnt3D(140, 30, 23));
            disjoint.Add(new Pnt3D(300, 30, 56));
            disjoint.Add(new Pnt3D(300, -10, 0));

            RingGroup poly1 = CreatePoly(ring1);

            poly1.AddInteriorRing(new Linestring(new[]
            {
                new Pnt3D(25, 50, 0),
                new Pnt3D(50, 50, 0),
                new Pnt3D(50, 75, 0),
                new Pnt3D(25, 75, 0),
                new Pnt3D(25, 50, 0)
            }
                                                 ));

            Linestring disjointRing = CreateRing(disjoint);

            var poly2 = new RingGroup(disjointRing);

            var multipolygon = new List <RingGroup>(new[] { poly1, poly2 });

            WkbGeomWriter writer = new WkbGeomWriter();

            byte[] bytes = writer.WriteMultipolygon(multipolygon);

            WkbGeomReader     reader       = new WkbGeomReader();
            IList <RingGroup> deserialized = reader.ReadMultiPolygon(new MemoryStream(bytes));

            Assert.IsTrue(deserialized[0].Equals(multipolygon[0]));
            Assert.IsTrue(deserialized[1].Equals(multipolygon[1]));
        }
Example #3
0
        public void CanReadClockwiseWindingPolygon()
        {
            // Some OGC 1.1 implementations do not have counter-clockwise polygon winding order:
            var ring1 = new List <Pnt3D>
            {
                new Pnt3D(0, 0, 9),
                new Pnt3D(0, 100, 8),
                new Pnt3D(100, 100, 5),
                new Pnt3D(100, 20, 9)
            };

            RingGroup polygon = CreatePoly(ring1);

            polygon.AddInteriorRing(new Linestring(new[]
            {
                new Pnt3D(25, 50, 0),
                new Pnt3D(50, 50, 0),
                new Pnt3D(50, 75, 0),
                new Pnt3D(25, 75, 0),
                new Pnt3D(25, 50, 0)
            }
                                                   ));

            RingGroup inverted = (RingGroup)polygon.Clone();

            inverted.ReverseOrientation();

            WkbGeomWriter writer = new WkbGeomWriter();

            byte[] bytes = writer.WritePolygon(inverted);

            const bool    assumeWkbPolygonsClockwise = true;
            WkbGeomReader reader = new WkbGeomReader(assumeWkbPolygonsClockwise);

            RingGroup deserialized = reader.ReadPolygon(new MemoryStream(bytes));

            Assert.IsTrue(deserialized.Equals(polygon));
        }