Пример #1
0
 public virtual void TestBufferPolyline()
 {
     com.epl.geometry.SpatialReference sr        = com.epl.geometry.SpatialReference.Create(4326);
     com.epl.geometry.Polyline         inputGeom = new com.epl.geometry.Polyline();
     com.epl.geometry.OperatorBuffer   buffer    = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer);
     com.epl.geometry.OperatorSimplify simplify  = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify);
     inputGeom.StartPath(0, 0);
     inputGeom.LineTo(50, 50);
     inputGeom.LineTo(50, 0);
     inputGeom.LineTo(0, 50);
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         NUnit.Framework.Assert.IsTrue(result.IsEmpty());
     }
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -1, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         NUnit.Framework.Assert.IsTrue(result.IsEmpty());
     }
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.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.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.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.epl.geometry.Polyline();
         inputGeom.StartPath(0, 0);
         inputGeom.LineTo(50, 50);
         inputGeom.StartPath(50, 0);
         inputGeom.LineTo(0, 50);
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.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));
     }
     {
         inputGeom = new com.epl.geometry.Polyline();
         inputGeom.StartPath(1.762614, 0.607368);
         inputGeom.LineTo(1.762414, 0.606655);
         inputGeom.LineTo(1.763006, 0.607034);
         inputGeom.LineTo(1.762548, 0.607135);
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0.005, null);
         NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, 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);
        }
Пример #3
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);
            }
        }
Пример #4
0
 private static void ShowProjectedGeometryInfo(com.epl.geometry.MapGeometry mapGeom)
 {
     System.Console.Out.WriteLine("\n");
     com.epl.geometry.MapGeometry geom = mapGeom;
     // while ((geom = geomCursor.next()) != null) {
     if (geom.GetGeometry() is com.epl.geometry.Point)
     {
         com.epl.geometry.Point pnt = (com.epl.geometry.Point)geom.GetGeometry();
         System.Console.Out.WriteLine("Point(" + pnt.GetX() + " , " + pnt.GetY() + ")");
         if (geom.GetSpatialReference() == null)
         {
             System.Console.Out.WriteLine("No spatial reference");
         }
         else
         {
             System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID());
         }
     }
     else
     {
         if (geom.GetGeometry() is com.epl.geometry.MultiPoint)
         {
             com.epl.geometry.MultiPoint mp = (com.epl.geometry.MultiPoint)geom.GetGeometry();
             System.Console.Out.WriteLine("Multipoint has " + mp.GetPointCount() + " points.");
             System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID());
         }
         else
         {
             if (geom.GetGeometry() is com.epl.geometry.Polygon)
             {
                 com.epl.geometry.Polygon mp = (com.epl.geometry.Polygon)geom.GetGeometry();
                 System.Console.Out.WriteLine("Polygon has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts.");
                 if (mp.GetPathCount() > 1)
                 {
                     System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1));
                     System.Console.Out.WriteLine("Part end of 2nd segment   : " + mp.GetPathEnd(1));
                     System.Console.Out.WriteLine("Part size of 2nd segment  : " + mp.GetPathSize(1));
                     int start = mp.GetPathStart(1);
                     int end   = mp.GetPathEnd(1);
                     for (int i = start; i < end; i++)
                     {
                         com.epl.geometry.Point pp = mp.GetPoint(i);
                         System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")");
                     }
                 }
                 System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID());
             }
             else
             {
                 if (geom.GetGeometry() is com.epl.geometry.Polyline)
                 {
                     com.epl.geometry.Polyline mp = (com.epl.geometry.Polyline)geom.GetGeometry();
                     System.Console.Out.WriteLine("Polyline has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts.");
                     System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1));
                     System.Console.Out.WriteLine("Part end of 2nd segment   : " + mp.GetPathEnd(1));
                     System.Console.Out.WriteLine("Part size of 2nd segment  : " + mp.GetPathSize(1));
                     int start = mp.GetPathStart(1);
                     int end   = mp.GetPathEnd(1);
                     for (int i = start; i < end; i++)
                     {
                         com.epl.geometry.Point pp = mp.GetPoint(i);
                         System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")");
                     }
                     System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID());
                 }
             }
         }
     }
 }