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 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 testBufferLine() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Line inputGeom = new com.esri.core.geometry.Line(12, 120, 20, 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); 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 - 8) < 0.001 && System.Math.abs(env2D.getHeight() - 80) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 16) < 0.001 && System.Math.abs(env2D.getCenterY() - 120) < 0.001); 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); NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null)); { 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()); } }
public virtual void testSerializeLine() { try { java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream oo = new java.io.ObjectOutputStream(streamOut); com.esri.core.geometry.Line pt = new com.esri.core.geometry.Line(); pt.setStart(new com.esri.core.geometry.Point(10, 30)); pt.setEnd(new com.esri.core.geometry.Point(120, 40)); oo.writeObject(pt); java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut .toByteArray()); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(streamIn); com.esri.core.geometry.Line ptRes = (com.esri.core.geometry.Line)ii.readObject(); NUnit.Framework.Assert.IsTrue(ptRes.equals(pt)); } catch (System.Exception ex) { // fail("Line serialization failure"); NUnit.Framework.Assert.AreEqual(ex.Message, "Cannot serialize this geometry"); } }
public virtual void TestBufferLine() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Line inputGeom = new com.esri.core.geometry.Line(12, 120, 20, 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); 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 - 8) < 0.001 && System.Math.Abs(env2D.GetHeight() - 80) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 16) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 120) < 0.001); 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); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); { 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()); } }
public virtual void testLine() { com.esri.core.geometry.Line env = new com.esri.core.geometry.Line(); env.setStartXY(100, 200); env.setEndXY(250, 300); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); env.setStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 1); env.setEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 2); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 0) == 1); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 0) == 2); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); env.setStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 3); env.setEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 4); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 4); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID)); env.setStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 5 ); env.setEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 6); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 0) == 1); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 0) == 2); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 4); env.dropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 4); com.esri.core.geometry.Line env1 = new com.esri.core.geometry.Line(); env.copyTo(env1); NUnit.Framework.Assert.IsFalse(env1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.getStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.getEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0) == 4); }
public virtual void TestIsSimpleBasicsLine() { com.esri.core.geometry.Line line = new com.esri.core.geometry.Line(); bool result = simplifyOp.IsSimpleAsFeature(line, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); line.SetStart(new com.esri.core.geometry.Point(0, 0)); // line.setEndXY(0, 0); result = simplifyOp.IsSimpleAsFeature(line, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); line.SetEnd(new com.esri.core.geometry.Point(1, 0)); result = simplifyOp.IsSimpleAsFeature(line, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(result); }
public virtual void TestCR177477getPathEnd() { com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon(); pg.StartPath(-130, 40); pg.LineTo(-70, 40); pg.LineTo(-70, 10); pg.LineTo(-130, 10); pg.StartPath(-60, 40); pg.LineTo(-50, 40); pg.LineTo(-50, 10); pg.LineTo(-60, 10); pg.StartPath(-40, 40); pg.LineTo(-30, 40); pg.LineTo(-30, 10); pg.LineTo(-40, 10); int pathCount = pg.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 3); // int startIndex = pg.getPathStart(pathCount - 1); // int endIndex = pg.getPathEnd(pathCount - 1); com.esri.core.geometry.Line line = new com.esri.core.geometry.Line(); line.ToString(); line.SetStart(new com.esri.core.geometry.Point(0, 0)); line.SetEnd(new com.esri.core.geometry.Point(1, 0)); line.ToString(); double geoLength = com.esri.core.geometry.GeometryEngine.GeodesicDistanceOnWGS84(new com.esri.core.geometry.Point(0, 0), new com.esri.core.geometry.Point(1, 0)); NUnit.Framework.Assert.IsTrue(System.Math.Abs(geoLength - 111319) < 1); }
public virtual void TestLine() { com.esri.core.geometry.Line env = new com.esri.core.geometry.Line(); env.SetStartXY(100, 200); env.SetEndXY(250, 300); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); env.SetStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 1); env.SetEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 2); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0) == 1); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0) == 2); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); env.SetStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 3); env.SetEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 4); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 4); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); env.SetStartAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 5); env.SetEndAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 6); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0) == 1); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0) == 2); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 4); env.DropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 4); com.esri.core.geometry.Line env1 = new com.esri.core.geometry.Line(); env.CopyTo(env1); NUnit.Framework.Assert.IsFalse(env1.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 5); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0) == 6); NUnit.Framework.Assert.IsTrue(env.GetStartAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 3); NUnit.Framework.Assert.IsTrue(env.GetEndAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0) == 4); }
public virtual void TestHullTickTock() { com.esri.core.geometry.Polygon geom1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon geom2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point geom3 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Line geom4 = new com.esri.core.geometry.Line(); com.esri.core.geometry.Envelope geom5 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.MultiPoint geom6 = new com.esri.core.geometry.MultiPoint(); // polygon geom1.StartPath(0, 0); geom1.LineTo(0, 0); geom1.LineTo(5, 11); geom1.LineTo(5, 11); geom1.LineTo(10, 0); geom1.LineTo(10, 0); // polygon geom2.StartPath(0, 5); geom2.LineTo(0, 5); geom2.LineTo(10, 5); geom2.LineTo(10, 5); geom2.LineTo(5, -5); geom2.LineTo(5, -5); // point geom3.SetXY(15, 1.25); // segment geom4.SetEndXY(-5, 1.25); geom4.SetStartXY(0, 0); // envelope geom5.SetCoords(0, 0, 5, 10); // multi_point geom6.Add(10, 5); geom6.Add(10, 10); // Create com.esri.core.geometry.ListeningGeometryCursor gc = new com.esri.core.geometry.ListeningGeometryCursor(); com.esri.core.geometry.GeometryCursor ticktock = com.esri.core.geometry.OperatorConvexHull.Local().Execute(gc, true, null); // Use tick-tock to push a geometry and do a piece of work. gc.Tick(geom1); ticktock.Tock(); gc.Tick(geom2); ticktock.Tock(); gc.Tick(geom3); // skiped one tock just for testing. ticktock.Tock(); gc.Tick(geom4); ticktock.Tock(); gc.Tick(geom5); ticktock.Tock(); gc.Tick(geom6); ticktock.Tock(); // Get the result com.esri.core.geometry.Geometry result = ticktock.Next(); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)result; NUnit.Framework.Assert.IsTrue(com.esri.core.geometry.OperatorConvexHull.Local().IsConvex(convex_hull, null)); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); com.esri.core.geometry.Point2D p5 = convex_hull.GetXY(4); com.esri.core.geometry.Point2D p6 = convex_hull.GetXY(5); NUnit.Framework.Assert.IsTrue(p1.x == 5.0 && p1.y == 11.0); NUnit.Framework.Assert.IsTrue(p2.x == 10.0 && p2.y == 10); NUnit.Framework.Assert.IsTrue(p3.x == 15.0 && p3.y == 1.25); NUnit.Framework.Assert.IsTrue(p4.x == 5.0 && p4.y == -5.0); NUnit.Framework.Assert.IsTrue(p5.x == -5.0 && p5.y == 1.25); NUnit.Framework.Assert.IsTrue(p6.x == 0.0 && p6.y == 10.0); }
public static void TestMergeCursor() { com.esri.core.geometry.OperatorConvexHull bounding = (com.esri.core.geometry.OperatorConvexHull)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ConvexHull); com.esri.core.geometry.Polygon geom1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon geom2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point geom3 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Line geom4 = new com.esri.core.geometry.Line(); com.esri.core.geometry.Envelope geom5 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.MultiPoint geom6 = new com.esri.core.geometry.MultiPoint(); // polygon geom1.StartPath(0, 0); geom1.LineTo(0, 0); geom1.LineTo(5, 11); geom1.LineTo(5, 11); geom1.LineTo(10, 0); geom1.LineTo(10, 0); // polygon geom2.StartPath(0, 5); geom2.LineTo(0, 5); geom2.LineTo(10, 5); geom2.LineTo(10, 5); geom2.LineTo(5, -5); geom2.LineTo(5, -5); // point geom3.SetXY(15, 1.25); // segment geom4.SetEndXY(-5, 1.25); geom4.SetStartXY(0, 0); // envelope geom5.SetCoords(0, 0, 5, 10); // multi_point geom6.Add(10, 5); geom6.Add(10, 10); // create cursor com.esri.core.geometry.Geometry[] geoms = new com.esri.core.geometry.Geometry[6]; geoms[0] = geom1; geoms[1] = geom2; geoms[2] = geom3; geoms[3] = geom4; geoms[4] = geom5; geoms[5] = geom6; com.esri.core.geometry.GeometryCursor cursor = new com.esri.core.geometry.SimpleGeometryCursor(geoms); // create convex hull from the cursor with b_merge set to true com.esri.core.geometry.GeometryCursor convex_hull_curs = bounding.Execute(cursor, true, null); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(convex_hull_curs.Next()); NUnit.Framework.Assert.IsTrue(convex_hull_curs.Next() == null); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); com.esri.core.geometry.Point2D p5 = convex_hull.GetXY(4); com.esri.core.geometry.Point2D p6 = convex_hull.GetXY(5); NUnit.Framework.Assert.IsTrue(p1.x == 5.0 && p1.y == 11.0); NUnit.Framework.Assert.IsTrue(p2.x == 10.0 && p2.y == 10); NUnit.Framework.Assert.IsTrue(p3.x == 15.0 && p3.y == 1.25); NUnit.Framework.Assert.IsTrue(p4.x == 5.0 && p4.y == -5.0); NUnit.Framework.Assert.IsTrue(p5.x == -5.0 && p5.y == 1.25); NUnit.Framework.Assert.IsTrue(p6.x == 0.0 && p6.y == 10.0); // Test GeometryEngine com.esri.core.geometry.Geometry[] merged_hull = com.esri.core.geometry.GeometryEngine.ConvexHull(geoms, true); convex_hull = (com.esri.core.geometry.Polygon)merged_hull[0]; p1 = convex_hull.GetXY(0); p2 = convex_hull.GetXY(1); p3 = convex_hull.GetXY(2); p4 = convex_hull.GetXY(3); p5 = convex_hull.GetXY(4); p6 = convex_hull.GetXY(5); NUnit.Framework.Assert.IsTrue(p1.x == 5.0 && p1.y == 11.0); NUnit.Framework.Assert.IsTrue(p2.x == 10.0 && p2.y == 10); NUnit.Framework.Assert.IsTrue(p3.x == 15.0 && p3.y == 1.25); NUnit.Framework.Assert.IsTrue(p4.x == 5.0 && p4.y == -5.0); NUnit.Framework.Assert.IsTrue(p5.x == -5.0 && p5.y == 1.25); NUnit.Framework.Assert.IsTrue(p6.x == 0.0 && p6.y == 10.0); }
public static void TestDegenerate() { com.esri.core.geometry.OperatorConvexHull bounding = (com.esri.core.geometry.OperatorConvexHull)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ConvexHull); com.esri.core.geometry.OperatorDensifyByLength densify = (com.esri.core.geometry.OperatorDensifyByLength)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.DensifyByLength); { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(0, 0); polygon.LineTo(1, 0); polygon.LineTo(0, 0); polygon.LineTo(2, 0); polygon.LineTo(1, 0); polygon.LineTo(3, 0); polygon.StartPath(0, 0); polygon.LineTo(1, 0); polygon.LineTo(0, 0); polygon.LineTo(2, 0); polygon.LineTo(1, 0); polygon.LineTo(3, 0); com.esri.core.geometry.Polygon densified = (com.esri.core.geometry.Polygon)(densify.Execute(polygon, .5, null)); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(densified, null)); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(convex_hull.CalculateArea2D() == 0.0); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); NUnit.Framework.Assert.IsTrue(p1.x == 0.0 && p1.y == 0.0); NUnit.Framework.Assert.IsTrue(p2.x == 3.0 && p2.y == 0.0); } { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); polygon.LineTo(com.esri.core.geometry.NumberUtils.DoubleEps(), 0); polygon.LineTo(0, com.esri.core.geometry.NumberUtils.DoubleEps()); polygon.LineTo(10, 0); polygon.LineTo(10, 0); polygon.LineTo(10, 5); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 10); polygon.LineTo(0, 0); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); polygon.LineTo(10, 0); polygon.LineTo(10, 0); polygon.LineTo(10, 5); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 10); polygon.LineTo(0, 0); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); polygon.LineTo(10, 0); polygon.LineTo(5, 0); polygon.LineTo(10, 0); polygon.LineTo(10, 5); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 0); com.esri.core.geometry.Polygon densified = (com.esri.core.geometry.Polygon)(densify.Execute(polygon, 1, null)); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(densified, null)); double area = convex_hull.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(area == 100.0); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); NUnit.Framework.Assert.IsTrue(p1.x == 0.0 && p1.y == 0.0); NUnit.Framework.Assert.IsTrue(p2.x == 0.0 && p2.y == 10.0); NUnit.Framework.Assert.IsTrue(p3.x == 10.0 && p3.y == 10.0); NUnit.Framework.Assert.IsTrue(p4.x == 10.0 && p4.y == 0.0); } { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(5, 10); polygon.LineTo(5, 5); polygon.LineTo(5, 8); polygon.LineTo(10, 10); polygon.LineTo(10, 0); com.esri.core.geometry.Polygon densified = (com.esri.core.geometry.Polygon)(densify.Execute(polygon, 1, null)); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(densified, null)); double area = convex_hull.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(area == 100.0); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); NUnit.Framework.Assert.IsTrue(p1.x == 0.0 && p1.y == 0.0); NUnit.Framework.Assert.IsTrue(p2.x == 0.0 && p2.y == 10.0); NUnit.Framework.Assert.IsTrue(p3.x == 10.0 && p3.y == 10.0); NUnit.Framework.Assert.IsTrue(p4.x == 10.0 && p4.y == 0.0); } { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); polygon.LineTo(10, 0); polygon.LineTo(5, 0); polygon.LineTo(10, 0); polygon.LineTo(10, 5); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(10, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 10); polygon.LineTo(5, 10); polygon.LineTo(0, 0); com.esri.core.geometry.Polygon densified = (com.esri.core.geometry.Polygon)(densify.Execute(polygon, 1, null)); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(densified, null)); double area = convex_hull.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(area == 100.0); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); NUnit.Framework.Assert.IsTrue(p1.x == 0.0 && p1.y == 0.0); NUnit.Framework.Assert.IsTrue(p2.x == 0.0 && p2.y == 10.0); NUnit.Framework.Assert.IsTrue(p3.x == 10.0 && p3.y == 10.0); NUnit.Framework.Assert.IsTrue(p4.x == 10.0 && p4.y == 0.0); } { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 10); polygon.LineTo(0, 0); polygon.LineTo(10, 10); polygon.LineTo(0, 0); polygon.LineTo(10, 0); polygon.LineTo(0, 0); polygon.StartPath(0, 10); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.LineTo(0, 10); polygon.LineTo(10, 0); polygon.LineTo(0, 10); polygon.LineTo(0, 0); polygon.LineTo(0, 10); polygon.StartPath(10, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(0, 0); polygon.LineTo(10, 10); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.StartPath(10, 0); polygon.LineTo(10, 0); polygon.LineTo(0, 0); polygon.LineTo(10, 0); polygon.LineTo(0, 10); polygon.LineTo(10, 0); polygon.LineTo(10, 10); polygon.LineTo(10, 0); com.esri.core.geometry.Polygon densified = (com.esri.core.geometry.Polygon)(densify.Execute(polygon, 1, null)); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(densified, null)); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); com.esri.core.geometry.Point2D p1 = convex_hull.GetXY(0); com.esri.core.geometry.Point2D p2 = convex_hull.GetXY(1); com.esri.core.geometry.Point2D p3 = convex_hull.GetXY(2); com.esri.core.geometry.Point2D p4 = convex_hull.GetXY(3); NUnit.Framework.Assert.IsTrue(p1.x == 0.0 && p1.y == 0.0); NUnit.Framework.Assert.IsTrue(p2.x == 0.0 && p2.y == 10.0); NUnit.Framework.Assert.IsTrue(p3.x == 10.0 && p3.y == 10.0); NUnit.Framework.Assert.IsTrue(p4.x == 10.0 && p4.y == 0.0); } { com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); mpoint.Add(4, 4); mpoint.Add(4, 4); mpoint.Add(4, 4); mpoint.Add(4, 4); com.esri.core.geometry.Polygon convex_hull = (com.esri.core.geometry.Polygon)(bounding.Execute(mpoint, null)); NUnit.Framework.Assert.IsTrue(convex_hull.GetPointCount() == 2); NUnit.Framework.Assert.IsTrue(convex_hull.CalculateArea2D() == 0.0); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); } { com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); mpoint.Add(4, 4); com.esri.core.geometry.MultiPoint convex_hull = (com.esri.core.geometry.MultiPoint)(bounding.Execute(mpoint, null)); NUnit.Framework.Assert.IsTrue(convex_hull.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(convex_hull == mpoint); } { com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); mpoint.Add(4, 4); mpoint.Add(4, 5); com.esri.core.geometry.Polyline convex_hull = (com.esri.core.geometry.Polyline)(bounding.Execute(mpoint, null)); NUnit.Framework.Assert.IsTrue(convex_hull.GetPointCount() == 2); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(convex_hull.CalculateLength2D() == 1.0); } { com.esri.core.geometry.Line line = new com.esri.core.geometry.Line(); line.SetStartXY(0, 0); line.SetEndXY(0, 1); com.esri.core.geometry.Polyline convex_hull = (com.esri.core.geometry.Polyline)(bounding.Execute(line, null)); NUnit.Framework.Assert.IsTrue(convex_hull.GetPointCount() == 2); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(convex_hull.CalculateLength2D() == 1.0); } { com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(0, 0); polyline.LineTo(0, 1); com.esri.core.geometry.Polyline convex_hull = (com.esri.core.geometry.Polyline)(bounding.Execute(polyline, null)); NUnit.Framework.Assert.IsTrue(convex_hull.GetPointCount() == 2); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(polyline == convex_hull); NUnit.Framework.Assert.IsTrue(convex_hull.CalculateLength2D() == 1.0); } { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(0, 0, 10, 10); com.esri.core.geometry.Envelope convex_hull = (com.esri.core.geometry.Envelope)(bounding.Execute(env, null)); NUnit.Framework.Assert.IsTrue(bounding.IsConvex(convex_hull, null)); NUnit.Framework.Assert.IsTrue(env == convex_hull); } }