Пример #1
0
        public static void testClipGeometries()
        {
            // RandomTest();
            com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal
                                                                 .getInstance();
            com.esri.core.geometry.OperatorClip clipOp = (com.esri.core.geometry.OperatorClip
                                                          )engine.getOperator(com.esri.core.geometry.Operator.Type.Clip);
            com.esri.core.geometry.Polygon polygon = makePolygon();
            com.esri.core.geometry.SimpleGeometryCursor polygonCurs = new com.esri.core.geometry.SimpleGeometryCursor
                                                                          (polygon);
            com.esri.core.geometry.Polyline             polyline     = makePolyline();
            com.esri.core.geometry.SimpleGeometryCursor polylineCurs = new com.esri.core.geometry.SimpleGeometryCursor
                                                                           (polyline);
            com.esri.core.geometry.MultiPoint           multipoint     = makeMultiPoint();
            com.esri.core.geometry.SimpleGeometryCursor multipointCurs = new com.esri.core.geometry.SimpleGeometryCursor
                                                                             (multipoint);
            com.esri.core.geometry.Point point = makePoint();
            com.esri.core.geometry.SimpleGeometryCursor pointCurs = new com.esri.core.geometry.SimpleGeometryCursor
                                                                        (point);
            com.esri.core.geometry.SpatialReference spatialRef = com.esri.core.geometry.SpatialReference
                                                                 .create(3857);
            com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D
                                                             ();
            envelope.xmin = 0;
            envelope.xmax = 20;
            envelope.ymin = 5;
            envelope.ymax = 15;
            // Cursor implementation
            com.esri.core.geometry.GeometryCursor clipPolygonCurs = clipOp.execute(polygonCurs
                                                                                   , envelope, spatialRef, null);
            com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipPolygonCurs
                                                            .next();
            double area = clippedPolygon.calculateArea2D();

            NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 25) < 0.00001);
            // Single Geometry implementation
            clippedPolygon = (com.esri.core.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.esri.core.geometry.GeometryCursor clipPolylineCurs = clipOp.execute(polylineCurs
                                                                                    , envelope, spatialRef, null);
            com.esri.core.geometry.Polyline clippedPolyline = (com.esri.core.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.esri.core.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.esri.core.geometry.GeometryCursor clipMulti_pointCurs = clipOp.execute(multipointCurs
                                                                                       , envelope, spatialRef, null);
            com.esri.core.geometry.MultiPoint clipped_multi_point = (com.esri.core.geometry.MultiPoint
                                                                     )clipMulti_pointCurs.next();
            int pointCount = clipped_multi_point.getPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            // Cursor implementation
            com.esri.core.geometry.GeometryCursor clipPointCurs = clipOp.execute(pointCurs, envelope
                                                                                 , spatialRef, null);
            com.esri.core.geometry.Point clippedPoint = (com.esri.core.geometry.Point)clipPointCurs
                                                        .next();
            NUnit.Framework.Assert.IsTrue(clippedPoint != null);
            // RandomTest();
            com.esri.core.geometry.Polyline _poly = new com.esri.core.geometry.Polyline();
            _poly.startPath(2, 2);
            _poly.lineTo(0, 0);
            com.esri.core.geometry.Envelope2D _env = new com.esri.core.geometry.Envelope2D();
            _env.setCoords(2, 1, 5, 3);
            com.esri.core.geometry.Polyline _clippedPolyline = (com.esri.core.geometry.Polyline
                                                                )clipOp.execute(_poly, _env, spatialRef, null);
            NUnit.Framework.Assert.IsTrue(_clippedPolyline.isEmpty());
            {
                com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon();
                poly.addEnvelope(new com.esri.core.geometry.Envelope2D(0, 0, 100, 100), false);
                poly.addEnvelope(new com.esri.core.geometry.Envelope2D(5, 5, 95, 95), true);
                com.esri.core.geometry.Polygon clippedPoly = (com.esri.core.geometry.Polygon)clipOp
                                                             .execute(poly, new com.esri.core.geometry.Envelope2D(-10, -10, 110, 50), spatialRef
                                                                      , null);
                NUnit.Framework.Assert.IsTrue(clippedPoly.getPathCount() == 1);
                NUnit.Framework.Assert.IsTrue(clippedPoly.getPointCount() == 8);
            }
        }
        /// <exception cref="org.codehaus.jackson.JsonParseException"/>
        /// <exception cref="System.IO.IOException"/>
        internal virtual bool testPolygon()
        {
            bool bAnswer = true;

            com.esri.core.geometry.Polygon polygon = new com.esri.core.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);
            {
                org.codehaus.jackson.JsonParser polygonPathsWgs84Parser = factory.createJsonParser
                                                                              (com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWGS84, polygon
                                                                                                                                    ));
                com.esri.core.geometry.MapGeometry mPolygonWGS84MP = com.esri.core.geometry.GeometryEngine
                                                                     .jsonToGeometry(polygonPathsWgs84Parser);
                NUnit.Framework.Assert.IsTrue(polygon.getPointCount() + 1 == ((com.esri.core.geometry.Polygon
                                                                               )mPolygonWGS84MP.getGeometry()).getPointCount());
                NUnit.Framework.Assert.IsTrue(polygon.getPoint(0).getX() == ((com.esri.core.geometry.Polygon
                                                                              )mPolygonWGS84MP.getGeometry()).getPoint(0).getX());
                NUnit.Framework.Assert.IsTrue(polygon.getPoint(0).getY() == ((com.esri.core.geometry.Polygon
                                                                              )mPolygonWGS84MP.getGeometry()).getPoint(0).getY());
                NUnit.Framework.Assert.IsTrue(polygon.getPathCount() == ((com.esri.core.geometry.Polygon
                                                                          )mPolygonWGS84MP.getGeometry()).getPathCount());
                NUnit.Framework.Assert.IsTrue(polygon.getSegmentCount() + 1 == ((com.esri.core.geometry.Polygon
                                                                                 )mPolygonWGS84MP.getGeometry()).getSegmentCount());
                NUnit.Framework.Assert.IsTrue(polygon.getSegmentCount(0) == ((com.esri.core.geometry.Polygon
                                                                              )mPolygonWGS84MP.getGeometry()).getSegmentCount(0));
                NUnit.Framework.Assert.IsTrue(polygon.getSegmentCount(1) + 1 == ((com.esri.core.geometry.Polygon
                                                                                  )mPolygonWGS84MP.getGeometry()).getSegmentCount(1));
                int lastIndex = polygon.getPointCount() - 1;
                NUnit.Framework.Assert.IsTrue(polygon.getPoint(lastIndex).getX() == ((com.esri.core.geometry.Polygon
                                                                                      )mPolygonWGS84MP.getGeometry()).getPoint(lastIndex).getX());
                NUnit.Framework.Assert.IsTrue(polygon.getPoint(lastIndex).getY() == ((com.esri.core.geometry.Polygon
                                                                                      )mPolygonWGS84MP.getGeometry()).getPoint(lastIndex).getY());
                NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.getID() == mPolygonWGS84MP.getSpatialReference
                                                  ().getID());
                if (!checkResultSpatialRef(mPolygonWGS84MP, 4326, 0))
                {
                    bAnswer = false;
                }
            }
            {
                com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon();
                p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z);
                p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M);
                string s = com.esri.core.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.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0, 3);
                p.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 7);
                p.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 5);
                p.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 5, 0, 5);
                s = com.esri.core.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.esri.core.geometry.MapGeometry mapGeometry = com.esri.core.geometry.GeometryEngine
                                                                 .jsonToGeometry(factory.createJsonParser(rings));
                com.esri.core.geometry.Polygon p = (com.esri.core.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.esri.core.geometry.VertexDescription.Semantics
                                                             .Z));
                NUnit.Framework.Assert.IsTrue(!p.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                              .M));
            }
            return(bAnswer);
        }
        public static void testDifferenceAndSymmetricDifference()
        {
            com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal
                                                                 .getInstance();
            com.esri.core.geometry.OperatorDifference differenceOp = (com.esri.core.geometry.OperatorDifference
                                                                      )engine.getOperator(com.esri.core.geometry.Operator.Type.Difference);
            com.esri.core.geometry.SpatialReference spatialRef = com.esri.core.geometry.SpatialReference
                                                                 .create(102113);
            com.esri.core.geometry.Polygon    polygon1      = makePolygon1();
            com.esri.core.geometry.Polygon    polygon2      = makePolygon2();
            com.esri.core.geometry.Polyline   polyline1     = makePolyline1();
            com.esri.core.geometry.MultiPoint multipoint1   = makeMultiPoint1();
            com.esri.core.geometry.MultiPoint multipoint2   = makeMultiPoint2();
            com.esri.core.geometry.MultiPoint multipoint3   = makeMultiPoint3();
            com.esri.core.geometry.Point      point1        = makePoint1();
            com.esri.core.geometry.Point      point2        = makePoint2();
            com.esri.core.geometry.Envelope   envelope1     = makeEnvelope1();
            com.esri.core.geometry.Envelope   envelope2     = makeEnvelope2();
            com.esri.core.geometry.Envelope   envelope3     = makeEnvelope3();
            com.esri.core.geometry.Polygon    outputPolygon = (com.esri.core.geometry.Polygon)differenceOp
                                                              .execute(polygon1, polygon2, spatialRef, null);
            double area = outputPolygon.calculateArea2D();

            NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001);
            {
                com.esri.core.geometry.Point    point_1  = new com.esri.core.geometry.Point(-130, 10);
                com.esri.core.geometry.Point    point_2  = new com.esri.core.geometry.Point(-130, 10);
                com.esri.core.geometry.Geometry baseGeom = new com.esri.core.geometry.Point(point_1
                                                                                            .getX(), point_1.getY());
                com.esri.core.geometry.Geometry comparisonGeom = new com.esri.core.geometry.Point
                                                                     (point_2.getX(), point2.getY());
                com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                             .create(4326);
                com.esri.core.geometry.Geometry geom = differenceOp.execute(baseGeom, comparisonGeom
                                                                            , sr, null);
            }
            com.esri.core.geometry.OperatorSymmetricDifference symDifferenceOp = (com.esri.core.geometry.OperatorSymmetricDifference
                                                                                  )engine.getOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference);
            outputPolygon = (com.esri.core.geometry.Polygon)symDifferenceOp.execute(polygon1,
                                                                                    polygon2, spatialRef, null);
            area = outputPolygon.calculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 150) <= 0.001);
            com.esri.core.geometry.Polyline outputPolyline = (com.esri.core.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.esri.core.geometry.MultiPoint outputMultiPoint = (com.esri.core.geometry.MultiPoint
                                                                  )differenceOp.execute(multipoint1, polygon1, spatialRef, null);
            int pointCount = outputMultiPoint.getPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount == 1);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1
                                                                                           , point1, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1
                                                                                           , point2, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 4);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1
                                                                                        , point1, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 2);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1
                                                                                        , point2, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 3);
            outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon1, envelope1
                                                                                  , spatialRef, null));
            area = outputPolygon.calculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001);
            outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon2, envelope2
                                                                                  , spatialRef, null));
            area = outputPolygon.calculateArea2D();
            NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001);
            outputPolyline = (com.esri.core.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.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1
                                                                                        , envelope2, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 1);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint2
                                                                                        , envelope2, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 6);
            outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint3
                                                                                        , envelope2, spatialRef, null));
            pointCount = outputMultiPoint.getPointCount();
            NUnit.Framework.Assert.IsTrue(pointCount == 0);
            com.esri.core.geometry.Point outputPoint = (com.esri.core.geometry.Point)(differenceOp
                                                                                      .execute(point1, envelope2, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(!outputPoint.isEmpty());
            outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point2, envelope2
                                                                              , spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPoint.isEmpty());
            outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(envelope3,
                                                                                  envelope2, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty());
            outputPolygon = (com.esri.core.geometry.Polygon)(symDifferenceOp.execute(envelope3
                                                                                     , envelope3, spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty());
            outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point1, polygon1
                                                                              , spatialRef, null));
            NUnit.Framework.Assert.IsTrue(outputPoint != null);
        }