Ejemplo n.º 1
0
        public static void TestClipGeometries()
        {
            // RandomTest();
            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                     = MakePolygon();
            com.epl.geometry.SimpleGeometryCursor polygonCurs    = new com.epl.geometry.SimpleGeometryCursor(polygon);
            com.epl.geometry.Polyline             polyline       = MakePolyline();
            com.epl.geometry.SimpleGeometryCursor polylineCurs   = new com.epl.geometry.SimpleGeometryCursor(polyline);
            com.epl.geometry.MultiPoint           multipoint     = MakeMultiPoint();
            com.epl.geometry.SimpleGeometryCursor multipointCurs = new com.epl.geometry.SimpleGeometryCursor(multipoint);
            com.epl.geometry.Point point = MakePoint();
            com.epl.geometry.SimpleGeometryCursor pointCurs  = new com.epl.geometry.SimpleGeometryCursor(point);
            com.epl.geometry.SpatialReference     spatialRef = com.epl.geometry.SpatialReference.Create(3857);
            com.epl.geometry.Envelope2D           envelope   = new com.epl.geometry.Envelope2D();
            envelope.xmin = 0;
            envelope.xmax = 20;
            envelope.ymin = 5;
            envelope.ymax = 15;
            // Cursor implementation
            com.epl.geometry.GeometryCursor clipPolygonCurs = clipOp.Execute(polygonCurs, envelope, spatialRef, null);
            com.epl.geometry.Polygon        clippedPolygon  = (com.epl.geometry.Polygon)clipPolygonCurs.Next();
            double area = clippedPolygon.CalculateArea2D();

            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001);
            // Single Geometry implementation
            clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelope, spatialRef, null);
            area           = clippedPolygon.CalculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001);
            // Cursor implementation
            com.epl.geometry.GeometryCursor clipPolylineCurs = clipOp.Execute(polylineCurs, envelope, spatialRef, null);
            com.epl.geometry.Polyline       clippedPolyline  = (com.epl.geometry.Polyline)clipPolylineCurs.Next();
            double length = clippedPolyline.CalculateLength2D();

            NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10);
            // Single Geometry implementation
            clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(polyline, envelope, spatialRef, null);
            length          = clippedPolyline.CalculateLength2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10);
            // Cursor implementation
            com.epl.geometry.GeometryCursor clipMulti_pointCurs = clipOp.Execute(multipointCurs, envelope, spatialRef, null);
            com.epl.geometry.MultiPoint     clipped_multi_point = (com.epl.geometry.MultiPoint)clipMulti_pointCurs.Next();
            int pointCount = clipped_multi_point.GetPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            // Cursor implementation
            com.epl.geometry.GeometryCursor clipPointCurs = clipOp.Execute(pointCurs, envelope, spatialRef, null);
            com.epl.geometry.Point          clippedPoint  = (com.epl.geometry.Point)clipPointCurs.Next();
            NUnit.Framework.Assert.IsTrue(clippedPoint != null);
            // RandomTest();
            com.epl.geometry.Polyline _poly = new com.epl.geometry.Polyline();
            _poly.StartPath(2, 2);
            _poly.LineTo(0, 0);
            com.epl.geometry.Envelope2D _env = new com.epl.geometry.Envelope2D();
            _env.SetCoords(2, 1, 5, 3);
            com.epl.geometry.Polyline _clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(_poly, _env, spatialRef, null);
            NUnit.Framework.Assert.IsTrue(_clippedPolyline.IsEmpty());
            {
                com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon();
                poly.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 100, 100), false);
                poly.AddEnvelope(new com.epl.geometry.Envelope2D(5, 5, 95, 95), true);
                com.epl.geometry.Polygon clippedPoly = (com.epl.geometry.Polygon)clipOp.Execute(poly, new com.epl.geometry.Envelope2D(-10, -10, 110, 50), spatialRef, null);
                NUnit.Framework.Assert.IsTrue(clippedPoly.GetPathCount() == 1);
                NUnit.Framework.Assert.IsTrue(clippedPoly.GetPointCount() == 8);
            }
        }
Ejemplo n.º 2
0
        public static void TestDifferenceAndSymmetricDifference()
        {
            com.epl.geometry.OperatorFactoryLocal engine       = com.epl.geometry.OperatorFactoryLocal.GetInstance();
            com.epl.geometry.OperatorDifference   differenceOp = (com.epl.geometry.OperatorDifference)engine.GetOperator(com.epl.geometry.Operator.Type.Difference);
            com.epl.geometry.SpatialReference     spatialRef   = com.epl.geometry.SpatialReference.Create(102113);
            com.epl.geometry.Polygon    polygon1      = MakePolygon1();
            com.epl.geometry.Polygon    polygon2      = MakePolygon2();
            com.epl.geometry.Polyline   polyline1     = MakePolyline1();
            com.epl.geometry.MultiPoint multipoint1   = MakeMultiPoint1();
            com.epl.geometry.MultiPoint multipoint2   = MakeMultiPoint2();
            com.epl.geometry.MultiPoint multipoint3   = MakeMultiPoint3();
            com.epl.geometry.Point      point1        = MakePoint1();
            com.epl.geometry.Point      point2        = MakePoint2();
            com.epl.geometry.Envelope   envelope1     = MakeEnvelope1();
            com.epl.geometry.Envelope   envelope2     = MakeEnvelope2();
            com.epl.geometry.Envelope   envelope3     = MakeEnvelope3();
            com.epl.geometry.Polygon    outputPolygon = (com.epl.geometry.Polygon)differenceOp.Execute(polygon1, polygon2, spatialRef, null);
            double area = outputPolygon.CalculateArea2D();

            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001);
            {
                com.epl.geometry.Point            point_1        = new com.epl.geometry.Point(-130, 10);
                com.epl.geometry.Point            point_2        = new com.epl.geometry.Point(-130, 10);
                com.epl.geometry.Geometry         baseGeom       = new com.epl.geometry.Point(point_1.GetX(), point_1.GetY());
                com.epl.geometry.Geometry         comparisonGeom = new com.epl.geometry.Point(point_2.GetX(), point2.GetY());
                com.epl.geometry.SpatialReference sr             = com.epl.geometry.SpatialReference.Create(4326);
                com.epl.geometry.Geometry         geom           = differenceOp.Execute(baseGeom, comparisonGeom, sr, null);
            }
            com.epl.geometry.OperatorSymmetricDifference symDifferenceOp = (com.epl.geometry.OperatorSymmetricDifference)engine.GetOperator(com.epl.geometry.Operator.Type.SymmetricDifference);
            outputPolygon = (com.epl.geometry.Polygon)symDifferenceOp.Execute(polygon1, polygon2, spatialRef, null);
            area          = outputPolygon.CalculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 150) <= 0.001);
            com.epl.geometry.Polyline outputPolyline = (com.epl.geometry.Polyline)differenceOp.Execute(polyline1, polygon1, spatialRef, null);
            double length = outputPolyline.CalculateLength2D();

            NUnit.Framework.Assert.IsTrue(System.Math.Abs(length * length - 50) < 0.001);
            com.epl.geometry.MultiPoint outputMultiPoint = (com.epl.geometry.MultiPoint)differenceOp.Execute(multipoint1, polygon1, spatialRef, null);
            int pointCount = outputMultiPoint.GetPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount == 1);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(symDifferenceOp.Execute(multipoint1, point1, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(symDifferenceOp.Execute(multipoint1, point2, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 4);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, point1, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, point2, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 3);
            outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(polygon1, envelope1, spatialRef, null));
            area          = outputPolygon.CalculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001);
            outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(polygon2, envelope2, spatialRef, null));
            area          = outputPolygon.CalculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001);
            outputPolyline = (com.epl.geometry.Polyline)(differenceOp.Execute(polyline1, envelope2, spatialRef, null));
            length         = outputPolyline.CalculateLength2D();
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(length * length - 50) <= 0.001);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, envelope2, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 1);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint2, envelope2, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 6);
            outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint3, envelope2, spatialRef, null));
            pointCount       = outputMultiPoint.GetPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 0);
            com.epl.geometry.Point outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point1, envelope2, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(!outputPoint.IsEmpty());
            outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point2, envelope2, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPoint.IsEmpty());
            outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(envelope3, envelope2, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.IsEmpty());
            outputPolygon = (com.epl.geometry.Polygon)(symDifferenceOp.Execute(envelope3, envelope3, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.IsEmpty());
            outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point1, polygon1, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPoint != null);
        }
        /// <exception cref="com.fasterxml.jackson.core.JsonParseException"/>
        /// <exception cref="System.IO.IOException"/>
        internal virtual bool TestPolygon()
        {
            bool bAnswer = true;

            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.CreateParser(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());
                if (!CheckResultSpatialRef(mPolygonWGS84MP, 4326, 0))
                {
                    bAnswer = false;
                }
            }
            {
                com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
                p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
                p.StartPath(0, 0);
                p.LineTo(0, 1);
                p.LineTo(4, 4);
                p.StartPath(2, 2);
                p.LineTo(3, 3);
                p.LineTo(7, 8);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 7);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 5);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 5);
                s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[[[0,0,3,null],[0,1,0,7],[4,4,0,5],[0,0,3,null]],[[2,2,0,null],[3,3,0,null],[7,8,0,5],[2,2,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
            }
            {
                // Test Import Polygon from Polygon
                string rings = "{\"hasZ\": true, \"rings\" : [ [ [0,0, 5], [0.0, 10.0, 5], [10.0,10.0, 5, 66666], [10.0,0.0, 5] ], [ [12, 12] ],  [ [13 , 17], [13 , 17] ], [ [1.0, 1.0, 5, 66666], [9.0,1.0, 5], [9.0,9.0, 5], [1.0,9.0, 5], [1.0, 1.0, 5] ] ] }";
                com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(rings));
                com.epl.geometry.Polygon     p           = (com.epl.geometry.Polygon)mapGeometry.GetGeometry();
                double area   = p.CalculateArea2D();
                double length = p.CalculateLength2D();
                NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 4);
                int count = p.GetPointCount();
                NUnit.Framework.Assert.IsTrue(count == 15);
                NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
                NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
            }
            return(bAnswer);
        }