public static void testEditShape() { { // std::shared_ptr<Esri_runtimecore::Geometry::Polygon> poly_base_6 // = std::make_shared<Esri_runtimecore::Geometry::Polygon>(); // Single part polygon com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(14, 15); poly.lineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(14, 15); poly.lineTo(10, 11); poly.startPath(100, 10); poly.lineTo(100, 12); poly.lineTo(14, 150); poly.lineTo(10, 101); poly.lineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Single part polyline com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(14, 15); poly.lineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape .getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(14, 15); poly.lineTo(10, 11); poly.startPath(100, 10); poly.lineTo(100, 12); poly.lineTo(14, 150); poly.lineTo(10, 101); poly.lineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape .getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Five part poly. Close one of parts to test if it works. com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(14, 15); poly.lineTo(10, 11); poly.startPath(100, 10); poly.lineTo(100, 12); poly.lineTo(14, 150); poly.lineTo(10, 101); poly.lineTo(100, 11); poly.startPath(1100, 101); poly.lineTo(1300, 132); poly.lineTo(144, 150); poly.lineTo(106, 1051); poly.lineTo(1600, 161); poly.startPath(100, 190); poly.lineTo(1800, 192); poly.lineTo(184, 8150); poly.lineTo(1080, 181); poly.startPath(1030, 10); poly.lineTo(1300, 132); poly.lineTo(314, 3150); poly.lineTo(310, 1301); poly.lineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); editShape.setClosedPath(editShape.getNextPath(editShape.getFirstPath(geom)), true ); ((com.esri.core.geometry.MultiPathImpl)poly._getImpl()).closePathWithLine(1); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape .getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(314, 3150); poly.lineTo(310, 1301); poly.lineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); int vertex = editShape.getFirstVertex(editShape.getFirstPath(geom)); vertex = editShape.removeVertex(vertex, true); vertex = editShape.getNextVertex(vertex); editShape.removeVertex(vertex, true); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape .getGeometry(geom); poly.setEmpty(); poly.startPath(10, 12); poly.lineTo(310, 1301); poly.lineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 12); poly.lineTo(314, 3150); poly.lineTo(310, 1301); poly.lineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); int vertex = editShape.getFirstVertex(editShape.getFirstPath(geom)); vertex = editShape.removeVertex(vertex, true); vertex = editShape.getNextVertex(vertex); editShape.removeVertex(vertex, true); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); poly.setEmpty(); poly.startPath(10, 12); poly.lineTo(310, 1301); poly.lineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 10.001); poly.lineTo(10.001, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); editShape.filterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.isEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 10.0025); poly.lineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); editShape.filterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); NUnit.Framework.Assert.IsTrue(!poly2.isEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(10, 10); poly.lineTo(10, 10.001); poly.lineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape (); int geom = editShape.addGeometry(poly); editShape.filterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape. getGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.isEmpty()); } { // Test attribute splitting 1 com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.startPath(0, 0); polyline.lineTo(1, 1); polyline.lineTo(2, 2); polyline.lineTo(3, 3); polyline.lineTo(4, 4); polyline.startPath(5, 5); polyline.lineTo(6, 6); polyline.lineTo(7, 7); polyline.lineTo(8, 8); polyline.lineTo(9, 9); polyline.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0, 4); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 1, 0, 8); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 2, 0, 12); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 3, 0, 16); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 4, 0, 20); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 5, 0, 22); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 6, 0, 26); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 7, 0, 30); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 8, 0, 34); polyline.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 9, 0, 38); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.addGeometry(polyline); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32 (0); for (int path = shape.getFirstPath(geometry); path != -1; path = shape.getNextPath (path)) { for (int vertex = shape.getFirstVertex(path); vertex != -1; vertex = shape.getNextVertex (vertex)) { if (vertex != shape.getLastVertex(path)) { vertex_handles.add(vertex); } } } double[] t = new double[1]; for (int i = 0; i < vertex_handles.size(); i++) { int vertex = vertex_handles.read(i); t[0] = 0.5; shape.splitSegment(vertex, t, 1); } com.esri.core.geometry.Polyline chopped_polyline = (com.esri.core.geometry.Polyline )shape.getGeometry(geometry); NUnit.Framework.Assert.IsTrue(chopped_polyline.getPointCount() == 18); double att_ = 4; for (int i_1 = 0; i_1 < 18; i_1++) { double att = chopped_polyline.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, i_1, 0); NUnit.Framework.Assert.IsTrue(att == att_); att_ += 2; } } { // Test attribute splitting 2 com.esri.core.geometry.Polyline line1 = new com.esri.core.geometry.Polyline(); com.esri.core.geometry.Polyline line2 = new com.esri.core.geometry.Polyline(); line1.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line2.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line1.startPath(0, 0); line1.lineTo(10, 10); line2.startPath(10, 0); line2.lineTo(0, 10); line1.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); line1.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17 ); line2.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 5); line2.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 15 ); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int g1 = shape.addGeometry(line1); int g2 = shape.addGeometry(line2); com.esri.core.geometry.CrackAndCluster.execute(shape, 0.001, null, true); com.esri.core.geometry.Polyline chopped_line1 = (com.esri.core.geometry.Polyline) shape.getGeometry(g1); com.esri.core.geometry.Polyline chopped_line2 = (com.esri.core.geometry.Polyline) shape.getGeometry(g2); double att1 = chopped_line1.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 1, 0); double att2 = chopped_line2.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 1, 0); NUnit.Framework.Assert.IsTrue(att1 == 12); NUnit.Framework.Assert.IsTrue(att2 == 10); } { // Test attribute splitting 3 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, 10); polygon.lineTo(10, 10); polygon.lineTo(10, 0); polygon.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); polygon.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17); polygon.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 23); polygon.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0, 43); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.addGeometry(polygon); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32 (0); int start_v = shape.getFirstVertex(shape.getFirstPath(geometry)); int v = start_v; do { vertex_handles.add(v); v = shape.getNextVertex(v); }while (v != start_v); double[] t = new double[1]; for (int i = 0; i < vertex_handles.size(); i++) { int v1 = vertex_handles.read(i); t[0] = 0.5; shape.splitSegment(v1, t, 1); } com.esri.core.geometry.Polygon cut_polygon = (com.esri.core.geometry.Polygon)shape .getGeometry(geometry); NUnit.Framework.Assert.IsTrue(cut_polygon.getPointCount() == 8); com.esri.core.geometry.Point2D pt0 = cut_polygon.getXY(0); double a0 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 0, 0); NUnit.Framework.Assert.IsTrue(a0 == 25); com.esri.core.geometry.Point2D pt1 = cut_polygon.getXY(1); double a1 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 1, 0); NUnit.Framework.Assert.IsTrue(a1 == 7); com.esri.core.geometry.Point2D pt2 = cut_polygon.getXY(2); double a2 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 2, 0); NUnit.Framework.Assert.IsTrue(a2 == 12); com.esri.core.geometry.Point2D pt3 = cut_polygon.getXY(3); double a3 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 3, 0); NUnit.Framework.Assert.IsTrue(a3 == 17); com.esri.core.geometry.Point2D pt4 = cut_polygon.getXY(4); double a4 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 4, 0); NUnit.Framework.Assert.IsTrue(a4 == 20); com.esri.core.geometry.Point2D pt5 = cut_polygon.getXY(5); double a5 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 5, 0); NUnit.Framework.Assert.IsTrue(a5 == 23); com.esri.core.geometry.Point2D pt6 = cut_polygon.getXY(6); double a6 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 6, 0); NUnit.Framework.Assert.IsTrue(a6 == 33); com.esri.core.geometry.Point2D pt7 = cut_polygon.getXY(7); double a7 = cut_polygon.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .M, 7, 0); NUnit.Framework.Assert.IsTrue(a7 == 43); } }
public static void compareGeometryContent(com.esri.core.geometry.MultiVertexGeometry geom1, com.esri.core.geometry.MultiVertexGeometry geom2) { // Geometry types NUnit.Framework.Assert.IsTrue(geom1.getType().value() == geom2.getType().value()); // Envelopes com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(); geom1.queryEnvelope2D(env1); com.esri.core.geometry.Envelope2D env2 = new com.esri.core.geometry.Envelope2D(); geom2.queryEnvelope2D(env2); NUnit.Framework.Assert.IsTrue(env1.xmin == env2.xmin && env1.xmax == env2.xmax && env1.ymin == env2.ymin && env1.ymax == env2.ymax); int type = geom1.getType().value(); if (type == com.esri.core.geometry.Geometry.GeometryType.Polyline || type == com.esri.core.geometry.Geometry.GeometryType .Polygon) { // Part Count int partCount1 = ((com.esri.core.geometry.MultiPath)geom1).getPathCount(); int partCount2 = ((com.esri.core.geometry.MultiPath)geom2).getPathCount(); NUnit.Framework.Assert.IsTrue(partCount1 == partCount2); // Part indices for (int i = 0; i < partCount1; i++) { int start1 = ((com.esri.core.geometry.MultiPath)geom1).getPathStart(i); int start2 = ((com.esri.core.geometry.MultiPath)geom2).getPathStart(i); NUnit.Framework.Assert.IsTrue(start1 == start2); int end1 = ((com.esri.core.geometry.MultiPath)geom1).getPathEnd(i); int end2 = ((com.esri.core.geometry.MultiPath)geom2).getPathEnd(i); NUnit.Framework.Assert.IsTrue(end1 == end2); } } // Point count int pointCount1 = geom1.getPointCount(); int pointCount2 = geom2.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2); if (type == com.esri.core.geometry.Geometry.GeometryType.MultiPoint || type == com.esri.core.geometry.Geometry.GeometryType .Polyline || type == com.esri.core.geometry.Geometry.GeometryType.Polygon) { // POSITION com.esri.core.geometry.AttributeStreamBase positionStream1 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom1._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .POSITION); com.esri.core.geometry.AttributeStreamOfDbl position1 = (com.esri.core.geometry.AttributeStreamOfDbl )(positionStream1); com.esri.core.geometry.AttributeStreamBase positionStream2 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom2._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .POSITION); com.esri.core.geometry.AttributeStreamOfDbl position2 = (com.esri.core.geometry.AttributeStreamOfDbl )(positionStream2); for (int i = 0; i < pointCount1; i++) { double x1 = position1.read(2 * i); double x2 = position2.read(2 * i); NUnit.Framework.Assert.IsTrue(x1 == x2); double y1 = position1.read(2 * i + 1); double y2 = position2.read(2 * i + 1); NUnit.Framework.Assert.IsTrue(y1 == y2); } // Zs bool bHasZs1 = geom1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z); bool bHasZs2 = geom2.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z); NUnit.Framework.Assert.IsTrue(bHasZs1 == bHasZs2); if (bHasZs1) { com.esri.core.geometry.AttributeStreamBase zStream1 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom1._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .Z); com.esri.core.geometry.AttributeStreamOfDbl zs1 = (com.esri.core.geometry.AttributeStreamOfDbl )(zStream1); com.esri.core.geometry.AttributeStreamBase zStream2 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom2._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .Z); com.esri.core.geometry.AttributeStreamOfDbl zs2 = (com.esri.core.geometry.AttributeStreamOfDbl )(zStream2); for (int i_1 = 0; i_1 < pointCount1; i_1++) { double z1 = zs1.read(i_1); double z2 = zs2.read(i_1); NUnit.Framework.Assert.IsTrue(z1 == z2); } } // Ms bool bHasMs1 = geom1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M); bool bHasMs2 = geom2.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M); NUnit.Framework.Assert.IsTrue(bHasMs1 == bHasMs2); if (bHasMs1) { com.esri.core.geometry.AttributeStreamBase mStream1 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom1._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .M); com.esri.core.geometry.AttributeStreamOfDbl ms1 = (com.esri.core.geometry.AttributeStreamOfDbl )(mStream1); com.esri.core.geometry.AttributeStreamBase mStream2 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom2._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .M); com.esri.core.geometry.AttributeStreamOfDbl ms2 = (com.esri.core.geometry.AttributeStreamOfDbl )(mStream2); for (int i_1 = 0; i_1 < pointCount1; i_1++) { double m1 = ms1.read(i_1); double m2 = ms2.read(i_1); NUnit.Framework.Assert.IsTrue(m1 == m2); } } // IDs bool bHasIDs1 = geom1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID); bool bHasIDs2 = geom2.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID); NUnit.Framework.Assert.IsTrue(bHasIDs1 == bHasIDs2); if (bHasIDs1) { com.esri.core.geometry.AttributeStreamBase idStream1 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom1._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .ID); com.esri.core.geometry.AttributeStreamOfInt32 ids1 = (com.esri.core.geometry.AttributeStreamOfInt32 )(idStream1); com.esri.core.geometry.AttributeStreamBase idStream2 = ((com.esri.core.geometry.MultiVertexGeometryImpl )geom2._getImpl()).getAttributeStreamRef(com.esri.core.geometry.VertexDescription.Semantics .ID); com.esri.core.geometry.AttributeStreamOfInt32 ids2 = (com.esri.core.geometry.AttributeStreamOfInt32 )(idStream2); for (int i_1 = 0; i_1 < pointCount1; i_1++) { int id1 = ids1.read(i_1); int id2 = ids2.read(i_1); NUnit.Framework.Assert.IsTrue(id1 == id2); } } } }
public static void TestEditShape_() { { // std::shared_ptr<Esri_runtimecore::Geometry::Polygon> poly_base_6 // = std::make_shared<Esri_runtimecore::Geometry::Polygon>(); // Single part polygon com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Single part polyline com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Five part poly. Close one of parts to test if it works. com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); poly.StartPath(1100, 101); poly.LineTo(1300, 132); poly.LineTo(144, 150); poly.LineTo(106, 1051); poly.LineTo(1600, 161); poly.StartPath(100, 190); poly.LineTo(1800, 192); poly.LineTo(184, 8150); poly.LineTo(1080, 181); poly.StartPath(1030, 10); poly.LineTo(1300, 132); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.SetClosedPath(editShape.GetNextPath(editShape.GetFirstPath(geom)), true); ((com.esri.core.geometry.MultiPathImpl)poly._getImpl()).ClosePathWithLine(1); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); int vertex = editShape.GetFirstVertex(editShape.GetFirstPath(geom)); vertex = editShape.RemoveVertex(vertex, true); vertex = editShape.GetNextVertex(vertex); editShape.RemoveVertex(vertex, true); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); poly.SetEmpty(); poly.StartPath(10, 12); poly.LineTo(310, 1301); poly.LineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); int vertex = editShape.GetFirstVertex(editShape.GetFirstPath(geom)); vertex = editShape.RemoveVertex(vertex, true); vertex = editShape.GetNextVertex(vertex); editShape.RemoveVertex(vertex, true); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); poly.SetEmpty(); poly.StartPath(10, 12); poly.LineTo(310, 1301); poly.LineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(10.001, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.0025); poly.LineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(!poly2.IsEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test attribute splitting 1 com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(0, 0); polyline.LineTo(1, 1); polyline.LineTo(2, 2); polyline.LineTo(3, 3); polyline.LineTo(4, 4); polyline.StartPath(5, 5); polyline.LineTo(6, 6); polyline.LineTo(7, 7); polyline.LineTo(8, 8); polyline.LineTo(9, 9); polyline.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0, 4); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 1, 0, 8); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 2, 0, 12); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 3, 0, 16); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 4, 0, 20); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 5, 0, 22); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 6, 0, 26); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 7, 0, 30); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 8, 0, 34); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 9, 0, 38); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.AddGeometry(polyline); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32(0); for (int path = shape.GetFirstPath(geometry); path != -1; path = shape.GetNextPath(path)) { for (int vertex = shape.GetFirstVertex(path); vertex != -1; vertex = shape.GetNextVertex(vertex)) { if (vertex != shape.GetLastVertex(path)) { vertex_handles.Add(vertex); } } } double[] t = new double[1]; for (int i = 0; i < vertex_handles.Size(); i++) { int vertex = vertex_handles.Read(i); t[0] = 0.5; shape.SplitSegment(vertex, t, 1); } com.esri.core.geometry.Polyline chopped_polyline = (com.esri.core.geometry.Polyline)shape.GetGeometry(geometry); NUnit.Framework.Assert.IsTrue(chopped_polyline.GetPointCount() == 18); double att_ = 4; for (int i_1 = 0; i_1 < 18; i_1++) { double att = chopped_polyline.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, i_1, 0); NUnit.Framework.Assert.IsTrue(att == att_); att_ += 2; } } { // Test attribute splitting 2 com.esri.core.geometry.Polyline line1 = new com.esri.core.geometry.Polyline(); com.esri.core.geometry.Polyline line2 = new com.esri.core.geometry.Polyline(); line1.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line2.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line1.StartPath(0, 0); line1.LineTo(10, 10); line2.StartPath(10, 0); line2.LineTo(0, 10); line1.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); line1.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17); line2.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 5); line2.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 15); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int g1 = shape.AddGeometry(line1); int g2 = shape.AddGeometry(line2); com.esri.core.geometry.CrackAndCluster.Execute(shape, 0.001, null, true); com.esri.core.geometry.Polyline chopped_line1 = (com.esri.core.geometry.Polyline)shape.GetGeometry(g1); com.esri.core.geometry.Polyline chopped_line2 = (com.esri.core.geometry.Polyline)shape.GetGeometry(g2); double att1 = chopped_line1.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); double att2 = chopped_line2.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(att1 == 12); NUnit.Framework.Assert.IsTrue(att2 == 10); } { // Test attribute splitting 3 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, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 23); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0, 43); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.AddGeometry(polygon); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32(0); int start_v = shape.GetFirstVertex(shape.GetFirstPath(geometry)); int v = start_v; do { vertex_handles.Add(v); v = shape.GetNextVertex(v); } while (v != start_v); double[] t = new double[1]; for (int i = 0; i < vertex_handles.Size(); i++) { int v1 = vertex_handles.Read(i); t[0] = 0.5; shape.SplitSegment(v1, t, 1); } com.esri.core.geometry.Polygon cut_polygon = (com.esri.core.geometry.Polygon)shape.GetGeometry(geometry); NUnit.Framework.Assert.IsTrue(cut_polygon.GetPointCount() == 8); com.esri.core.geometry.Point2D pt0 = cut_polygon.GetXY(0); double a0 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0); NUnit.Framework.Assert.IsTrue(a0 == 25); com.esri.core.geometry.Point2D pt1 = cut_polygon.GetXY(1); double a1 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(a1 == 7); com.esri.core.geometry.Point2D pt2 = cut_polygon.GetXY(2); double a2 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0); NUnit.Framework.Assert.IsTrue(a2 == 12); com.esri.core.geometry.Point2D pt3 = cut_polygon.GetXY(3); double a3 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0); NUnit.Framework.Assert.IsTrue(a3 == 17); com.esri.core.geometry.Point2D pt4 = cut_polygon.GetXY(4); double a4 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 4, 0); NUnit.Framework.Assert.IsTrue(a4 == 20); com.esri.core.geometry.Point2D pt5 = cut_polygon.GetXY(5); double a5 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 5, 0); NUnit.Framework.Assert.IsTrue(a5 == 23); com.esri.core.geometry.Point2D pt6 = cut_polygon.GetXY(6); double a6 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 6, 0); NUnit.Framework.Assert.IsTrue(a6 == 33); com.esri.core.geometry.Point2D pt7 = cut_polygon.GetXY(7); double a7 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 7, 0); NUnit.Framework.Assert.IsTrue(a7 == 43); } }