Example #1
0
        public virtual void testMultiPointAndMultiPoint3()
        {
            com.esri.core.geometry.MultiPoint basePl = new com.esri.core.geometry.MultiPoint(
                );
            basePl.add(new com.esri.core.geometry.Point(-116, 21));
            basePl.add(new com.esri.core.geometry.Point(-117, 20));
            com.esri.core.geometry.MultiPoint compPl = new com.esri.core.geometry.MultiPoint(
                );
            compPl.add(new com.esri.core.geometry.Point(-116, 20));
            compPl.add(new com.esri.core.geometry.Point(-117, 21));
            compPl.add(new com.esri.core.geometry.Point(-118, 20));
            compPl.add(new com.esri.core.geometry.Point(-119, 21));
            int noException = 1;

            // no exception
            com.esri.core.geometry.Geometry intersectGeom = null;
            try
            {
                intersectGeom = com.esri.core.geometry.GeometryEngine.intersect(basePl, compPl, com.esri.core.geometry.SpatialReference
                                                                                .create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.AreEqual(noException, 1);
            NUnit.Framework.Assert.IsTrue(intersectGeom.isEmpty());
        }
 public virtual void OffsetPolygon_(double distance, com.esri.core.geometry.OperatorOffset.JoinType
                                    joins)
 {
     com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon();
     polygon.startPath(0, 0);
     polygon.lineTo(0, 16);
     polygon.lineTo(16, 16);
     polygon.lineTo(16, 11);
     polygon.lineTo(10, 10);
     polygon.lineTo(10, 12);
     polygon.lineTo(3, 12);
     polygon.lineTo(3, 4);
     polygon.lineTo(10, 4);
     polygon.lineTo(10, 6);
     polygon.lineTo(16, 5);
     polygon.lineTo(16, 0);
     com.esri.core.geometry.OperatorOffset offset = (com.esri.core.geometry.OperatorOffset
                                                     )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                            .Offset);
     com.esri.core.geometry.Geometry outputGeom = offset.execute(polygon, null, distance
                                                                 , joins, 2, 0, null);
     NUnit.Framework.Assert.IsNotNull(outputGeom);
     if (distance > 2)
     {
         NUnit.Framework.Assert.IsTrue(outputGeom.isEmpty());
     }
 }
        public virtual void testBufferPoint()
        {
            com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                         .create(4326);
            com.esri.core.geometry.Point inputGeom = new com.esri.core.geometry.Point(12, 120
                                                                                      );
            com.esri.core.geometry.OperatorBuffer buffer = (com.esri.core.geometry.OperatorBuffer
                                                            )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                   .Buffer);
            com.esri.core.geometry.OperatorSimplify simplify = (com.esri.core.geometry.OperatorSimplify
                                                                )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                       .Simplify);
            com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 40.0, null
                                                                    );
            NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                          .Polygon);
            com.esri.core.geometry.Polygon poly = (com.esri.core.geometry.Polygon)result;
            int pathCount = poly.getPathCount();

            NUnit.Framework.Assert.IsTrue(pathCount == 1);
            int pointCount = poly.getPointCount();

            NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 100.0) < 10);
            com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D();
            result.queryEnvelope2D(env2D);
            NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - 80) < 0.01 && System.Math
                                          .abs(env2D.getHeight() - 80) < 0.01);
            NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 12) < 0.001 &&
                                          System.Math.abs(env2D.getCenterY() - 120) < 0.001);
            com.esri.core.geometry.NonSimpleResult nsr = new com.esri.core.geometry.NonSimpleResult
                                                             ();
            bool is_simple = simplify.isSimpleAsFeature(result, sr, true, nsr, null);

            NUnit.Framework.Assert.IsTrue(is_simple);
            {
                result = buffer.execute(inputGeom, sr, 0, null);
                NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                              .Polygon);
                NUnit.Framework.Assert.IsTrue(result.isEmpty());
            }
            {
                result = buffer.execute(inputGeom, sr, -1, null);
                NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                              .Polygon);
                NUnit.Framework.Assert.IsTrue(result.isEmpty());
            }
        }
Example #4
0
        public virtual void testPointAndPolygon2()
        {
            com.esri.core.geometry.Point   basePl = new com.esri.core.geometry.Point(-115, 20);
            com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon();
            compPl.startPath(new com.esri.core.geometry.Point(-116, 20));
            compPl.lineTo(new com.esri.core.geometry.Point(-131, 10));
            compPl.lineTo(new com.esri.core.geometry.Point(-121, 50));
            int noException = 1;

            // no exception
            com.esri.core.geometry.Geometry intersectGeom = null;
            try
            {
                intersectGeom = com.esri.core.geometry.GeometryEngine.intersect(basePl, compPl, com.esri.core.geometry.SpatialReference
                                                                                .create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.AreEqual(noException, 1);
            NUnit.Framework.Assert.IsTrue(intersectGeom.isEmpty());
        }
Example #5
0
        public virtual void testWKB2()
        {
            // JSON -> GEOM -> WKB
            // String strPolygon1 =
            // "{\"xmin\":-1.16605115291E7,\"ymin\":4925189.941699997,\"xmax\":-1.16567772126E7,\"ymax\":4928658.771399997,\"spatialReference\":{\"wkid\":102100}}";
            string strPolygon1 = "{\"rings\" : [ [ [-1.16605115291E7,4925189.941699997], [-1.16567772126E7,4925189.941699997], [-1.16567772126E7,4928658.771399997], [-1.16605115291E7,4928658.771399997], [-1.16605115291E7,4925189.941699997] ] ], \"spatialReference\" : {\"wkid\" : 102100}}";

            org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory();
            org.codehaus.jackson.JsonParser  parser  = factory.createJsonParser(strPolygon1);
            parser.nextToken();
            com.esri.core.geometry.MapGeometry mapGeom = com.esri.core.geometry.GeometryEngine
                                                         .jsonToGeometry(parser);
            com.esri.core.geometry.Geometry geom = mapGeom.getGeometry();
            // simplifying geom
            com.esri.core.geometry.OperatorSimplify operatorSimplify = (com.esri.core.geometry.OperatorSimplify
                                                                        )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                               .Simplify);
            com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                         .create(102100);
            geom = operatorSimplify.execute(geom, sr, true, null);
            com.esri.core.geometry.OperatorExportToWkb operatorExport = (com.esri.core.geometry.OperatorExportToWkb
                                                                         )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                                .ExportToWkb);
            java.nio.ByteBuffer byteBuffer = operatorExport.execute(0, geom, null);
            byte[] wkb = ((byte[])byteBuffer.array());
            // // checking WKB correctness
            // WKBReader jtsReader = new WKBReader();
            // com.vividsolutions.jts.geom.Geometry jtsGeom = jtsReader.read(wkb);
            // System.out.println("jtsGeom = " + jtsGeom);
            // WKB -> GEOM -> JSON
            com.esri.core.geometry.OperatorImportFromWkb operatorImport = (com.esri.core.geometry.OperatorImportFromWkb
                                                                           )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                                  .ImportFromWkb);
            geom = operatorImport.execute(0, com.esri.core.geometry.Geometry.Type.Polygon, java.nio.ByteBuffer
                                          .wrap(wkb), null);
            NUnit.Framework.Assert.IsTrue(!geom.isEmpty());
        }
 public virtual void testBufferPolyline()
 {
     com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                  .create(4326);
     com.esri.core.geometry.Polyline       inputGeom = new com.esri.core.geometry.Polyline();
     com.esri.core.geometry.OperatorBuffer buffer    = (com.esri.core.geometry.OperatorBuffer
                                                        )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                               .Buffer);
     com.esri.core.geometry.OperatorSimplify simplify = (com.esri.core.geometry.OperatorSimplify
                                                         )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                .Simplify);
     inputGeom.startPath(0, 0);
     inputGeom.lineTo(50, 50);
     inputGeom.lineTo(50, 0);
     inputGeom.lineTo(0, 50);
     {
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 0, null);
         NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                       .Polygon);
         NUnit.Framework.Assert.IsTrue(result.isEmpty());
     }
     {
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, -1, null);
         NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                       .Polygon);
         NUnit.Framework.Assert.IsTrue(result.isEmpty());
     }
     {
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 40.0, null
                                                                 );
         NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                       .Polygon);
         com.esri.core.geometry.Polygon    poly  = (com.esri.core.geometry.Polygon)(result);
         com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D();
         result.queryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - 80 - 50) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() - 80 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 25) < 0.1 && System.Math
                                       .abs(env2D.getCenterY() - 25) < 0.1);
         int pathCount = poly.getPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 1);
         int pointCount = poly.getPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 171.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
     {
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                       .Polygon);
         com.esri.core.geometry.Polygon    poly  = (com.esri.core.geometry.Polygon)(result);
         com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D();
         result.queryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - 8 - 50) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() - 8 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 25) < 0.1 && System.Math
                                       .abs(env2D.getCenterY() - 25) < 0.1);
         int pathCount = poly.getPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 2);
         int pointCount = poly.getPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 186.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
     {
         inputGeom = new com.esri.core.geometry.Polyline();
         inputGeom.startPath(0, 0);
         inputGeom.lineTo(50, 50);
         inputGeom.startPath(50, 0);
         inputGeom.lineTo(0, 50);
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType
                                       .Polygon);
         com.esri.core.geometry.Polygon    poly  = (com.esri.core.geometry.Polygon)(result);
         com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D();
         result.queryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - 8 - 50) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() - 8 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 25) < 0.1 && System.Math
                                       .abs(env2D.getCenterY() - 25) < 0.1);
         int pathCount = poly.getPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 1);
         int pointCount = poly.getPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 208.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
 }