예제 #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);
            }
        }
        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 TestPolyline()
        {
            bool bAnswer = true;

            com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline();
            polyline.StartPath(-97.06138, 32.837);
            polyline.LineTo(-97.06133, 32.836);
            polyline.LineTo(-97.06124, 32.834);
            polyline.LineTo(-97.06127, 32.832);
            polyline.StartPath(-97.06326, 32.759);
            polyline.LineTo(-97.06298, 32.755);
            {
                com.fasterxml.jackson.core.JsonParser polylinePathsWgs84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polyline));
                com.epl.geometry.MapGeometry          mPolylineWGS84MP         = com.epl.geometry.GeometryEngine.JsonToGeometry(polylinePathsWgs84Parser);
                NUnit.Framework.Assert.IsTrue(polyline.GetPointCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPointCount());
                NUnit.Framework.Assert.IsTrue(polyline.GetPoint(0).GetX() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(0).GetX());
                NUnit.Framework.Assert.IsTrue(polyline.GetPoint(0).GetY() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(0).GetY());
                NUnit.Framework.Assert.IsTrue(polyline.GetPathCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPathCount());
                NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount());
                NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount(0) == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount(0));
                NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount(1) == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount(1));
                int lastIndex = polyline.GetPointCount() - 1;
                NUnit.Framework.Assert.IsTrue(polyline.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX());
                NUnit.Framework.Assert.IsTrue(polyline.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY());
                NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolylineWGS84MP.GetSpatialReference().GetID());
                if (!CheckResultSpatialRef(mPolylineWGS84MP, 4326, 0))
                {
                    bAnswer = false;
                }
            }
            {
                com.epl.geometry.Polyline p = new com.epl.geometry.Polyline();
                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,\"paths\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
                p.StartPath(0, 0);
                p.LineTo(0, 1);
                p.StartPath(2, 2);
                p.LineTo(3, 3);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3);
                p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 5);
                s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"paths\":[[[0,0,3,null],[0,1,0,5]],[[2,2,0,null],[3,3,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
            }
            {
                string paths = "{\"hasZ\" : true, \"paths\" : [ [ [0.0, 0.0,3], [0, 10.0,3], [10.0, 10.0,3, 6666], [10.0, 0.0,3, 6666] ], [ [1.0, 1,3], [1.0, 9.0,3], [9.0, 9.0,3], [1.0, 9.0,3] ] ], \"spatialReference\" : {\"wkid\" : 4326}, \"hasM\" : false}";
                com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(paths));
                com.epl.geometry.Polyline    p           = (com.epl.geometry.Polyline)mapGeometry.GetGeometry();
                NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 2);
                int count = p.GetPathCount();
                NUnit.Framework.Assert.IsTrue(p.GetPointCount() == 8);
                NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
                NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
                double z = p.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0);
                NUnit.Framework.Assert.IsTrue(z == 3);
                double length = p.CalculateLength2D();
                NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 54.0) <= 0.001);
                com.epl.geometry.SpatialReference spatial_reference = mapGeometry.GetSpatialReference();
                NUnit.Framework.Assert.IsTrue(spatial_reference.GetID() == 4326);
            }
            return(bAnswer);
        }