public static com.esri.core.geometry.Envelope MakeEnvelope3() { com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(5, 5, 6, 6); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env); return envelope; }
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); } } }
internal static com.esri.core.geometry.QuadTree BuildQuadTree_(com.esri.core.geometry.MultiPointImpl multipointImpl) { com.esri.core.geometry.Envelope2D extent = new com.esri.core.geometry.Envelope2D(); multipointImpl.QueryEnvelope2D(extent); com.esri.core.geometry.QuadTree quadTree = new com.esri.core.geometry.QuadTree(extent, 8); com.esri.core.geometry.Envelope2D boundingbox = new com.esri.core.geometry.Envelope2D(); com.esri.core.geometry.Point2D pt; for (int i = 0; i < multipointImpl.GetPointCount(); i++) { pt = multipointImpl.GetXY(i); boundingbox.SetCoords(pt.x, pt.y, pt.x, pt.y); quadTree.Insert(i, boundingbox, -1); } return quadTree; }
public static void TestEnvelope2Dintersector() { System.Collections.Generic.List<com.esri.core.geometry.Envelope2D> envelopes = new System.Collections.Generic.List<com.esri.core.geometry.Envelope2D>(0); com.esri.core.geometry.Envelope2D env0 = new com.esri.core.geometry.Envelope2D(2, 3, 4, 4); com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(5, 13, 9, 15); com.esri.core.geometry.Envelope2D env2 = new com.esri.core.geometry.Envelope2D(6, 9, 11, 12); com.esri.core.geometry.Envelope2D env3 = new com.esri.core.geometry.Envelope2D(8, 10, 9, 17); com.esri.core.geometry.Envelope2D env4 = new com.esri.core.geometry.Envelope2D(11.001, 12, 14, 14); com.esri.core.geometry.Envelope2D env5 = new com.esri.core.geometry.Envelope2D(1, 3, 3, 4); com.esri.core.geometry.Envelope2D env6 = new com.esri.core.geometry.Envelope2D(0, 2, 5, 10); com.esri.core.geometry.Envelope2D env7 = new com.esri.core.geometry.Envelope2D(4, 7, 5, 10); com.esri.core.geometry.Envelope2D env8 = new com.esri.core.geometry.Envelope2D(3, 15, 15, 15); com.esri.core.geometry.Envelope2D env9 = new com.esri.core.geometry.Envelope2D(0, 9, 14, 9); com.esri.core.geometry.Envelope2D env10 = new com.esri.core.geometry.Envelope2D(0, 8.999, 14, 8.999); envelopes.Add(env0); envelopes.Add(env1); envelopes.Add(env2); envelopes.Add(env3); envelopes.Add(env4); envelopes.Add(env5); envelopes.Add(env6); envelopes.Add(env7); envelopes.Add(env8); envelopes.Add(env9); envelopes.Add(env10); com.esri.core.geometry.Envelope2DIntersectorImpl intersector = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector.SetTolerance(0.001); intersector.StartConstruction(); for (int i = 0; i < envelopes.Count; i++) { intersector.AddEnvelope(i, envelopes[i]); } intersector.EndConstruction(); int count = 0; while (intersector.Next()) { int env_a = intersector.GetHandleA(); int env_b = intersector.GetHandleB(); count++; com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); env.Inflate(0.001, 0.001); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 16)); com.esri.core.geometry.Envelope2DIntersectorImpl intersector2 = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector2.SetTolerance(0.0); intersector2.StartConstruction(); for (int i_1 = 0; i_1 < envelopes.Count; i_1++) { intersector2.AddEnvelope(i_1, envelopes[i_1]); } intersector2.EndConstruction(); count = 0; while (intersector2.Next()) { int env_a = intersector2.GetHandleA(); int env_b = intersector2.GetHandleB(); count++; com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 13)); env0 = new com.esri.core.geometry.Envelope2D(0, 0, 0, 10); env1 = new com.esri.core.geometry.Envelope2D(0, 10, 10, 10); env2 = new com.esri.core.geometry.Envelope2D(10, 0, 10, 10); env3 = new com.esri.core.geometry.Envelope2D(0, 0, 10, 0); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env1); envelopes.Add(env2); envelopes.Add(env3); com.esri.core.geometry.Envelope2DIntersectorImpl intersector3 = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector3.SetTolerance(0.001); intersector3.StartConstruction(); for (int i_2 = 0; i_2 < envelopes.Count; i_2++) { intersector3.AddEnvelope(i_2, envelopes[i_2]); } intersector3.EndConstruction(); count = 0; while (intersector3.Next()) { int env_a = intersector3.GetHandleA(); int env_b = intersector3.GetHandleB(); count++; com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } NUnit.Framework.Assert.IsTrue(count == 4); env0 = new com.esri.core.geometry.Envelope2D(0, 0, 0, 10); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); com.esri.core.geometry.Envelope2DIntersectorImpl intersector4 = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector4.SetTolerance(0.001); intersector4.StartConstruction(); for (int i_3 = 0; i_3 < envelopes.Count; i_3++) { intersector4.AddEnvelope(i_3, envelopes[i_3]); } intersector4.EndConstruction(); count = 0; while (intersector4.Next()) { int env_a = intersector4.GetHandleA(); int env_b = intersector4.GetHandleB(); count++; com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 6)); env0 = new com.esri.core.geometry.Envelope2D(0, 10, 10, 10); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); com.esri.core.geometry.Envelope2DIntersectorImpl intersector5 = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector5.SetTolerance(0.001); intersector5.StartConstruction(); for (int i_4 = 0; i_4 < envelopes.Count; i_4++) { intersector5.AddEnvelope(i_4, envelopes[i_4]); } intersector5.EndConstruction(); count = 0; while (intersector5.Next()) { int env_a = intersector5.GetHandleA(); int env_b = intersector5.GetHandleB(); count++; com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } NUnit.Framework.Assert.IsTrue(count == 6); }
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 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 TestFromProjection() { com.esri.core.geometry.MultiPoint multiPointInitial = new com.esri.core.geometry.MultiPoint(); multiPointInitial.Add(-20037508.342789244, 3360107.7777777780); multiPointInitial.Add(-18924313.434856508, 3360107.7777777780); multiPointInitial.Add(-18924313.434856508, -3360107.7777777780); multiPointInitial.Add(-20037508.342789244, -3360107.7777777780); com.esri.core.geometry.Geometry geom1 = ((com.esri.core.geometry.MultiPoint)multiPointInitial); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(102100); com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(-20037508.342788246, -30240971.958386172, 20037508.342788246, 30240971.958386205); /* xmin */ /* ymin */ /* xmax */ /* ymax */ // /*xmin*/ -20037508.342788246 // /*ymin*/ -30240971.958386172 // /*xmax*/ 20037508.342788246 // /*ymax*/ 30240971.958386205 com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(env.xmin, env.ymin); poly.LineTo(env.xmin, env.ymax); poly.LineTo(env.xmax, env.ymax); poly.LineTo(env.xmax, env.ymin); com.esri.core.geometry.Geometry geom2 = new com.esri.core.geometry.Envelope(env); // Geometry geom2 = poly; com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.MultiPoint multiPointOut = (com.esri.core.geometry.MultiPoint)(operatorIntersection.Execute(geom1, geom2, sr, null)); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D().Length == 2); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[0].x == -18924313.434856508); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[0].y == 3360107.7777777780); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[1].x == -18924313.434856508); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[1].y == -3360107.7777777780); }
public static void TestClipIssue258243() { com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); poly1.StartPath(21.476191371901479, 41.267022001907215); poly1.LineTo(59.669186665158051, 36.62700518555863); poly1.LineTo(20.498578117352313, 30.363180148246094); poly1.LineTo(18.342565836615044, 46.303295352085627); poly1.LineTo(17.869569458621626, 23.886816966894159); poly1.LineTo(19.835465558090434, 20); poly1.LineTo(18.83911285048551, 43.515995498114791); poly1.LineTo(20.864485260298004, 20.235921201027757); poly1.LineTo(18.976127544787012, 20); poly1.LineTo(34.290201277718218, 61.801369014954794); poly1.LineTo(20.734727419368866, 20); poly1.LineTo(18.545865698148113, 20); poly1.LineTo(19.730260558565515, 20); poly1.LineTo(19.924806216827005, 23.780315893949187); poly1.LineTo(21.675168105421452, 36.699924873001258); poly1.LineTo(22.500527828912158, 43.703424859922983); poly1.LineTo(42.009527116514818, 36.995486982256089); poly1.LineTo(24.469729873835782, 58.365871758247039); poly1.LineTo(24.573736036545878, 36.268390409195824); poly1.LineTo(22.726502169802746, 20); poly1.LineTo(23.925834885228145, 20); poly1.LineTo(25.495346880936729, 20); poly1.LineTo(23.320941499288317, 20); poly1.LineTo(24.05655665646276, 28.659578774758632); poly1.LineTo(23.205940789341135, 38.491506888710504); poly1.LineTo(21.472847203385509, 53.057228182018044); poly1.LineTo(25.04257681654104, 20); poly1.LineTo(25.880572351149542, 25.16102863979474); poly1.LineTo(26.756283333879658, 20); poly1.LineTo(21.476191371901479, 41.267022001907215); com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793); try { com.esri.core.geometry.Geometry output_geom = com.esri.core.geometry.OperatorClip.Local().Execute(poly1, env, com.esri.core.geometry.SpatialReference.Create(4326), null); com.esri.core.geometry.Envelope envPoly = new com.esri.core.geometry.Envelope(); poly1.QueryEnvelope(envPoly); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(env); e.Intersect(envPoly); com.esri.core.geometry.Envelope clippedEnv = new com.esri.core.geometry.Envelope(); output_geom.QueryEnvelope(clippedEnv); NUnit.Framework.Assert.IsTrue(System.Math.Abs(clippedEnv.GetXMin() - e.GetXMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMin() - e.GetYMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetXMax() - e.GetXMax()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMax() - e.GetYMax()) < 1e-10); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue(false); } }
public static void TestClipAttributes() { 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.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(30, 30); polygon.LineTo(60, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 120); com.esri.core.geometry.Envelope2D clipper = new com.esri.core.geometry.Envelope2D(); clipper.SetCoords(10, 0, 50, 20); com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipOp.Execute(polygon, clipper, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0) == 100); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996); // 20.0 NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0) == 20); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0) == 40); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 4, 0) == 80); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 5, 0) == 100); } { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(0, 40); polygon.LineTo(20, 40); polygon.LineTo(20, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 120); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0, 180); com.esri.core.geometry.Envelope2D clipper = new com.esri.core.geometry.Envelope2D(); clipper.SetCoords(0, 10, 20, 20); com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipOp.Execute(polygon, clipper, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0) == 15); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0) == 30); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0) == 150); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0) == 165); } }
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); } }