예제 #1
0
        public virtual void TestPolygonWithHoleReversed()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            //exterior ring - has to be clockwise for Esri
            p.StartPath(100.0, 0.0);
            p.LineTo(100.0, 1.0);
            p.LineTo(101.0, 1.0);
            p.LineTo(101.0, 0.0);
            p.ClosePathWithLine();
            //hole - counterclockwise for Esri
            p.StartPath(100.2, 0.2);
            p.LineTo(100.8, 0.2);
            p.LineTo(100.8, 0.8);
            p.LineTo(100.2, 0.8);
            p.ClosePathWithLine();
            p.ReverseAllPaths();
            //make it reversed. Exterior ring - ccw, hole - cw.
            com.epl.geometry.OperatorExportToGeoJson exporter = (com.epl.geometry.OperatorExportToGeoJson)factory.GetOperator(com.epl.geometry.Operator.Type.ExportToGeoJson);
            string result = exporter.Execute(p);

            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}", result);
        }
예제 #2
0
 public static void TestPointInAnyOuterRing()
 {
     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
     // outer ring1
     polygon.StartPath(-200, -100);
     polygon.LineTo(200, -100);
     polygon.LineTo(200, 100);
     polygon.LineTo(-190, 100);
     polygon.LineTo(-190, 90);
     polygon.LineTo(-200, 90);
     // hole
     polygon.StartPath(-100, 50);
     polygon.LineTo(100, 50);
     polygon.LineTo(100, -40);
     polygon.LineTo(90, -40);
     polygon.LineTo(90, -50);
     polygon.LineTo(-100, -50);
     // island
     polygon.StartPath(-10, -10);
     polygon.LineTo(10, -10);
     polygon.LineTo(10, 10);
     polygon.LineTo(-10, 10);
     // outer ring2
     polygon.StartPath(300, 300);
     polygon.LineTo(310, 300);
     polygon.LineTo(310, 310);
     polygon.LineTo(300, 310);
     polygon.ReverseAllPaths();
     com.epl.geometry.Point2D testPointIn1 = new com.epl.geometry.Point2D(1, 2);
     // inside the island
     com.epl.geometry.Point2D testPointIn2 = new com.epl.geometry.Point2D(190, 90);
     // inside, betwen outer
     // ring1 and the hole
     com.epl.geometry.Point2D testPointIn3 = new com.epl.geometry.Point2D(305, 305);
     // inside the outer ring2
     com.epl.geometry.Point2D testPointOut1 = new com.epl.geometry.Point2D(300, 2);
     // outside any
     com.epl.geometry.Point2D testPointOut2 = new com.epl.geometry.Point2D(-195, 95);
     // outside any (in the
     // concave area of outer
     // ring 2)
     com.epl.geometry.Point2D testPointOut3 = new com.epl.geometry.Point2D(99, 49);
     // outside (in the hole)
     com.epl.geometry.PolygonUtils.PiPResult res;
     // is_point_in_polygon_2D
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointIn1, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointIn2, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointIn3, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointOut1, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointOut2, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
     res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, testPointOut3, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
     // Ispoint_in_any_outer_ring
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointIn1, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointIn2, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointIn3, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointOut1, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointOut2, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
     res = com.epl.geometry.PolygonUtils.IsPointInAnyOuterRing(polygon, testPointOut3, 0);
     NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
 }