Пример #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));
        }
Пример #2
0
        public void CanReadWriteSingleRingPolygonXyz()
        {
            IPolygon poly = GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 400);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WritePolygon(poly);

            // Wkx
            var        ordinates     = Ordinates.Xyz;
            LinearRing wkxLinearRing =
                ToWkxLinearRing(GeometryUtils.GetWKSPointZs(poly), ordinates);

            byte[] wkx = ToChristianSchwarzWkb(ToWkxPolygon(wkxLinearRing));
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter geomWriter = new WkbGeomWriter();
            RingGroup     ringGroup  = GeometryConversionUtils.CreateRingGroup(poly);

            byte[] wkbGeom = geomWriter.WritePolygon(ringGroup, ordinates);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb));

            Assert.IsTrue(GeometryUtils.AreEqual(poly, restored));

            WkbGeomReader geomReader = new WkbGeomReader();

            Assert.IsTrue(
                ringGroup.Equals(geomReader.ReadPolygon(new MemoryStream(wkbGeom))));
        }
Пример #3
0
        public void CanReadWriteSingleExteriorRingWithIslandsPolygonXyz()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IPolygon outerRing =
                GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 432);

            outerRing.SpatialReference = sr;

            IPolygon innerRing =
                GeometryFactory.CreatePolygon(2600100, 1200100, 2600200, 1200200, 321);

            innerRing.SpatialReference = sr;

            IPolygon polyWithHole = (IPolygon)IntersectionUtils.Difference(outerRing, innerRing);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WritePolygon(polyWithHole);

            // Wkx
            var       ordinates    = Ordinates.Xyz;
            IGeometry exteriorRing = GeometryUtils.GetParts(polyWithHole).First();
            IGeometry interiorRing = GeometryUtils.GetPaths(polyWithHole).Last();

            LinearRing wkxOuterRing = ToWkxLinearRing(exteriorRing, ordinates);
            LinearRing wkxInnerRing = ToWkxLinearRing(interiorRing, ordinates);

            byte[] wkx = ToChristianSchwarzWkb(ToWkxPolygon(wkxOuterRing, new[] { wkxInnerRing }));
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter geomWriter = new WkbGeomWriter();
            RingGroup     ringGroup  = GeometryConversionUtils.CreateRingGroup(polyWithHole);

            byte[] wkbGeom = geomWriter.WritePolygon(ringGroup, ordinates);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb));

            Assert.IsTrue(GeometryUtils.AreEqual(polyWithHole, restored));

            // Geom:
            WkbGeomReader geomReader = new WkbGeomReader();

            Assert.IsTrue(
                ringGroup.Equals(geomReader.ReadPolygon(new MemoryStream(wkbGeom))));
        }
Пример #4
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));
        }