Ejemplo n.º 1
0
 public virtual void TestPolygon()
 {
     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
     polygon.StartPath(-97.06138, 32.837);
     polygon.LineTo(-97.06133, 32.836);
     polygon.LineTo(-97.06124, 32.834);
     polygon.LineTo(-97.06127, 32.832);
     polygon.StartPath(-97.06326, 32.759);
     polygon.LineTo(-97.06298, 32.755);
     {
         com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon));
         com.epl.geometry.MapGeometry          mPolygonWGS84MP         = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser);
         NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount());
         NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX());
         NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY());
         NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount());
         NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount());
         NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0));
         NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1));
         int lastIndex = polygon.GetPointCount() - 1;
         NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX());
         NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY());
         NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID());
         com.epl.geometry.Polygon emptyPolygon = new com.epl.geometry.Polygon();
         string emptyPolygonString             = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyPolygon);
         polygonPathsWgs84Parser = factory.CreateJsonParser(emptyPolygonString);
         mPolygonWGS84MP         = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser);
         NUnit.Framework.Assert.IsTrue(mPolygonWGS84MP.GetGeometry().IsEmpty());
         NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID());
     }
 }
 public static void Test5()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(0, 1);
     poly.LineTo(1, 1);
     poly.LineTo(1, 0);
     poly.StartPath(2, 0);
     poly.LineTo(2, 1);
     poly.LineTo(3, 1);
     poly.LineTo(3, 0);
     poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 1);
     poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 3);
     poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 6, 0, 1);
     poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 4);
     poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 0, 3, 1);
     poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 0, 1, 3);
     poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 1, 2, 1);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 2);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 1);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 2);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 3);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 3);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 4);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 6, 0) == 1);
     NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 7, 0) == 2);
 }
Ejemplo n.º 3
0
 private static com.epl.geometry.Polygon MakePolygon()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(0, 10);
     poly.LineTo(10, 10);
     poly.LineTo(10, 0);
     poly.StartPath(3, 3);
     poly.LineTo(7, 3);
     poly.LineTo(7, 7);
     poly.LineTo(3, 7);
     return(poly);
 }
Ejemplo n.º 4
0
        public virtual void TestEqualsOnPolygons()
        {
            com.epl.geometry.SpatialReference sr     = com.epl.geometry.SpatialReference.Create(4326);
            com.epl.geometry.Polygon          baseMp = new com.epl.geometry.Polygon();
            com.epl.geometry.Polygon          compMp = new com.epl.geometry.Polygon();
            baseMp.StartPath(-116, 40);
            baseMp.LineTo(-120, 39);
            baseMp.LineTo(-121, 10);
            baseMp.LineTo(-130, 12);
            baseMp.LineTo(-108, 25);
            compMp.StartPath(-116, 40);
            compMp.LineTo(-120, 39);
            compMp.LineTo(-121, 10);
            compMp.LineTo(-130, 12);
            compMp.LineTo(-108, 25);
            bool isEqual;

            try
            {
                isEqual = com.epl.geometry.GeometryEngine.Equals(baseMp, compMp, sr);
            }
            catch (System.ArgumentException)
            {
                isEqual = false;
            }
            NUnit.Framework.Assert.IsTrue(isEqual);
        }
Ejemplo n.º 5
0
        public virtual void TestTouchOnPolygons()
        {
            com.epl.geometry.Polygon pg = new com.epl.geometry.Polygon();
            pg.StartPath(new com.epl.geometry.Point(-130, 10));
            pg.LineTo(-131, 15);
            pg.LineTo(-140, 20);
            com.epl.geometry.Polygon pg2 = new com.epl.geometry.Polygon();
            pg2.StartPath(new com.epl.geometry.Point(-130, 10));
            pg2.LineTo(-131, 15);
            pg2.LineTo(-120, 20);
            com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326);
            bool isTouched;
            bool isTouched2;

            try
            {
                isTouched  = com.epl.geometry.GeometryEngine.Touches(pg, pg2, sr);
                isTouched2 = com.epl.geometry.GeometryEngine.Touches(pg2, pg, sr);
            }
            catch (System.ArgumentException)
            {
                isTouched  = false;
                isTouched2 = false;
            }
            NUnit.Framework.Assert.AreEqual(isTouched && isTouched2, true);
        }
Ejemplo n.º 6
0
        public virtual void TestGeometryCollection()
        {
            com.epl.geometry.SpatialReference sr         = com.epl.geometry.SpatialReference.Create(4326);
            System.Text.StringBuilder         geometrySb = new System.Text.StringBuilder();
            geometrySb.Append("{\"type\" : \"GeometryCollection\", \"geometries\" : [");
            com.epl.geometry.ogc.OGCPoint point = new com.epl.geometry.ogc.OGCPoint(new com.epl.geometry.Point(1.0, 1.0), sr);
            NUnit.Framework.Assert.AreEqual("{\"x\":1,\"y\":1,\"spatialReference\":{\"wkid\":4326}}", point.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[1,1],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", point.AsGeoJson());
            geometrySb.Append(point.AsGeoJson()).Append(", ");
            com.epl.geometry.ogc.OGCLineString line = new com.epl.geometry.ogc.OGCLineString(new com.epl.geometry.Polyline(new com.epl.geometry.Point(1.0, 1.0), new com.epl.geometry.Point(2.0, 2.0)), 0, sr);
            NUnit.Framework.Assert.AreEqual("{\"paths\":[[[1,1],[2,2]]],\"spatialReference\":{\"wkid\":4326}}", line.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", line.AsGeoJson());
            geometrySb.Append(line.AsGeoJson()).Append(", ");
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(1.0, 1.0);
            p.LineTo(2.0, 2.0);
            p.LineTo(3.0, 1.0);
            p.LineTo(2.0, 0.0);
            com.epl.geometry.ogc.OGCPolygon polygon = new com.epl.geometry.ogc.OGCPolygon(p, sr);
            NUnit.Framework.Assert.AreEqual("{\"rings\":[[[1,1],[2,2],[3,1],[2,0],[1,1]]],\"spatialReference\":{\"wkid\":4326}}", polygon.AsJson());
            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", polygon.AsGeoJson());
            geometrySb.Append(polygon.AsGeoJson()).Append("]}");
            System.Collections.Generic.IList <com.epl.geometry.ogc.OGCGeometry> geoms = new System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry>(3);
            geoms.Add(point);
            geoms.Add(line);
            geoms.Add(polygon);
            com.epl.geometry.ogc.OGCConcreteGeometryCollection collection = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(geoms, sr);
            string s2 = collection.AsGeoJson();

            NUnit.Framework.Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1,1]},{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]},{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]]}],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
                                            , collection.AsGeoJson());
        }
Ejemplo n.º 7
0
        public virtual void TestIntersectBetweenPolylineAndPolygon()
        {
            com.epl.geometry.Polyline basePl = new com.epl.geometry.Polyline();
            basePl.StartPath(new com.epl.geometry.Point(-117, 20));
            basePl.LineTo(new com.epl.geometry.Point(-117, 10));
            basePl.LineTo(new com.epl.geometry.Point(-130, 10));
            basePl.LineTo(new com.epl.geometry.Point(-130, 20));
            basePl.LineTo(new com.epl.geometry.Point(-117, 20));
            com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon();
            compPl.StartPath(-116, 20);
            compPl.LineTo(-131, 10);
            compPl.LineTo(-121, 50);
            com.epl.geometry.Geometry intersectGeom = null;
            int noException = 1;

            // no exception
            try
            {
                intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.IsNotNull(intersectGeom);
        }
Ejemplo n.º 8
0
 public static void TestPointInPolygonBugCR181840()
 {
     com.epl.geometry.PolygonUtils.PiPResult res;
     {
         // pointInPolygonBugCR181840 - point in polygon bug
         com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
         // outer ring1
         polygon.StartPath(0, 0);
         polygon.LineTo(10, 10);
         polygon.LineTo(20, 0);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(15, 10), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(2, 10), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(5, 5), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     }
     {
         // CR181840 - point in polygon bug
         com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
         // outer ring1
         polygon.StartPath(10, 10);
         polygon.LineTo(20, 0);
         polygon.LineTo(0, 0);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(15, 10), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(2, 10), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside);
         res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(5, 5), 0);
         NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside);
     }
 }
Ejemplo n.º 9
0
        public virtual void TestPointAndPolygon3()
        {
            com.epl.geometry.Point   basePl = new com.epl.geometry.Point(-121, 20);
            com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon();
            compPl.StartPath(new com.epl.geometry.Point(-116, 20));
            compPl.LineTo(new com.epl.geometry.Point(-131, 10));
            compPl.LineTo(new com.epl.geometry.Point(-121, 50));
            int noException = 1;

            // no exception
            com.epl.geometry.Geometry intersectGeom = null;
            try
            {
                intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.AreEqual(noException, 1);
            NUnit.Framework.Assert.IsNotNull(intersectGeom);
            NUnit.Framework.Assert.IsTrue(intersectGeom.GetType() == com.epl.geometry.Geometry.Type.Point);
            com.epl.geometry.Point ip = (com.epl.geometry.Point)intersectGeom;
            NUnit.Framework.Assert.AreEqual(ip.GetX(), -121, 0.1E7);
            NUnit.Framework.Assert.AreEqual(ip.GetY(), 20, 0.1E7);
        }
Ejemplo n.º 10
0
        public virtual void TestGeometryToJSONOldID()
        {
            // CR
            com.epl.geometry.Polygon geom = new com.epl.geometry.Polygon();
            geom.StartPath(new com.epl.geometry.Point(-113, 34));
            geom.LineTo(new com.epl.geometry.Point(-105, 34));
            geom.LineTo(new com.epl.geometry.Point(-108, 40));
            string outputPolygon = com.epl.geometry.GeometryEngine.GeometryToJson(com.epl.geometry.SpatialReference.Create(3857), geom);
            // Test
            // WKID
            // ==
            // -1
            string correctPolygon = "{\"rings\":[[[-113,34],[-105,34],[-108,40],[-113,34]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}";

            NUnit.Framework.Assert.IsTrue(outputPolygon.Equals(correctPolygon));
            com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory();
            com.fasterxml.jackson.core.JsonParser  jp = jf.CreateJsonParser(outputPolygon);
            jp.NextToken();
            com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp);
            int srId    = mg.GetSpatialReference().GetID();
            int srOldId = mg.GetSpatialReference().GetOldID();

            NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 3857);
            NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetLatestID() == 3857);
            NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetOldID() == 102100);
        }
Ejemplo n.º 11
0
 public static void Test1()
 {
     com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance();
     com.epl.geometry.OperatorGeneralize   op     = (com.epl.geometry.OperatorGeneralize)engine.GetOperator(com.epl.geometry.Operator.Type.Generalize);
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(1, 1);
     poly.LineTo(2, 0);
     poly.LineTo(3, 2);
     poly.LineTo(4, 1);
     poly.LineTo(5, 0);
     poly.LineTo(5, 10);
     poly.LineTo(0, 10);
     com.epl.geometry.Geometry  geom   = op.Execute(poly, 2, true, null);
     com.epl.geometry.Polygon   p      = (com.epl.geometry.Polygon)geom;
     com.epl.geometry.Point2D[] points = p.GetCoordinates2D();
     NUnit.Framework.Assert.IsTrue(points.Length == 4);
     NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0);
     NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 0);
     NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10);
     NUnit.Framework.Assert.IsTrue(points[3].x == 0 && points[3].y == 10);
     com.epl.geometry.Geometry geom1 = op.Execute(geom, 5, false, null);
     p      = (com.epl.geometry.Polygon)geom1;
     points = p.GetCoordinates2D();
     NUnit.Framework.Assert.IsTrue(points.Length == 3);
     NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0);
     NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 10);
     NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10);
     geom1  = op.Execute(geom, 5, true, null);
     p      = (com.epl.geometry.Polygon)geom1;
     points = p.GetCoordinates2D();
     NUnit.Framework.Assert.IsTrue(points.Length == 0);
 }
Ejemplo n.º 12
0
        public virtual void TestTouchesOnPolylineAndPolygon()
        {
            com.epl.geometry.SpatialReference sr     = com.epl.geometry.SpatialReference.Create(4326);
            com.epl.geometry.Polygon          basePl = new com.epl.geometry.Polygon();
            basePl.StartPath(new com.epl.geometry.Point(-117, 20));
            basePl.LineTo(new com.epl.geometry.Point(-100, 20));
            basePl.LineTo(new com.epl.geometry.Point(-100, 10));
            basePl.LineTo(new com.epl.geometry.Point(-117, 10));
            com.epl.geometry.Polyline compPl = new com.epl.geometry.Polyline();
            compPl.StartPath(new com.epl.geometry.Point(-117, 20));
            compPl.LineTo(new com.epl.geometry.Point(-108, 25));
            compPl.LineTo(new com.epl.geometry.Point(-100, 20));
            compPl.LineTo(new com.epl.geometry.Point(-100, 30));
            bool isTouched;

            try
            {
                isTouched = com.epl.geometry.GeometryEngine.Touches(basePl, compPl, sr);
            }
            catch (System.ArgumentException)
            {
                isTouched = false;
            }
            NUnit.Framework.Assert.AreEqual(isTouched, true);
        }
Ejemplo n.º 13
0
        public static void TestDistanceBetweenHugeGeometries()
        {
            /* const */
            int N = 1000;
            // Should be even
            /* const */
            double theoreticalDistance = 0.77;

            com.epl.geometry.Polygon poly  = new com.epl.geometry.Polygon();
            com.epl.geometry.Polygon poly2 = new com.epl.geometry.Polygon();
            double theta       = 0.0;
            double thetaPlusPi = System.Math.PI;
            double dTheta      = 2.0 * System.Math.PI / N;
            double distance;

            poly.StartPath(System.Math.Cos(theta), System.Math.Sin(theta));
            // Add something so that poly2's bounding box is in poly's. Deleting
            // this should not affect answer.
            poly.LineTo(1.0, 1.5 + theoreticalDistance);
            poly.LineTo(3.5 + theoreticalDistance, 1.5 + theoreticalDistance);
            poly.LineTo(3.5 + theoreticalDistance, 2.0 + theoreticalDistance);
            poly.LineTo(0.95, 2.0 + theoreticalDistance);
            // ///////////////////////////////////////////////////////////
            poly2.StartPath(2.0 + theoreticalDistance + System.Math.Cos(thetaPlusPi), System.Math.Sin(thetaPlusPi));
            for (double i = 1; i < N; i++)
            {
                theta       += dTheta;
                thetaPlusPi += dTheta;
                poly.LineTo(System.Math.Cos(theta), System.Math.Sin(theta));
                poly2.LineTo(2.0 + theoreticalDistance + System.Math.Cos(thetaPlusPi), System.Math.Sin(thetaPlusPi));
            }
            distance = com.epl.geometry.GeometryEngine.Distance(poly, poly2, null);
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(distance - theoreticalDistance) < 1.0e-10);
        }
Ejemplo n.º 14
0
 public static com.epl.geometry.Polygon MakePolygon9()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(0, 10);
     poly.LineTo(10, 10);
     poly.LineTo(10, 0);
     poly.StartPath(0, 20);
     poly.LineTo(0, 30);
     poly.LineTo(10, 30);
     poly.LineTo(10, 20);
     poly.StartPath(0, 40);
     poly.LineTo(0, 50);
     poly.LineTo(10, 50);
     poly.LineTo(10, 40);
     return(poly);
 }
Ejemplo n.º 15
0
 internal static com.epl.geometry.Polygon MakePolygon()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(10, 10);
     poly.LineTo(20, 0);
     return(poly);
 }
Ejemplo n.º 16
0
 public static com.epl.geometry.Polygon MakePolygon2()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(5, 5);
     poly.LineTo(5, 15);
     poly.LineTo(15, 15);
     poly.LineTo(15, 5);
     return(poly);
 }
Ejemplo n.º 17
0
 internal virtual com.epl.geometry.Polygon MakePolygon2()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(0, 0);
     poly.LineTo(0, 10);
     poly.LineTo(10, 10);
     poly.LineTo(10, 0);
     return(poly);
 }
Ejemplo n.º 18
0
        public virtual void TestOGCPolygonWithHole()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            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();
            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();
            com.epl.geometry.ogc.OGCPolygon ogcPolygon = new com.epl.geometry.ogc.OGCPolygon(p, null);
            string result = ogcPolygon.AsGeoJson();

            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.2,0.8],[100.8,0.8],[100.8,0.2],[100.2,0.2]]],\"crs\":null}", result);
        }
Ejemplo n.º 19
0
        public virtual void TestPolygonWithHoleGeometryEngine()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(100.0, 0.0);
            //clockwise exterior
            p.LineTo(100.0, 1.0);
            p.LineTo(101.0, 1.0);
            p.LineTo(101.0, 0.0);
            p.ClosePathWithLine();
            p.StartPath(100.2, 0.2);
            //counterclockwise hole
            p.LineTo(100.8, 0.2);
            p.LineTo(100.8, 0.8);
            p.LineTo(100.2, 0.8);
            p.ClosePathWithLine();
            string result = com.epl.geometry.GeometryEngine.GeometryToGeoJson(p);

            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.2,0.8],[100.8,0.8],[100.8,0.2],[100.2,0.2]]]}", result);
        }
Ejemplo n.º 20
0
        public virtual void TestTouchesBetweenPolylineAndPolygon()
        {
            com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326);
            com.epl.geometry.Polyline         pl = new com.epl.geometry.Polyline();
            pl.StartPath(2, 4);
            pl.LineTo(1, 10);
            pl.LineTo(6, 12);
            com.epl.geometry.Polygon compPg = new com.epl.geometry.Polygon();
            compPg.StartPath(2, 4);
            compPg.LineTo(2, 9);
            compPg.LineTo(9, 9);
            compPg.LineTo(9, 4);
            compPg.StartPath(2, 9);
            compPg.LineTo(6, 12);
            compPg.LineTo(9, 10);
            bool isTouched = com.epl.geometry.GeometryEngine.Touches(pl, compPg, sr);

            NUnit.Framework.Assert.AreEqual(isTouched, true);
        }
Ejemplo n.º 21
0
        public virtual void TestPolygonWithHole()
        {
            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();
            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],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.2,0.8],[100.8,0.8],[100.8,0.2],[100.2,0.2]]]}", result);
        }
Ejemplo n.º 22
0
        public virtual void TestPolygonGeometryEngine()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(100.0, 0.0);
            p.LineTo(101.0, 0.0);
            p.LineTo(101.0, 1.0);
            p.LineTo(100.0, 1.0);
            p.ClosePathWithLine();
            string result = com.epl.geometry.GeometryEngine.GeometryToGeoJson(p);

            NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]]}", result);
        }
Ejemplo n.º 23
0
        public virtual void TestPolygon()
        {
            com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
            p.StartPath(100.0, 0.0);
            p.LineTo(101.0, 0.0);
            p.LineTo(101.0, 1.0);
            p.LineTo(100.0, 1.0);
            p.ClosePathWithLine();
            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]]]}", result);
        }
Ejemplo n.º 24
0
 public static void TestClipIssue258243()
 {
     com.epl.geometry.Polygon poly1 = new com.epl.geometry.Polygon();
     poly1.StartPath(21.476191371901479, 41.267022001907215);
     poly1.LineTo(59.669186665158051, 36.62700518555863);
     poly1.LineTo(20.498578117352313, 30.363180148246094);
     poly1.LineTo(18.342565836615044, 46.303295352085627);
     poly1.LineTo(17.869569458621626, 23.886816966894159);
     poly1.LineTo(19.835465558090434, 20);
     poly1.LineTo(18.83911285048551, 43.515995498114791);
     poly1.LineTo(20.864485260298004, 20.235921201027757);
     poly1.LineTo(18.976127544787012, 20);
     poly1.LineTo(34.290201277718218, 61.801369014954794);
     poly1.LineTo(20.734727419368866, 20);
     poly1.LineTo(18.545865698148113, 20);
     poly1.LineTo(19.730260558565515, 20);
     poly1.LineTo(19.924806216827005, 23.780315893949187);
     poly1.LineTo(21.675168105421452, 36.699924873001258);
     poly1.LineTo(22.500527828912158, 43.703424859922983);
     poly1.LineTo(42.009527116514818, 36.995486982256089);
     poly1.LineTo(24.469729873835782, 58.365871758247039);
     poly1.LineTo(24.573736036545878, 36.268390409195824);
     poly1.LineTo(22.726502169802746, 20);
     poly1.LineTo(23.925834885228145, 20);
     poly1.LineTo(25.495346880936729, 20);
     poly1.LineTo(23.320941499288317, 20);
     poly1.LineTo(24.05655665646276, 28.659578774758632);
     poly1.LineTo(23.205940789341135, 38.491506888710504);
     poly1.LineTo(21.472847203385509, 53.057228182018044);
     poly1.LineTo(25.04257681654104, 20);
     poly1.LineTo(25.880572351149542, 25.16102863979474);
     poly1.LineTo(26.756283333879658, 20);
     poly1.LineTo(21.476191371901479, 41.267022001907215);
     com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
     env.SetCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793);
     try
     {
         com.epl.geometry.Geometry output_geom = com.epl.geometry.OperatorClip.Local().Execute(poly1, env, com.epl.geometry.SpatialReference.Create(4326), null);
         com.epl.geometry.Envelope envPoly     = new com.epl.geometry.Envelope();
         poly1.QueryEnvelope(envPoly);
         com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(env);
         e.Intersect(envPoly);
         com.epl.geometry.Envelope clippedEnv = new com.epl.geometry.Envelope();
         output_geom.QueryEnvelope(clippedEnv);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(clippedEnv.GetXMin() - e.GetXMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMin() - e.GetYMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetXMax() - e.GetXMax()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMax() - e.GetYMax()) < 1e-10);
     }
     catch (System.Exception)
     {
         NUnit.Framework.Assert.IsTrue(false);
     }
 }
Ejemplo n.º 25
0
 public static void TestArcObjectsFailureCR196492()
 {
     com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance();
     com.epl.geometry.OperatorClip         clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip);
     com.epl.geometry.Polygon polygon             = new com.epl.geometry.Polygon();
     polygon.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 600, 600), false);
     polygon.StartPath(30, 300);
     polygon.LineTo(20, 310);
     polygon.LineTo(10, 300);
     com.epl.geometry.SpatialReference gcsWGS84       = com.epl.geometry.SpatialReference.Create(4326);
     com.epl.geometry.Envelope2D       envelopeCR     = new com.epl.geometry.Envelope2D(10, 10, 500, 500);
     com.epl.geometry.Polygon          clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null);
     NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 7);
 }
Ejemplo n.º 26
0
 internal virtual com.epl.geometry.Polygon MakePolygon()
 {
     com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
     poly.StartPath(3, -2);
     poly.LineTo(2, -1);
     poly.LineTo(3, 0);
     poly.LineTo(4, 0);
     poly.StartPath(1.75, 1);
     poly.LineTo(0.75, 2);
     poly.LineTo(1.75, 3);
     poly.LineTo(2.25, 2.5);
     poly.LineTo(2.75, 2);
     poly.StartPath(3, 2.5);
     poly.LineTo(2.5, 3);
     poly.LineTo(2, 3.5);
     poly.LineTo(3, 4.5);
     poly.LineTo(4, 3.5);
     poly.StartPath(4.75, 1);
     poly.LineTo(3.75, 2);
     poly.LineTo(4, 2.25);
     poly.LineTo(4.75, 3);
     poly.LineTo(5.75, 2);
     return(poly);
 }
Ejemplo n.º 27
0
        /// <summary>Gets the current bounding geometry.</summary>
        /// <remarks>
        /// Gets the current bounding geometry.
        /// Returns a Geometry.
        /// </remarks>
        internal virtual com.epl.geometry.Geometry GetBoundingGeometry()
        {
            // Extracts the convex hull from the tree. Reading the tree in order from first to last is the resulting convex hull.
            com.epl.geometry.Point point = new com.epl.geometry.Point();
            int first = m_tree_hull.GetFirst(-1);

            com.epl.geometry.Polygon hull = new com.epl.geometry.Polygon(m_shape.GetVertexDescription());
            m_shape.QueryPoint(m_tree_hull.GetElement(first), point);
            hull.StartPath(point);
            for (int i = m_tree_hull.GetNext(first); i != -1; i = m_tree_hull.GetNext(i))
            {
                m_shape.QueryPoint(m_tree_hull.GetElement(i), point);
                hull.LineTo(point);
            }
            return(hull);
        }
Ejemplo n.º 28
0
 public static void TestProximity2D_3()
 {
     com.epl.geometry.OperatorFactoryLocal factory   = com.epl.geometry.OperatorFactoryLocal.GetInstance();
     com.epl.geometry.OperatorProximity2D  proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D);
     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
     polygon.StartPath(new com.epl.geometry.Point(-120, 22));
     polygon.LineTo(new com.epl.geometry.Point(-120, 10));
     polygon.LineTo(new com.epl.geometry.Point(-110, 10));
     polygon.LineTo(new com.epl.geometry.Point(-110, 22));
     com.epl.geometry.Point point = new com.epl.geometry.Point();
     point.SetXY(-110, 20);
     com.epl.geometry.Proximity2DResult result = proximity.GetNearestCoordinate(polygon, point, false);
     com.epl.geometry.Point             point2 = new com.epl.geometry.Point();
     point2.SetXY(-120, 12);
     com.epl.geometry.Proximity2DResult[] results = proximity.GetNearestVertices(polygon, point2, 10, 12);
 }
Ejemplo n.º 29
0
        public static void TestDistanceBetweenTriangles()
        {
            double distance;

            com.epl.geometry.Polygon poly  = new com.epl.geometry.Polygon();
            com.epl.geometry.Polygon poly2 = new com.epl.geometry.Polygon();
            poly.StartPath(0.0, 0.0);
            poly.LineTo(1.0, 2.0);
            poly.LineTo(0.0, 2.0);
            double xSeparation = 0.1;
            double ySeparation = 0.1;

            poly2.StartPath(xSeparation + 1.0, 2.0 - ySeparation);
            poly2.LineTo(xSeparation + 2.0, 2.0 - ySeparation);
            poly2.LineTo(xSeparation + 2.0, 4.0 - ySeparation);
            distance = com.epl.geometry.GeometryEngine.Distance(poly, poly2, null);
            NUnit.Framework.Assert.IsTrue(0.0 < distance && distance < xSeparation + ySeparation);
        }
Ejemplo n.º 30
0
 public static void TestClipAttributes()
 {
     com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance();
     com.epl.geometry.OperatorClip         clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip);
     {
         com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
         polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
         polygon.StartPath(0, 0);
         polygon.LineTo(30, 30);
         polygon.LineTo(60, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120);
         com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D();
         clipper.SetCoords(10, 0, 50, 20);
         com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 100);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996);
         // 20.0
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 20);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 40);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 80);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 100);
     }
     {
         com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
         polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
         polygon.StartPath(0, 0);
         polygon.LineTo(0, 40);
         polygon.LineTo(20, 40);
         polygon.LineTo(20, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 180);
         com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D();
         clipper.SetCoords(0, 10, 20, 20);
         com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 15);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 30);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 150);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 165);
     }
 }