예제 #1
0
        public virtual void testMultiPointAndMultiPoint2()
        {
            com.esri.core.geometry.MultiPoint basePl = new com.esri.core.geometry.MultiPoint(
                );
            basePl.add(new com.esri.core.geometry.Point(-116, 20));
            basePl.add(new com.esri.core.geometry.Point(-118, 21));
            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(-118, 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.IsNotNull(intersectGeom);
            NUnit.Framework.Assert.IsTrue(intersectGeom.getType() == com.esri.core.geometry.Geometry.Type
                                          .MultiPoint);
            com.esri.core.geometry.MultiPoint ip = (com.esri.core.geometry.MultiPoint)intersectGeom;
            NUnit.Framework.Assert.AreEqual(-116, 0.1E7, ip.getPoint(0).getX());
            NUnit.Framework.Assert.AreEqual(20, 0.1E7, ip.getPoint(0).getY());
            NUnit.Framework.Assert.AreEqual(-118, 0.1E7, ip.getPoint(0).getX());
            NUnit.Framework.Assert.AreEqual(21, 0.1E7, ip.getPoint(0).getY());
        }
예제 #2
0
        public virtual void testPointAndPolyline1()
        {
            com.esri.core.geometry.Point    basePl = new com.esri.core.geometry.Point(-116, 20);
            com.esri.core.geometry.Polyline compPl = new com.esri.core.geometry.Polyline();
            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.IsNotNull(intersectGeom);
            NUnit.Framework.Assert.IsTrue(intersectGeom.getType() == com.esri.core.geometry.Geometry.Type
                                          .Point);
            com.esri.core.geometry.Point ip = (com.esri.core.geometry.Point)intersectGeom;
            NUnit.Framework.Assert.AreEqual(-116, 0.1E7, ip.getX());
            NUnit.Framework.Assert.AreEqual(20, 0.1E7, ip.getY());
        }
예제 #3
0
        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());
            }
        }
예제 #4
0
 public virtual void testBufferPolygon()
 {
     com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                  .create(4326);
     com.esri.core.geometry.Polygon        inputGeom = new com.esri.core.geometry.Polygon();
     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);
     {
         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 == inputGeom);
     }
     {
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 10, 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() - 20 - 50) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() - 20 - 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 - 104.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
     {
         sr        = com.esri.core.geometry.SpatialReference.create(4326);
         inputGeom = new com.esri.core.geometry.Polygon();
         inputGeom.startPath(0, 0);
         inputGeom.lineTo(50, 50);
         inputGeom.lineTo(50, 0);
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, -10, 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() - 15.85) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() - 15.85) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 32.07) < 0.1 &&
                                       System.Math.abs(env2D.getCenterY() - 17.93) < 0.1);
         int pathCount = poly.getPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 1);
         int pointCount = poly.getPointCount();
         NUnit.Framework.Assert.IsTrue(pointCount == 3);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
     {
         sr        = com.esri.core.geometry.SpatialReference.create(4326);
         inputGeom = new com.esri.core.geometry.Polygon();
         inputGeom.startPath(0, 0);
         inputGeom.lineTo(0, 50);
         inputGeom.lineTo(50, 50);
         inputGeom.lineTo(50, 0);
         inputGeom.startPath(10, 10);
         inputGeom.lineTo(40, 10);
         inputGeom.lineTo(40, 40);
         inputGeom.lineTo(10, 40);
         com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, -2, 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() + 4 - 50) < 0.1 &&
                                       System.Math.abs(env2D.getHeight() + 4 - 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 - 108) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null));
     }
 }
 public virtual void testMP2onCR175871()
 {
     com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon();
     pg.startPath(-50, 10);
     pg.lineTo(-50, 12);
     pg.lineTo(-45, 12);
     pg.lineTo(-45, 10);
     com.esri.core.geometry.Polygon pg1 = new com.esri.core.geometry.Polygon();
     pg1.startPath(-45, 10);
     pg1.lineTo(-40, 10);
     pg1.lineTo(-40, 8);
     pg.add(pg1, false);
     try
     {
         string jSonStr = com.esri.core.geometry.GeometryEngine.geometryToJson(4326, pg);
         org.codehaus.jackson.JsonFactory jf = new org.codehaus.jackson.JsonFactory();
         org.codehaus.jackson.JsonParser  jp = jf.createJsonParser(jSonStr);
         jp.nextToken();
         com.esri.core.geometry.MapGeometry mg = com.esri.core.geometry.GeometryEngine.jsonToGeometry
                                                     (jp);
         com.esri.core.geometry.Geometry gm = mg.getGeometry();
         NUnit.Framework.Assert.AreEqual(com.esri.core.geometry.Geometry.Type.Polygon, gm.
                                         getType());
         com.esri.core.geometry.Polygon pgNew = (com.esri.core.geometry.Polygon)gm;
         NUnit.Framework.Assert.AreEqual(pgNew.getPathCount(), pg.getPathCount());
         NUnit.Framework.Assert.AreEqual(pgNew.getPointCount(), pg.getPointCount());
         NUnit.Framework.Assert.AreEqual(pgNew.getSegmentCount(), pg.getSegmentCount());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(0).getX(), 0.000000001, pgNew.getPoint
                                             (0).getX());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getX(), 0.000000001, pgNew.getPoint
                                             (1).getX());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getX(), 0.000000001, pgNew.getPoint
                                             (2).getX());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getX(), 0.000000001, pgNew.getPoint
                                             (3).getX());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(0).getY(), 0.000000001, pgNew.getPoint
                                             (0).getY());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getY(), 0.000000001, pgNew.getPoint
                                             (1).getY());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getY(), 0.000000001, pgNew.getPoint
                                             (2).getY());
         NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getY(), 0.000000001, pgNew.getPoint
                                             (3).getY());
     }
     catch (System.Exception ex)
     {
         string err = ex.Message;
         System.Console.Out.Write(err);
         throw;
     }
 }