コード例 #1
0
 private static void TestShellRingOrientationSetter(GeometryFactoryEx gf, LinearRingOrientation ringOrientation, int failKind)
 {
     try
     {
         gf.OrientationOfExteriorRing = ringOrientation;
         if (failKind != 0)
         {
             Assert.Fail("Setting exterior ring orientation should have failed!");
         }
         Assert.AreEqual(ringOrientation, gf.OrientationOfExteriorRing);
     }
     catch (ArgumentOutOfRangeException iae)
     {
         if (failKind != 1)
         {
             Assert.Fail("Wrong argument");
         }
     }
     catch (InvalidOperationException isa)
     {
         if (failKind != 2)
         {
             Assert.Fail("Setting exterior ring orientation twice!");
         }
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
コード例 #2
0
        public void CustomGeometryFactoryShouldBeAllowedWithSRID()
        {
            var       pm          = new PrecisionModel(10);
            const int initialSRID = 0;
            var       csf         = PackedCoordinateSequenceFactory.FloatFactory;
            const LinearRingOrientation orientation = LinearRingOrientation.Clockwise;

            var gf = new GeometryFactoryEx(pm, initialSRID, csf)
            {
                OrientationOfExteriorRing = orientation,
            };

            const int expectedSRID = 4326;
            string    xml          = $@"
<gml:Point srsName='urn:ogc:def:crs:EPSG::{expectedSRID}' xmlns:gml='http://www.opengis.net/gml'>
  <gml:coordinates>45.67, 65.43</gml:coordinates>
</gml:Point>";

            var gr = new GMLReader(gf);

            foreach (var readMethod in GetReadMethods())
            {
                var pt = (Point)readMethod(gr, xml);
                Assert.That(pt.Factory, Is.InstanceOf <GeometryFactoryEx>()
                            .With.Property(nameof(GeometryFactoryEx.SRID)).EqualTo(expectedSRID)
                            .With.Property(nameof(GeometryFactoryEx.OrientationOfExteriorRing)).EqualTo(orientation)
                            .With.Property(nameof(GeometryFactoryEx.PrecisionModel)).EqualTo(pm)
                            .With.Property(nameof(GeometryFactoryEx.CoordinateSequenceFactory)).EqualTo(csf));
            }
        }
コード例 #3
0
        public void SettingSRIDShouldCopyFactoryFaithfully()
        {
            var       pm          = new PrecisionModel(10);
            const int initialSRID = 0;
            var       csf         = PackedCoordinateSequenceFactory.FloatFactory;
            const LinearRingOrientation orientation = LinearRingOrientation.Clockwise;

            var gf = new GeometryFactoryEx(pm, initialSRID, csf)
            {
                OrientationOfExteriorRing = orientation,
            };

            var env = new Envelope(-10, 10, -8, 8);
            var g   = gf.ToGeometry(env);

            const int expectedSRID = 4326;

            g.SRID = expectedSRID;
            Assert.That(g.Factory, Is.InstanceOf <GeometryFactoryEx>()
                        .With.Property(nameof(GeometryFactoryEx.SRID)).EqualTo(expectedSRID)
                        .With.Property(nameof(GeometryFactoryEx.OrientationOfExteriorRing)).EqualTo(orientation)
                        .With.Property(nameof(GeometryFactoryEx.PrecisionModel)).EqualTo(pm)
                        .With.Property(nameof(GeometryFactoryEx.CoordinateSequenceFactory)).EqualTo(csf));
        }
コード例 #4
0
        private static CoordinateSequence CreateRing(CoordinateSequenceFactory factory, int ring, LinearRingOrientation orientation)
        {
            var coordinates = CreateCcwRing(ring);

            if (orientation == LinearRingOrientation.Clockwise)
            {
                CoordinateArrays.Reverse(coordinates);
            }
            if (orientation == LinearRingOrientation.DontCare)
            {
                if (reverseSequence)
                {
                    CoordinateArrays.Reverse(coordinates);
                }
                reverseSequence = !reverseSequence;
            }

            return(factory.Create(coordinates));
        }
コード例 #5
0
        private static void TestShellRingOrientationEnforcement(LinearRingOrientation ringOrientation)
        {
            var gf = new GeometryFactoryEx();

            gf.OrientationOfExteriorRing = ringOrientation;
            var cf = gf.CoordinateSequenceFactory;

            var origShellSequence  = CreateRing(cf, 0, ringOrientation);
            var origHolesSequences = new[]
            {
                CreateRing(cf, 1, ringOrientation),
                CreateRing(cf, 2, ringOrientation)
            };

            var shell = gf.CreateLinearRing(origShellSequence.Copy());
            var holes = new LinearRing[]
            {
                gf.CreateLinearRing(origHolesSequences[0].Copy()),
                gf.CreateLinearRing(origHolesSequences[1].Copy())
            };

            var polygon = gf.CreatePolygon(shell, holes);

            switch (ringOrientation)
            {
            case LinearRingOrientation.CW:
                if (polygon.Shell.IsCCW)
                {
                    Assert.Fail($"Shell ring orientation requested {LinearRingOrientation.CW}, was CCW");
                }
                if (!polygon.Holes[0].IsCCW)
                {
                    Assert.Fail($"Hole[0] ring orientation requested {LinearRingOrientation.CCW}, was CW");
                }
                ;
                if (!polygon.Holes[1].IsCCW)
                {
                    Assert.Fail($"Hole[1] ring orientation requested {LinearRingOrientation.CCW}, was CW");
                }
                ;
                break;

            case LinearRingOrientation.CCW:
                if (!polygon.Shell.IsCCW)
                {
                    Assert.Fail($"Shell ring orientation requested {LinearRingOrientation.CCW}, was CW");
                }
                if (polygon.Holes[0].IsCCW)
                {
                    Assert.Fail($"Hole[0] ring orientation requested {LinearRingOrientation.CW}, was CCW");
                }
                ;
                if (polygon.Holes[1].IsCCW)
                {
                    Assert.Fail($"Hole[1] ring orientation requested {LinearRingOrientation.CW}, was CCW");
                }
                ;
                break;

            case LinearRingOrientation.DontCare:
                if (polygon.Shell.IsCCW != Orientation.IsCCW(origShellSequence))
                {
                    Assert.Fail($"Shell ring orientation flipped");
                }
                if (polygon.Holes[0].IsCCW != Orientation.IsCCW(origHolesSequences[0]))
                {
                    Assert.Fail($"Hole[0] ring orientation flipped");
                }
                if (polygon.Holes[1].IsCCW != Orientation.IsCCW(origHolesSequences[1]))
                {
                    Assert.Fail($"Hole[1] ring orientation flipped");
                }
                break;
            }

            // Set up a polygon with hole using buffer
            var pt   = new Coordinate(0, 0);
            var c    = gf.CreatePoint(pt);
            var b    = c.Buffer(10d);
            var s    = c.Buffer(6d);
            var test = (Polygon)b.Difference(s);

            if (ringOrientation == LinearRingOrientation.CW)
            {
                if (test.Shell.IsCCW)
                {
                    Assert.Fail($"Buffer should return shell ring with CW orientation");
                }
                if (!test.Holes[0].IsCCW)
                {
                    Assert.Fail($"Buffer should return hole ring with CCW orientation");
                }
            }
            else if (ringOrientation == LinearRingOrientation.CCW)
            {
                if (!test.Shell.IsCCW)
                {
                    Assert.Fail($"Buffer should return shell ring with CCW orientation");
                }
                if (test.Holes[0].IsCCW)
                {
                    Assert.Fail($"Buffer should return hole ring with CW orientation");
                }
            }
        }