public static void Test1() { com.esri.core.geometry.Polyline polyline; polyline = MakePolyline(); com.esri.core.geometry.MultiPathImpl polylineImpl = (com.esri.core.geometry.MultiPathImpl)polyline._getImpl(); com.esri.core.geometry.QuadTree quadtree = BuildQuadTree_(polylineImpl); com.esri.core.geometry.Line queryline = new com.esri.core.geometry.Line(34, 9, 66, 46); com.esri.core.geometry.QuadTree.QuadTreeIterator qtIter = quadtree.GetIterator(); NUnit.Framework.Assert.IsTrue(qtIter.Next() == -1); qtIter.ResetIterator(queryline, 0.0); int element_handle = qtIter.Next(); while (element_handle > 0) { int index = quadtree.GetElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.Next(); } com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D(34, 9, 66, 46); com.esri.core.geometry.Polygon queryPolygon = new com.esri.core.geometry.Polygon(); queryPolygon.AddEnvelope(envelope, true); qtIter.ResetIterator(queryline, 0.0); element_handle = qtIter.Next(); while (element_handle > 0) { int index = quadtree.GetElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.Next(); } }
public virtual void TestCreation1() { // Simple area and length calcul test com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); int number = poly.GetStateFlag(); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(1000, 2000, 1010, 2010); env.ToString(); poly.AddEnvelope(env, false); poly.ToString(); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() - 100) < 1e-12); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateLength2D() - 40) < 1e-12); poly.SetEmpty(); number = poly.GetStateFlag(); poly.AddEnvelope(env, true); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() + 100) < 1e-12); number = poly.GetStateFlag(); }
public virtual void TestIntersection1() { // OperatorFactoryLocal projEnv = OperatorFactoryLocal.getInstance(); // int codeIn = 26910;//NAD_1983_UTM_Zone_10N : GCS 6269 // int codeOut = 32610;//WGS_1984_UTM_Zone_10N; : GCS 4326 // int codeIn = SpatialReference::PCS_WGS_1984_UTM_10N; // int codeOut = SpatialReference::PCS_WORLD_MOLLWEIDE; // int codeOut = 102100; inputSR = com.esri.core.geometry.SpatialReference.Create(codeIn); NUnit.Framework.Assert.IsTrue(inputSR.GetID() == codeIn); outputSR = com.esri.core.geometry.SpatialReference.Create(codeOut); NUnit.Framework.Assert.IsTrue(outputSR.GetID() == codeOut); com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(855277, 3892059, 855277 + 100, 3892059 + 100); // Envelope env1 = new Envelope(-1000000, -1000000, 1000000, 1000000); // env1.SetCoords(-8552770, -3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(855277 + 1, 3892059 + 1, 855277 + 30, 3892059 + 20); poly2.AddEnvelope(env2, false); com.esri.core.geometry.GeometryCursor cursor1 = new com.esri.core.geometry.SimpleGeometryCursor(poly1); com.esri.core.geometry.GeometryCursor cursor2 = new com.esri.core.geometry.SimpleGeometryCursor(poly2); com.esri.core.geometry.GeometryCursor outputGeoms = operatorIntersection.Execute(cursor1, cursor2, inputSR, null); com.esri.core.geometry.Geometry geomr = outputGeoms.Next(); NUnit.Framework.Assert.IsNotNull(geomr); NUnit.Framework.Assert.IsTrue(geomr.GetType() == com.esri.core.geometry.Geometry.Type.Polygon); com.esri.core.geometry.Polygon geom = (com.esri.core.geometry.Polygon)geomr; NUnit.Framework.Assert.IsTrue(geom.GetPointCount() == 4); // com.esri.core.geometry.Point[] points = com.esri.core.geometry.TestCommonMethods.PointsFromMultiPath(geom); // // SPtrOfArrayOf(Point2D) // // pts = // // geom.get.getCoordinates2D(); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetX() - 855278.000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetY() - 3892060.0000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetX() - 855307.00000000093) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetY() - 3892079.0000000000) < 1e-7); // geomr = operatorIntersection.Execute(poly1, poly2, inputSR, null); // NUnit.Framework.Assert.IsNotNull(geomr); // NUnit.Framework.Assert.IsTrue(geomr.GetType() == com.esri.core.geometry.Geometry.Type.Polygon); // com.esri.core.geometry.Polygon outputGeom = (com.esri.core.geometry.Polygon)geomr; // NUnit.Framework.Assert.IsTrue(outputGeom.GetPointCount() == 4); // points = com.esri.core.geometry.TestCommonMethods.PointsFromMultiPath(outputGeom); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetX() - 855278.000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetY() - 3892060.0000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetX() - 855307.00000000093) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetY() - 3892079.0000000000) < 1e-7); }
public virtual void TestDisjointCrash() { com.esri.core.geometry.Polygon g1 = new com.esri.core.geometry.Polygon(); g1.AddEnvelope(com.esri.core.geometry.Envelope2D.Construct(0, 0, 10, 10), false); com.esri.core.geometry.Polygon g2 = new com.esri.core.geometry.Polygon(); g2.AddEnvelope(com.esri.core.geometry.Envelope2D.Construct(10, 1, 21, 21), false); g1 = (com.esri.core.geometry.Polygon)com.esri.core.geometry.OperatorDensifyByLength.Local().Execute(g1, 0.1, null); com.esri.core.geometry.OperatorDisjoint.Local().AccelerateGeometry(g1, com.esri.core.geometry.SpatialReference.Create(4267), com.esri.core.geometry.Geometry.GeometryAccelerationDegree.enumHot); bool res = com.esri.core.geometry.OperatorDisjoint.Local().Execute(g1, g2, com.esri.core.geometry.SpatialReference.Create(4267), null); NUnit.Framework.Assert.IsTrue(!res); }
public virtual void TestCreation() { { com.esri.core.geometry.OperatorFactoryLocal projEnv = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.SpatialReference inputSR = com.esri.core.geometry.SpatialReference.Create(3857); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(); env1.SetCoords(855277, 3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env2 = new com.esri.core.geometry.Envelope2D(); env2.SetCoords(855277, 3892059, 855277 + 300, 3892059 + 200); poly2.AddEnvelope(env2, false); { com.esri.core.geometry.OperatorEquals operatorEquals = (com.esri.core.geometry.OperatorEquals)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Equals)); bool result = operatorEquals.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); com.esri.core.geometry.Polygon poly11 = new com.esri.core.geometry.Polygon(); poly1.CopyTo(poly11); result = operatorEquals.Execute(poly1, poly11, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorCrosses operatorCrosses = (com.esri.core.geometry.OperatorCrosses)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Crosses)); bool result = operatorCrosses.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); } { com.esri.core.geometry.OperatorWithin operatorWithin = (com.esri.core.geometry.OperatorWithin)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Within)); bool result = operatorWithin.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); bool result = operatorDisjoint.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); poly2.QueryEnvelope2D(env2D); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env2D); bool result = operatorDisjoint.Execute(envelope, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(envelope, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); env2D.SetCoords(855277, 3892059, 855277 + 100, 3892059 + 100); poly.AddEnvelope(env2D, false); env2D.SetCoords(855277 + 10, 3892059 + 10, 855277 + 90, 3892059 + 90); poly.AddEnvelope(env2D, true); env2D.SetCoords(855277 + 20, 3892059 + 20, 855277 + 200, 3892059 + 80); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env2D); bool result = operatorDisjoint.Execute(envelope, poly, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(envelope, poly, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorTouches operatorTouches = (com.esri.core.geometry.OperatorTouches)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Touches)); bool result = operatorTouches.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); } } }
public virtual void TestOperatorDisjoint() { { com.esri.core.geometry.OperatorFactoryLocal projEnv = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.SpatialReference inputSR = com.esri.core.geometry.SpatialReference.Create(3857); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(); env1.SetCoords(855277, 3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env2 = new com.esri.core.geometry.Envelope2D(); env2.SetCoords(855277, 3892059, 855277 + 300, 3892059 + 200); poly2.AddEnvelope(env2, false); com.esri.core.geometry.Polygon poly3 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env3 = new com.esri.core.geometry.Envelope2D(); env3.SetCoords(855277 + 100, 3892059 + 100, 855277 + 100 + 100, 3892059 + 100 + 100); poly3.AddEnvelope(env3, false); com.esri.core.geometry.Polygon poly4 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env4 = new com.esri.core.geometry.Envelope2D(); env4.SetCoords(855277 + 200, 3892059 + 200, 855277 + 200 + 100, 3892059 + 200 + 100); poly4.AddEnvelope(env4, false); com.esri.core.geometry.Point point1 = new com.esri.core.geometry.Point(855277, 3892059); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(855277 + 2, 3892059 + 3); com.esri.core.geometry.Point point3 = new com.esri.core.geometry.Point(855277 - 2, 3892059 - 3); { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); bool result = operatorDisjoint.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(poly1, poly3, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(poly1, poly4, inputSR, null); NUnit.Framework.Assert.IsTrue(result); result = operatorDisjoint.Execute(poly1, point1, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(point1, poly1, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(poly1, point2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(point2, poly1, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); result = operatorDisjoint.Execute(poly1, point3, inputSR, null); NUnit.Framework.Assert.IsTrue(result); result = operatorDisjoint.Execute(point3, poly1, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } }
public virtual void Test0Poly() { // simple com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); poly1.AddEnvelope(new com.esri.core.geometry.Envelope(10, 10, 40, 20), false); poly1.AddEnvelope(new com.esri.core.geometry.Envelope(50, 10, 100, 20), false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)simplifyOp.Execute(poly1, null, false, null); bool res = simplifyOp.IsSimpleAsFeature(poly2, null, true, null, null); NUnit.Framework.Assert.IsTrue(res); }
public virtual void TestIsSimplePolygonRectangleOneBelow() { // Two rectangles one below another, simple com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.AddEnvelope(new com.esri.core.geometry.Envelope(50, 50, 100, 100), false); poly.AddEnvelope(new com.esri.core.geometry.Envelope(50, 200, 100, 250), false); bool result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(result); poly.ReverseAllPaths(); result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); }
public virtual void TestIsSimplePolygon_2RectanglesSideBySide() { // Two rectangles side by side, simple com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.AddEnvelope(new com.esri.core.geometry.Envelope(-200, -100, 200, 100), false); poly.AddEnvelope(new com.esri.core.geometry.Envelope(220, -50, 300, 50), false); bool result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(result); poly.ReverseAllPaths(); result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); }
public static void TestClipOfCoinciding() { 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 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D envelopeCR = new com.esri.core.geometry.Envelope2D(); envelopeCR.xmin = -180; envelopeCR.xmax = 180; envelopeCR.ymin = -90; envelopeCR.ymax = 90; polygon.AddEnvelope(envelopeCR, false); com.esri.core.geometry.SpatialReference gcsWGS84 = com.esri.core.geometry.SpatialReference.Create(4326); // CR com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 4); com.esri.core.geometry.OperatorDensifyByLength densifyOp = (com.esri.core.geometry.OperatorDensifyByLength)engine.GetOperator(com.esri.core.geometry.Operator.Type.DensifyByLength); polygon.SetEmpty(); polygon.AddEnvelope(envelopeCR, false); polygon = (com.esri.core.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.esri.core.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); }
public virtual void TestIsSimplePolygonRectangleHole() { // Rectangle and rectangular hole that has one segment overlapping // with the with the exterior ring. Cracking is needed. com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.AddEnvelope(new com.esri.core.geometry.Envelope(-200, -100, 200, 100), false); poly.AddEnvelope(new com.esri.core.geometry.Envelope(-100, -100, 100, 50), true); bool result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); poly.ReverseAllPaths(); result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); }
public virtual void TestSelfIntersecting() { // Test that we do not fail if there is // self-intersection // OperatorFactoryLocal projEnv = // OperatorFactoryLocal.getInstance(); com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(); env1.SetCoords(0, 0, 20, 30); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); poly2.StartPath(0, 0); poly2.LineTo(10, 10); poly2.LineTo(0, 10); poly2.LineTo(10, 0); com.esri.core.geometry.Polygon res = (com.esri.core.geometry.Polygon)(operatorIntersection.Execute(poly1, poly2, sr, null)); }
public virtual void TestMultipoint() { com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(855277, 3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.MultiPoint multiPoint = new com.esri.core.geometry.MultiPoint(); multiPoint.Add(855277 + 10, 3892059 + 10); multiPoint.Add(855277, 3892059); multiPoint.Add(855277 + 100, 3892059 + 100); multiPoint.Add(855277 + 100, 3892059 + 101); multiPoint.Add(855277 + 101, 3892059 + 100); multiPoint.Add(855277 + 101, 3892059 + 101); com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.MultiPoint mpResult = (com.esri.core.geometry.MultiPoint)operatorIntersection.Execute(poly1, multiPoint, inputSR, null); NUnit.Framework.Assert.IsTrue(mpResult.GetPointCount() == 3); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(0).GetX() == 855277 + 10 && mpResult.GetPoint(0).GetY() == 3892059 + 10); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(1).GetX() == 855277 && mpResult.GetPoint(1).GetY() == 3892059); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(2).GetX() == 855277 + 100 && mpResult.GetPoint(2).GetY() == 3892059 + 100); // Test intersection of Polygon with Envelope (calls Clip) com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(10, 10); poly.LineTo(20, 0); env1.SetXMin(0); env1.SetXMax(20); env1.SetYMin(5); env1.SetYMax(15); com.esri.core.geometry.Envelope envelope1 = env1; com.esri.core.geometry.Polygon clippedPoly = (com.esri.core.geometry.Polygon)operatorIntersection.Execute(poly, envelope1, inputSR, null); double area = clippedPoly.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Geometry res = GeometryEngine.difference(poly, envelope1, inputSR); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(855277 + 1, 3892059 + 1, 855277 + 30, 3892059 + 20); env2.SetXMin(5); env2.SetXMax(10); env2.SetYMin(0); env2.SetYMax(20); com.esri.core.geometry.Envelope envelope2 = env2; com.esri.core.geometry.Envelope clippedEnvelope = (com.esri.core.geometry.Envelope)operatorIntersection.Execute(envelope1, envelope2, inputSR, null); area = clippedEnvelope.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 50) < 0.00001); }
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); } }
public virtual void TestIsSimplePolygonRectangleHoleWrongDirection() { // Rectangle and rectangular hole that has wrong direction com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.AddEnvelope(new com.esri.core.geometry.Envelope(-200, -100, 200, 100), false); poly.AddEnvelope(new com.esri.core.geometry.Envelope(-100, -50, 100, 50), false); bool result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); poly.ReverseAllPaths(); result = simplifyOp.IsSimpleAsFeature(poly, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); }
public virtual void TestProximity2D_2() { com.esri.core.geometry.Point point1 = new com.esri.core.geometry.Point(3, 2); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(2, 4); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); envelope.SetCoords(4, 3, 7, 6); com.esri.core.geometry.Polygon polygonToTest = new com.esri.core.geometry.Polygon(); polygonToTest.AddEnvelope(envelope, false); com.esri.core.geometry.Proximity2DResult prxResult1 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(envelope, point1); com.esri.core.geometry.Proximity2DResult prxResult2 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(polygonToTest, point1); com.esri.core.geometry.Proximity2DResult prxResult3 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(envelope, point2, false); com.esri.core.geometry.Proximity2DResult prxResult4 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(polygonToTest, point2, false); com.esri.core.geometry.Point result1 = prxResult1.GetCoordinate(); com.esri.core.geometry.Point result2 = prxResult2.GetCoordinate(); NUnit.Framework.Assert.IsTrue(result1.GetX() == result2.GetX()); com.esri.core.geometry.Point result3 = prxResult3.GetCoordinate(); com.esri.core.geometry.Point result4 = prxResult4.GetCoordinate(); NUnit.Framework.Assert.IsTrue(result3.GetX() == result4.GetX()); }
public static void TestArcObjectsFailureCR196492() { 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 = new com.esri.core.geometry.Polygon(); polygon.AddEnvelope(new com.esri.core.geometry.Envelope2D(0, 0, 600, 600), false); polygon.StartPath(30, 300); polygon.LineTo(20, 310); polygon.LineTo(10, 300); com.esri.core.geometry.SpatialReference gcsWGS84 = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Envelope2D envelopeCR = new com.esri.core.geometry.Envelope2D(10, 10, 500, 500); com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 7); }