Example #1
0
        public static void TestClipOfCoinciding()
        {
            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          = new com.epl.geometry.Polygon();
            com.epl.geometry.Envelope2D envelopeCR       = new com.epl.geometry.Envelope2D();
            envelopeCR.xmin = -180;
            envelopeCR.xmax = 180;
            envelopeCR.ymin = -90;
            envelopeCR.ymax = 90;
            polygon.AddEnvelope(envelopeCR, false);
            com.epl.geometry.SpatialReference gcsWGS84 = com.epl.geometry.SpatialReference.Create(4326);
            // CR
            com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null);
            NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPathCount() == 1);
            NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 4);
            com.epl.geometry.OperatorDensifyByLength densifyOp = (com.epl.geometry.OperatorDensifyByLength)engine.GetOperator(com.epl.geometry.Operator.Type.DensifyByLength);
            polygon.SetEmpty();
            polygon.AddEnvelope(envelopeCR, false);
            polygon = (com.epl.geometry.Polygon)densifyOp.Execute(polygon, 1, null);
            int pc    = polygon.GetPointCount();
            int pathc = polygon.GetPathCount();

            NUnit.Framework.Assert.IsTrue(pc == 1080);
            NUnit.Framework.Assert.IsTrue(pathc == 1);
            clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null);
            int _pathc = clippedPolygon.GetPathCount();
            int _pc    = clippedPolygon.GetPointCount();

            NUnit.Framework.Assert.IsTrue(_pathc == 1);
            NUnit.Framework.Assert.IsTrue(_pc == pc);
        }
Example #2
0
 public static void TestGetXCorrectCR185697()
 {
     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.Polyline             polylineCR     = MakePolylineCR();
     com.epl.geometry.SimpleGeometryCursor polylineCursCR = new com.epl.geometry.SimpleGeometryCursor(polylineCR);
     com.epl.geometry.SpatialReference     gcsWGS84       = com.epl.geometry.SpatialReference.Create(4326);
     com.epl.geometry.Envelope2D           envelopeCR     = new com.epl.geometry.Envelope2D();
     envelopeCR.xmin = -180;
     envelopeCR.xmax = 180;
     envelopeCR.ymin = -90;
     envelopeCR.ymax = 90;
     // CR
     com.epl.geometry.Polyline clippedPolylineCR = (com.epl.geometry.Polyline)clipOp.Execute(polylineCR, envelopeCR, gcsWGS84, null);
     com.epl.geometry.Point    pointResult       = new com.epl.geometry.Point();
     clippedPolylineCR.GetPointByVal(0, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == -180);
     clippedPolylineCR.GetPointByVal(1, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == -90);
     clippedPolylineCR.GetPointByVal(2, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 0);
     clippedPolylineCR.GetPointByVal(3, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 100);
     clippedPolylineCR.GetPointByVal(4, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 170);
     clippedPolylineCR.GetPointByVal(5, pointResult);
     NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 180);
 }
Example #3
0
 public static void TestArcObjectsFailureCR196492()
 {
     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             = new com.epl.geometry.Polygon();
     polygon.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 600, 600), false);
     polygon.StartPath(30, 300);
     polygon.LineTo(20, 310);
     polygon.LineTo(10, 300);
     com.epl.geometry.SpatialReference gcsWGS84       = com.epl.geometry.SpatialReference.Create(4326);
     com.epl.geometry.Envelope2D       envelopeCR     = new com.epl.geometry.Envelope2D(10, 10, 500, 500);
     com.epl.geometry.Polygon          clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null);
     NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 7);
 }
Example #4
0
 public static void TestClipAttributes()
 {
     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 = new com.epl.geometry.Polygon();
         polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
         polygon.StartPath(0, 0);
         polygon.LineTo(30, 30);
         polygon.LineTo(60, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120);
         com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D();
         clipper.SetCoords(10, 0, 50, 20);
         com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 100);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996);
         // 20.0
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 20);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 40);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 80);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 100);
     }
     {
         com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
         polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
         polygon.StartPath(0, 0);
         polygon.LineTo(0, 40);
         polygon.LineTo(20, 40);
         polygon.LineTo(20, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120);
         polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 180);
         com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D();
         clipper.SetCoords(0, 10, 20, 20);
         com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 15);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 30);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 150);
         NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 165);
     }
 }
Example #5
0
 /// <summary>Calculates the clipped geometry from a target geometry using an envelope.</summary>
 /// <remarks>
 /// Calculates the clipped geometry from a target geometry using an envelope.
 /// See OperatorClip.
 /// </remarks>
 /// <param name="geometry">The geometry to be clipped.</param>
 /// <param name="envelope">The envelope used to clip.</param>
 /// <param name="spatialReference">The spatial reference of the geometries.</param>
 /// <returns>The geometry created by clipping.</returns>
 public static com.epl.geometry.Geometry Clip(com.epl.geometry.Geometry geometry, com.epl.geometry.Envelope envelope, com.epl.geometry.SpatialReference spatialReference)
 {
     com.epl.geometry.OperatorClip op     = (com.epl.geometry.OperatorClip)factory.GetOperator(com.epl.geometry.Operator.Type.Clip);
     com.epl.geometry.Geometry     result = op.Execute(geometry, com.epl.geometry.Envelope2D.Construct(envelope.GetXMin(), envelope.GetYMin(), envelope.GetXMax(), envelope.GetYMax()), spatialReference, null);
     return(result);
 }
Example #6
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);
            }
        }