public virtual void TestPolygon() { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(-97.06138, 32.837); polygon.LineTo(-97.06133, 32.836); polygon.LineTo(-97.06124, 32.834); polygon.LineTo(-97.06127, 32.832); polygon.StartPath(-97.06326, 32.759); polygon.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon)); com.epl.geometry.MapGeometry mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polygon.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); com.epl.geometry.Polygon emptyPolygon = new com.epl.geometry.Polygon(); string emptyPolygonString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyPolygon); polygonPathsWgs84Parser = factory.CreateJsonParser(emptyPolygonString); mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(mPolygonWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); } }
public static void TestClipOfCoinciding() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); com.epl.geometry.Envelope2D envelopeCR = new com.epl.geometry.Envelope2D(); envelopeCR.xmin = -180; envelopeCR.xmax = 180; envelopeCR.ymin = -90; envelopeCR.ymax = 90; polygon.AddEnvelope(envelopeCR, false); com.epl.geometry.SpatialReference gcsWGS84 = com.epl.geometry.SpatialReference.Create(4326); // CR com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 4); com.epl.geometry.OperatorDensifyByLength densifyOp = (com.epl.geometry.OperatorDensifyByLength)engine.GetOperator(com.epl.geometry.Operator.Type.DensifyByLength); polygon.SetEmpty(); polygon.AddEnvelope(envelopeCR, false); polygon = (com.epl.geometry.Polygon)densifyOp.Execute(polygon, 1, null); int pc = polygon.GetPointCount(); int pathc = polygon.GetPathCount(); NUnit.Framework.Assert.IsTrue(pc == 1080); NUnit.Framework.Assert.IsTrue(pathc == 1); clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); int _pathc = clippedPolygon.GetPathCount(); int _pc = clippedPolygon.GetPointCount(); NUnit.Framework.Assert.IsTrue(_pathc == 1); NUnit.Framework.Assert.IsTrue(_pc == pc); }
public virtual void TestBufferEnvelope() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Envelope inputGeom = new com.epl.geometry.Envelope(1, 0, 200, 400); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - (80 + 199)) < 0.001 && System.Math.Abs(env2D.GetHeight() - (80 + 400)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 201.0 / 2) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 400 / 2.0) < 0.001); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 104.0) < 10); com.epl.geometry.NonSimpleResult nsr = new com.epl.geometry.NonSimpleResult(); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, true, nsr, null)); { result = buffer.Execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -199 / 2.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -50.0, null); poly = (com.epl.geometry.Polygon)(result); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - (199 - 100)) < 0.001 && System.Math.Abs(env2D.GetHeight() - (400 - 100)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 201.0 / 2) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 400 / 2.0) < 0.001); pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 4.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
public virtual void TestBufferMultiPoint() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); com.epl.geometry.MultiPoint inputGeom = new com.epl.geometry.MultiPoint(); inputGeom.Add(12, 120); inputGeom.Add(20, 120); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.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 - 108.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.epl.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.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } }
public static void TestArcObjectsFailureCR196492() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 600, 600), false); polygon.StartPath(30, 300); polygon.LineTo(20, 310); polygon.LineTo(10, 300); com.epl.geometry.SpatialReference gcsWGS84 = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Envelope2D envelopeCR = new com.epl.geometry.Envelope2D(10, 10, 500, 500); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 7); }
public virtual void TestMP2onCR175871() { com.epl.geometry.Polygon pg = new com.epl.geometry.Polygon(); pg.StartPath(-50, 10); pg.LineTo(-50, 12); pg.LineTo(-45, 12); pg.LineTo(-45, 10); com.epl.geometry.Polygon pg1 = new com.epl.geometry.Polygon(); pg1.StartPath(-45, 10); pg1.LineTo(-40, 10); pg1.LineTo(-40, 8); pg.Add(pg1, false); com.epl.geometry.SpatialReference spatialReference = com.epl.geometry.SpatialReference.Create(4326); try { string jSonStr = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReference, pg); com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jp = jf.CreateJsonParser(jSonStr); jp.NextToken(); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp); com.epl.geometry.Geometry gm = mg.GetGeometry(); NUnit.Framework.Assert.AreEqual(com.epl.geometry.Geometry.Type.Polygon, gm.GetType()); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 4326); com.epl.geometry.Polygon pgNew = (com.epl.geometry.Polygon)gm; NUnit.Framework.Assert.AreEqual(pgNew.GetPathCount(), pg.GetPathCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetPointCount(), pg.GetPointCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetSegmentCount(), pg.GetSegmentCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(0).GetX(), pg.GetPoint(0).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetX(), pg.GetPoint(1).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetX(), pg.GetPoint(2).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetX(), pg.GetPoint(3).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(0).GetY(), pg.GetPoint(0).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetY(), pg.GetPoint(1).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetY(), pg.GetPoint(2).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetY(), pg.GetPoint(3).GetY(), 0.000000001); } catch (System.Exception ex) { string err = ex.Message; System.Console.Out.Write(err); throw; } }
internal static bool QuadTreeWillHelp(com.epl.geometry.Polygon polygon, int c_queries) { int n = polygon.GetPointCount(); if (n < 16) { return(false); } double c_build_quad_tree = 2.0; // what's a good constant? double c_query_quad_tree = 1.0; // what's a good constant? double c_point_in_polygon_brute_force = 1.0; // what's a good constant? double c_quad_tree = c_build_quad_tree * n + c_query_quad_tree * (System.Math.Log((double)n) / System.Math.Log(2.0)) * c_queries; double c_brute_force = c_point_in_polygon_brute_force * n * c_queries; return(c_quad_tree < c_brute_force); }
public static void TestEditShape__() { { // Single part polygon com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.epl.geometry.Polygon poly2 = (com.epl.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.epl.geometry.Polygon poly = new com.epl.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.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.epl.geometry.Polygon poly2 = (com.epl.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Single part polyline com.epl.geometry.Polyline poly = new com.epl.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.epl.geometry.Polyline poly2 = (com.epl.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.epl.geometry.Polyline poly = new com.epl.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.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.epl.geometry.Polyline poly2 = (com.epl.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.epl.geometry.Polyline poly = new com.epl.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.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.SetClosedPath(editShape.GetNextPath(editShape.GetFirstPath(geom)), true); ((com.epl.geometry.MultiPathImpl)poly._getImpl()).ClosePathWithLine(1); com.epl.geometry.Polyline poly2 = (com.epl.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.epl.geometry.Polyline poly = new com.epl.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.epl.geometry.EditShape editShape = new com.epl.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.epl.geometry.Polyline poly2 = (com.epl.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.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.epl.geometry.EditShape editShape = new com.epl.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.epl.geometry.Polygon poly2 = (com.epl.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.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(10.001, 10); com.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.epl.geometry.Polygon poly2 = (com.epl.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test Filter Close Points com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.0025); poly.LineTo(11.0, 10); com.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.epl.geometry.Polygon poly2 = (com.epl.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(!poly2.IsEmpty()); } { // Test Filter Close Points com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(11.0, 10); com.epl.geometry.EditShape editShape = new com.epl.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.epl.geometry.Polygon poly2 = (com.epl.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test attribute splitting 1 com.epl.geometry.Polyline polyline = new com.epl.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.epl.geometry.VertexDescription.Semantics.Z); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 4); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0, 8); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0, 12); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 3, 0, 16); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 4, 0, 20); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 5, 0, 22); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 6, 0, 26); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 7, 0, 30); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 8, 0, 34); polyline.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 9, 0, 38); com.epl.geometry.EditShape shape = new com.epl.geometry.EditShape(); int geometry = shape.AddGeometry(polyline); com.epl.geometry.AttributeStreamOfInt32 vertex_handles = new com.epl.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.epl.geometry.Polyline chopped_polyline = (com.epl.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.epl.geometry.VertexDescription.Semantics.Z, i_1, 0); NUnit.Framework.Assert.IsTrue(att == att_); att_ += 2; } } { // Test attribute splitting 2 com.epl.geometry.Polyline line1 = new com.epl.geometry.Polyline(); com.epl.geometry.Polyline line2 = new com.epl.geometry.Polyline(); line1.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); line2.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); line1.StartPath(0, 0); line1.LineTo(10, 10); line2.StartPath(10, 0); line2.LineTo(0, 10); line1.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 7); line1.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 17); line2.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 5); line2.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 15); com.epl.geometry.EditShape shape = new com.epl.geometry.EditShape(); int g1 = shape.AddGeometry(line1); int g2 = shape.AddGeometry(line2); com.epl.geometry.CrackAndCluster.Execute(shape, 0.001, null, true); com.epl.geometry.Polyline chopped_line1 = (com.epl.geometry.Polyline)shape.GetGeometry(g1); com.epl.geometry.Polyline chopped_line2 = (com.epl.geometry.Polyline)shape.GetGeometry(g2); double att1 = chopped_line1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0); double att2 = chopped_line2.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(att1 == 12); NUnit.Framework.Assert.IsTrue(att2 == 10); } { // Test attribute splitting 3 com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 7); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 17); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 23); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 43); com.epl.geometry.EditShape shape = new com.epl.geometry.EditShape(); int geometry = shape.AddGeometry(polygon); com.epl.geometry.AttributeStreamOfInt32 vertex_handles = new com.epl.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.epl.geometry.Polygon cut_polygon = (com.epl.geometry.Polygon)shape.GetGeometry(geometry); NUnit.Framework.Assert.IsTrue(cut_polygon.GetPointCount() == 8); com.epl.geometry.Point2D pt0 = cut_polygon.GetXY(0); double a0 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0); NUnit.Framework.Assert.IsTrue(a0 == 25); com.epl.geometry.Point2D pt1 = cut_polygon.GetXY(1); double a1 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(a1 == 7); com.epl.geometry.Point2D pt2 = cut_polygon.GetXY(2); double a2 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0); NUnit.Framework.Assert.IsTrue(a2 == 12); com.epl.geometry.Point2D pt3 = cut_polygon.GetXY(3); double a3 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0); NUnit.Framework.Assert.IsTrue(a3 == 17); com.epl.geometry.Point2D pt4 = cut_polygon.GetXY(4); double a4 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0); NUnit.Framework.Assert.IsTrue(a4 == 20); com.epl.geometry.Point2D pt5 = cut_polygon.GetXY(5); double a5 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0); NUnit.Framework.Assert.IsTrue(a5 == 23); com.epl.geometry.Point2D pt6 = cut_polygon.GetXY(6); double a6 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 6, 0); NUnit.Framework.Assert.IsTrue(a6 == 33); com.epl.geometry.Point2D pt7 = cut_polygon.GetXY(7); double a7 = cut_polygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 7, 0); NUnit.Framework.Assert.IsTrue(a7 == 43); } }
public virtual void TestBufferPolyline() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polyline inputGeom = new com.epl.geometry.Polyline(); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); inputGeom.LineTo(0, 50); { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -1, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 80 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 80 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 171.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 2); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 186.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { inputGeom = new com.epl.geometry.Polyline(); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.StartPath(50, 0); inputGeom.LineTo(0, 50); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 208.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { inputGeom = new com.epl.geometry.Polyline(); inputGeom.StartPath(1.762614, 0.607368); inputGeom.LineTo(1.762414, 0.606655); inputGeom.LineTo(1.763006, 0.607034); inputGeom.LineTo(1.762548, 0.607135); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0.005, null); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
public virtual void TestBufferPolygon() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polygon inputGeom = new com.epl.geometry.Polygon(); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result == inputGeom); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 10, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 20 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 20 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 104.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.epl.geometry.SpatialReference.Create(4326); inputGeom = new com.epl.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -10, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 15.85) < 0.1 && System.Math.Abs(env2D.GetHeight() - 15.85) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 32.07) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 17.93) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.epl.geometry.SpatialReference.Create(4326); inputGeom = new com.epl.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(0, 50); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); inputGeom.StartPath(10, 10); inputGeom.LineTo(40, 10); inputGeom.LineTo(40, 40); inputGeom.LineTo(10, 40); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -2, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() + 4 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() + 4 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 2); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 108) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
internal static void ExportPolygonToWkt(int export_flags, com.epl.geometry.Polygon polygon, System.Text.StringBuilder @string) { com.epl.geometry.MultiPathImpl polygon_impl = (com.epl.geometry.MultiPathImpl)polygon._getImpl(); if ((export_flags & com.epl.geometry.WktExportFlags.wktExportFailIfNotSimple) != 0) { int simple = polygon_impl.GetIsSimple(0.0); if (simple != com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Strong) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } } int point_count = polygon.GetPointCount(); int polygon_count = polygon_impl.GetOGCPolygonCount(); if (point_count > 0 && polygon_count == 0) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } int precision = 17 - (7 & (export_flags >> 13)); bool b_export_zs = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripZs) == 0; bool b_export_ms = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripMs) == 0; int path_count = 0; com.epl.geometry.AttributeStreamOfDbl position = null; com.epl.geometry.AttributeStreamOfDbl zs = null; com.epl.geometry.AttributeStreamOfDbl ms = null; com.epl.geometry.AttributeStreamOfInt8 path_flags = null; com.epl.geometry.AttributeStreamOfInt32 paths = null; if (point_count > 0) { position = (com.epl.geometry.AttributeStreamOfDbl)(polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION)); path_flags = polygon_impl.GetPathFlagsStreamRef(); paths = polygon_impl.GetPathStreamRef(); path_count = polygon_impl.GetPathCount(); if (b_export_zs) { if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z)) { zs = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z); } } if (b_export_ms) { if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M)) { ms = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M); } } } if ((export_flags & com.epl.geometry.WktExportFlags.wktExportPolygon) != 0) { if (polygon_count > 1) { throw new System.ArgumentException("Cannot export a Polygon with specified export flags: " + export_flags); } PolygonTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, @string); } else { MultiPolygonTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_count, path_count, @string); } }
private static void ShowProjectedGeometryInfo(com.epl.geometry.MapGeometry mapGeom) { System.Console.Out.WriteLine("\n"); com.epl.geometry.MapGeometry geom = mapGeom; // while ((geom = geomCursor.next()) != null) { if (geom.GetGeometry() is com.epl.geometry.Point) { com.epl.geometry.Point pnt = (com.epl.geometry.Point)geom.GetGeometry(); System.Console.Out.WriteLine("Point(" + pnt.GetX() + " , " + pnt.GetY() + ")"); if (geom.GetSpatialReference() == null) { System.Console.Out.WriteLine("No spatial reference"); } else { System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } } else { if (geom.GetGeometry() is com.epl.geometry.MultiPoint) { com.epl.geometry.MultiPoint mp = (com.epl.geometry.MultiPoint)geom.GetGeometry(); System.Console.Out.WriteLine("Multipoint has " + mp.GetPointCount() + " points."); System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } else { if (geom.GetGeometry() is com.epl.geometry.Polygon) { com.epl.geometry.Polygon mp = (com.epl.geometry.Polygon)geom.GetGeometry(); System.Console.Out.WriteLine("Polygon has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts."); if (mp.GetPathCount() > 1) { System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1)); System.Console.Out.WriteLine("Part end of 2nd segment : " + mp.GetPathEnd(1)); System.Console.Out.WriteLine("Part size of 2nd segment : " + mp.GetPathSize(1)); int start = mp.GetPathStart(1); int end = mp.GetPathEnd(1); for (int i = start; i < end; i++) { com.epl.geometry.Point pp = mp.GetPoint(i); System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")"); } } System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } else { if (geom.GetGeometry() is com.epl.geometry.Polyline) { com.epl.geometry.Polyline mp = (com.epl.geometry.Polyline)geom.GetGeometry(); System.Console.Out.WriteLine("Polyline has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts."); System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1)); System.Console.Out.WriteLine("Part end of 2nd segment : " + mp.GetPathEnd(1)); System.Console.Out.WriteLine("Part size of 2nd segment : " + mp.GetPathSize(1)); int start = mp.GetPathStart(1); int end = mp.GetPathEnd(1); for (int i = start; i < end; i++) { com.epl.geometry.Point pp = mp.GetPoint(i); System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")"); } System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } } } } }
// Mirrors wkt private static void ExportPolygonToGeoJson_(int export_flags, com.epl.geometry.Polygon polygon, com.epl.geometry.JsonWriter json_writer) { com.epl.geometry.MultiPathImpl polygon_impl = (com.epl.geometry.MultiPathImpl)(polygon._getImpl()); if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportFailIfNotSimple) != 0) { int simple = polygon_impl.GetIsSimple(0.0); if (simple != com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Strong) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } } int point_count = polygon.GetPointCount(); int polygon_count = polygon_impl.GetOGCPolygonCount(); if (point_count > 0 && polygon_count == 0) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } int precision = 17 - (31 & (export_flags >> 13)); bool bFixedPoint = (com.epl.geometry.GeoJsonExportFlags.geoJsonExportPrecisionFixedPoint & export_flags) != 0; bool b_export_zs = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripZs) == 0; bool b_export_ms = polygon_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripMs) == 0; if (!b_export_zs && b_export_ms) { throw new System.ArgumentException("invalid argument"); } int path_count = 0; com.epl.geometry.AttributeStreamOfDbl position = null; com.epl.geometry.AttributeStreamOfDbl zs = null; com.epl.geometry.AttributeStreamOfDbl ms = null; com.epl.geometry.AttributeStreamOfInt8 path_flags = null; com.epl.geometry.AttributeStreamOfInt32 paths = null; if (point_count > 0) { position = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); path_flags = polygon_impl.GetPathFlagsStreamRef(); paths = polygon_impl.GetPathStreamRef(); path_count = polygon_impl.GetPathCount(); if (b_export_zs) { if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z)) { zs = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z); } } if (b_export_ms) { if (polygon_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M)) { ms = (com.epl.geometry.AttributeStreamOfDbl)polygon_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M); } } } if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportPreferMultiGeometry) == 0 && polygon_count <= 1) { PolygonTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, paths, path_count, json_writer); } else { MultiPolygonTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, polygon_count, path_count, json_writer); } }
internal virtual com.epl.geometry.Geometry TryFastIntersectPolylinePolygon_(com.epl.geometry.Polyline polyline, com.epl.geometry.Polygon polygon) { com.epl.geometry.MultiPathImpl polylineImpl = (com.epl.geometry.MultiPathImpl)polyline._getImpl(); com.epl.geometry.MultiPathImpl polygonImpl = (com.epl.geometry.MultiPathImpl)polygon._getImpl(); double tolerance = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(m_spatial_reference, polygon, false); com.epl.geometry.Envelope2D clipEnvelope = new com.epl.geometry.Envelope2D(); { polygonImpl.QueryEnvelope2D(clipEnvelope); com.epl.geometry.Envelope2D env1 = new com.epl.geometry.Envelope2D(); polylineImpl.QueryEnvelope2D(env1); env1.Inflate(2.0 * tolerance, 2.0 * tolerance); clipEnvelope.Intersect(env1); System.Diagnostics.Debug.Assert((!clipEnvelope.IsEmpty())); } clipEnvelope.Inflate(10 * tolerance, 10 * tolerance); if (true) { double tol = 0; com.epl.geometry.Geometry clippedPolyline = com.epl.geometry.Clipper.Clip(polyline, clipEnvelope, tol, 0.0); polyline = (com.epl.geometry.Polyline)clippedPolyline; polylineImpl = (com.epl.geometry.MultiPathImpl)polyline._getImpl(); } com.epl.geometry.AttributeStreamOfInt32 clipResult = new com.epl.geometry.AttributeStreamOfInt32(0); int unresolvedSegments = -1; com.epl.geometry.GeometryAccelerators accel = polygonImpl._getAccelerators(); if (accel != null) { com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry(); if (rgeom != null) { unresolvedSegments = 0; clipResult.Reserve(polylineImpl.GetPointCount() + polylineImpl.GetPathCount()); com.epl.geometry.Envelope2D seg_env = new com.epl.geometry.Envelope2D(); com.epl.geometry.SegmentIteratorImpl iter = polylineImpl.QuerySegmentIterator(); while (iter.NextPath()) { while (iter.HasNextSegment()) { com.epl.geometry.Segment seg = iter.NextSegment(); seg.QueryEnvelope2D(seg_env); com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryEnvelopeInGeometry(seg_env); if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside) { clipResult.Add(1); } else { if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside) { clipResult.Add(0); } else { clipResult.Add(-1); unresolvedSegments++; } } } } } } if (polygon.GetPointCount() > 5) { double tol = 0; com.epl.geometry.Geometry clippedPolygon = com.epl.geometry.Clipper.Clip(polygon, clipEnvelope, tol, 0.0); polygon = (com.epl.geometry.Polygon)clippedPolygon; polygonImpl = (com.epl.geometry.MultiPathImpl)polygon._getImpl(); accel = polygonImpl._getAccelerators(); } //update accelerators if (unresolvedSegments < 0) { unresolvedSegments = polylineImpl.GetSegmentCount(); } // Some heuristics to decide if it makes sense to go with fast intersect // vs going with the regular planesweep. double totalPoints = (double)(polylineImpl.GetPointCount() + polygonImpl.GetPointCount()); double thisAlgorithmComplexity = ((double)unresolvedSegments * polygonImpl.GetPointCount()); // assume the worst case. double planesweepComplexity = System.Math.Log(totalPoints) * totalPoints; double empiricConstantFactorPlaneSweep = 4; if (thisAlgorithmComplexity > planesweepComplexity * empiricConstantFactorPlaneSweep) { // Based on the number of input points, we deduced that the // plansweep performance should be better than the brute force // performance. return null; } // resort to planesweep if quadtree does not help com.epl.geometry.QuadTreeImpl polygonQuadTree = null; com.epl.geometry.SegmentIteratorImpl polygonIter = polygonImpl.QuerySegmentIterator(); // Some logic to decide if it makes sense to build a quadtree on the // polygon segments if (accel != null && accel.GetQuadTree() != null) { polygonQuadTree = accel.GetQuadTree(); } if (polygonQuadTree == null && polygonImpl.GetPointCount() > 20) { polygonQuadTree = com.epl.geometry.InternalUtils.BuildQuadTree(polygonImpl); } com.epl.geometry.Polyline result_polyline = (com.epl.geometry.Polyline)polyline.CreateInstance(); com.epl.geometry.MultiPathImpl resultPolylineImpl = (com.epl.geometry.MultiPathImpl)result_polyline._getImpl(); com.epl.geometry.QuadTreeImpl.QuadTreeIteratorImpl qIter = null; com.epl.geometry.SegmentIteratorImpl polylineIter = polylineImpl.QuerySegmentIterator(); double[] @params = new double[9]; com.epl.geometry.AttributeStreamOfDbl intersections = new com.epl.geometry.AttributeStreamOfDbl(0); com.epl.geometry.SegmentBuffer segmentBuffer = new com.epl.geometry.SegmentBuffer(); int start_index = -1; int inCount = 0; int segIndex = 0; bool bOptimized = clipResult.Size() > 0; // The algorithm is like that: // Loop through all the segments of the polyline. // For each polyline segment, intersect it with each of the polygon // segments. // If no intersections found then, // If the polyline segment is completely inside, it is added to the // result polyline. // If it is outside, it is thrown out. // If it intersects, then cut the polyline segment to pieces and test // each part of the intersected result. // The cut pieces will either have one point inside, or one point // outside, or the middle point inside/outside. // int polylinePathIndex = -1; while (polylineIter.NextPath()) { polylinePathIndex = polylineIter.GetPathIndex(); int stateNewPath = 0; int stateAddSegment = 1; int stateManySegments = 2; int stateManySegmentsContinuePath = 2; int stateManySegmentsNewPath = 3; int state = stateNewPath; start_index = -1; inCount = 0; while (polylineIter.HasNextSegment()) { int clipStatus = bOptimized ? (int)clipResult.Get(segIndex) : -1; segIndex++; com.epl.geometry.Segment polylineSeg = polylineIter.NextSegment(); if (clipStatus < 0) { System.Diagnostics.Debug.Assert((clipStatus == -1)); // Analyse polyline segment for intersection with the // polygon. if (polygonQuadTree != null) { if (qIter == null) { qIter = polygonQuadTree.GetIterator(polylineSeg, tolerance); } else { qIter.ResetIterator(polylineSeg, tolerance); } int path_index = -1; for (int ind = qIter.Next(); ind != -1; ind = qIter.Next()) { polygonIter.ResetToVertex(polygonQuadTree.GetElement(ind)); // path_index path_index = polygonIter.GetPathIndex(); com.epl.geometry.Segment polygonSeg = polygonIter.NextSegment(); // intersect polylineSeg and polygonSeg. int count = polylineSeg.Intersect(polygonSeg, null, @params, null, tolerance); for (int i = 0; i < count; i++) { intersections.Add(@params[i]); } } } else { // no quadtree built polygonIter.ResetToFirstPath(); while (polygonIter.NextPath()) { while (polygonIter.HasNextSegment()) { com.epl.geometry.Segment polygonSeg = polygonIter.NextSegment(); // intersect polylineSeg and polygonSeg. int count = polylineSeg.Intersect(polygonSeg, null, @params, null, tolerance); for (int i = 0; i < count; i++) { intersections.Add(@params[i]); } } } } if (intersections.Size() > 0) { // intersections detected. intersections.Sort(0, intersections.Size()); // std::sort(intersections.begin(), // intersections.end()); double t0 = 0; intersections.Add(1.0); int status = -1; for (int i = 0, n = intersections.Size(); i < n; i++) { double t = intersections.Get(i); if (t == t0) { continue; } bool bWholeSegment = false; com.epl.geometry.Segment resSeg; if (t0 != 0 || t != 1.0) { polylineSeg.Cut(t0, t, segmentBuffer); resSeg = segmentBuffer.Get(); } else { resSeg = polylineSeg; bWholeSegment = true; } if (state >= stateManySegments) { resultPolylineImpl.AddSegmentsFromPath(polylineImpl, polylinePathIndex, start_index, inCount, state == stateManySegmentsNewPath); if (AnalyseClipSegment_(polygon, resSeg.GetStartXY(), tolerance) != 1) { if (AnalyseClipSegment_(polygon, resSeg, tolerance) != 1) { return null; } } //someting went wrong we'll falback to slower but robust planesweep code. resultPolylineImpl.AddSegment(resSeg, false); state = stateAddSegment; inCount = 0; } else { status = AnalyseClipSegment_(polygon, resSeg, tolerance); switch (status) { case 1: { if (!bWholeSegment) { resultPolylineImpl.AddSegment(resSeg, state == stateNewPath); state = stateAddSegment; } else { if (state < stateManySegments) { start_index = polylineIter.GetStartPointIndex() - polylineImpl.GetPathStart(polylinePathIndex); inCount = 1; if (state == stateNewPath) { state = stateManySegmentsNewPath; } else { System.Diagnostics.Debug.Assert((state == stateAddSegment)); state = stateManySegmentsContinuePath; } } else { inCount++; } } break; } case 0: { state = stateNewPath; start_index = -1; inCount = 0; break; } default: { return null; } } } // may happen if a segment // coincides with the border. t0 = t; } } else { clipStatus = AnalyseClipSegment_(polygon, polylineSeg.GetStartXY(), tolerance); // simple // case // no // intersection. // Both // points // must // be // inside. if (clipStatus < 0) { System.Diagnostics.Debug.Assert((clipStatus >= 0)); return null; } // something goes wrong, resort to // planesweep System.Diagnostics.Debug.Assert((AnalyseClipSegment_(polygon, polylineSeg.GetEndXY(), tolerance) == clipStatus)); if (clipStatus == 1) { // the whole segment inside if (state < stateManySegments) { System.Diagnostics.Debug.Assert((inCount == 0)); start_index = polylineIter.GetStartPointIndex() - polylineImpl.GetPathStart(polylinePathIndex); if (state == stateNewPath) { state = stateManySegmentsNewPath; } else { System.Diagnostics.Debug.Assert((state == stateAddSegment)); state = stateManySegmentsContinuePath; } } inCount++; } else { System.Diagnostics.Debug.Assert((state < stateManySegments)); start_index = -1; inCount = 0; } } intersections.Clear(false); } else { // clip status is determined by other means if (clipStatus == 0) { // outside System.Diagnostics.Debug.Assert((AnalyseClipSegment_(polygon, polylineSeg, tolerance) == 0)); System.Diagnostics.Debug.Assert((start_index < 0)); System.Diagnostics.Debug.Assert((inCount == 0)); continue; } if (clipStatus == 1) { System.Diagnostics.Debug.Assert((AnalyseClipSegment_(polygon, polylineSeg, tolerance) == 1)); if (state == stateNewPath) { state = stateManySegmentsNewPath; start_index = polylineIter.GetStartPointIndex() - polylineImpl.GetPathStart(polylinePathIndex); } else { if (state == stateAddSegment) { state = stateManySegmentsContinuePath; start_index = polylineIter.GetStartPointIndex() - polylineImpl.GetPathStart(polylinePathIndex); } else { System.Diagnostics.Debug.Assert((state >= stateManySegments)); } } inCount++; continue; } } } if (state >= stateManySegments) { resultPolylineImpl.AddSegmentsFromPath(polylineImpl, polylinePathIndex, start_index, inCount, state == stateManySegmentsNewPath); start_index = -1; } } return result_polyline; }
internal static bool IsConvex_(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker) { if (geom.IsEmpty()) { return(true); } // vacuously true com.epl.geometry.Geometry.Type type = geom.GetType(); if (type == com.epl.geometry.Geometry.Type.Point) { return(true); } // vacuously true if (type == com.epl.geometry.Geometry.Type.Envelope) { com.epl.geometry.Envelope envelope = (com.epl.geometry.Envelope)geom; if (envelope.GetXMin() == envelope.GetXMax() || envelope.GetYMin() == envelope.GetYMax()) { return(false); } return(true); } if (com.epl.geometry.MultiPath.IsSegment(type.Value())) { com.epl.geometry.Segment segment = (com.epl.geometry.Segment)geom; if (segment.GetStartXY().Equals(segment.GetEndXY())) { return(false); } return(true); } // true, but we will upgrade to a Polyline for the ConvexHull operation if (type == com.epl.geometry.Geometry.Type.MultiPoint) { com.epl.geometry.MultiPoint multi_point = (com.epl.geometry.MultiPoint)geom; if (multi_point.GetPointCount() == 1) { return(true); } // vacuously true, but we will downgrade to a Point for the ConvexHull operation return(false); } if (type == com.epl.geometry.Geometry.Type.Polyline) { com.epl.geometry.Polyline polyline = (com.epl.geometry.Polyline)geom; if (polyline.GetPathCount() == 1 && polyline.GetPointCount() == 2) { if (!polyline.GetXY(0).Equals(polyline.GetXY(1))) { return(true); } } // vacuously true return(false); } // create convex hull com.epl.geometry.Polygon polygon = (com.epl.geometry.Polygon)geom; if (polygon.GetPathCount() != 1 || polygon.GetPointCount() < 3) { return(false); } return(com.epl.geometry.ConvexHull.IsPathConvex(polygon, 0, progress_tracker)); }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestPolygon() { bool bAnswer = true; com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(-97.06138, 32.837); polygon.LineTo(-97.06133, 32.836); polygon.LineTo(-97.06124, 32.834); polygon.LineTo(-97.06127, 32.832); polygon.StartPath(-97.06326, 32.759); polygon.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon)); com.epl.geometry.MapGeometry mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polygon.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(mPolygonWGS84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.Polygon p = new com.epl.geometry.Polygon(); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.StartPath(0, 0); p.LineTo(0, 1); p.LineTo(4, 4); p.StartPath(2, 2); p.LineTo(3, 3); p.LineTo(7, 8); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 7); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 5); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 5); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[[[0,0,3,null],[0,1,0,7],[4,4,0,5],[0,0,3,null]],[[2,2,0,null],[3,3,0,null],[7,8,0,5],[2,2,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { // Test Import Polygon from Polygon string rings = "{\"hasZ\": true, \"rings\" : [ [ [0,0, 5], [0.0, 10.0, 5], [10.0,10.0, 5, 66666], [10.0,0.0, 5] ], [ [12, 12] ], [ [13 , 17], [13 , 17] ], [ [1.0, 1.0, 5, 66666], [9.0,1.0, 5], [9.0,9.0, 5], [1.0,9.0, 5], [1.0, 1.0, 5] ] ] }"; com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(rings)); com.epl.geometry.Polygon p = (com.epl.geometry.Polygon)mapGeometry.GetGeometry(); double area = p.CalculateArea2D(); double length = p.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 4); int count = p.GetPointCount(); NUnit.Framework.Assert.IsTrue(count == 15); NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); } return(bAnswer); }
public static void TestClipGeometries() { // RandomTest(); com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Polygon polygon = MakePolygon(); com.epl.geometry.SimpleGeometryCursor polygonCurs = new com.epl.geometry.SimpleGeometryCursor(polygon); com.epl.geometry.Polyline polyline = MakePolyline(); com.epl.geometry.SimpleGeometryCursor polylineCurs = new com.epl.geometry.SimpleGeometryCursor(polyline); com.epl.geometry.MultiPoint multipoint = MakeMultiPoint(); com.epl.geometry.SimpleGeometryCursor multipointCurs = new com.epl.geometry.SimpleGeometryCursor(multipoint); com.epl.geometry.Point point = MakePoint(); com.epl.geometry.SimpleGeometryCursor pointCurs = new com.epl.geometry.SimpleGeometryCursor(point); com.epl.geometry.SpatialReference spatialRef = com.epl.geometry.SpatialReference.Create(3857); com.epl.geometry.Envelope2D envelope = new com.epl.geometry.Envelope2D(); envelope.xmin = 0; envelope.xmax = 20; envelope.ymin = 5; envelope.ymax = 15; // Cursor implementation com.epl.geometry.GeometryCursor clipPolygonCurs = clipOp.Execute(polygonCurs, envelope, spatialRef, null); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipPolygonCurs.Next(); double area = clippedPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Single Geometry implementation clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelope, spatialRef, null); area = clippedPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Cursor implementation com.epl.geometry.GeometryCursor clipPolylineCurs = clipOp.Execute(polylineCurs, envelope, spatialRef, null); com.epl.geometry.Polyline clippedPolyline = (com.epl.geometry.Polyline)clipPolylineCurs.Next(); double length = clippedPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10); // Single Geometry implementation clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(polyline, envelope, spatialRef, null); length = clippedPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10); // Cursor implementation com.epl.geometry.GeometryCursor clipMulti_pointCurs = clipOp.Execute(multipointCurs, envelope, spatialRef, null); com.epl.geometry.MultiPoint clipped_multi_point = (com.epl.geometry.MultiPoint)clipMulti_pointCurs.Next(); int pointCount = clipped_multi_point.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); // Cursor implementation com.epl.geometry.GeometryCursor clipPointCurs = clipOp.Execute(pointCurs, envelope, spatialRef, null); com.epl.geometry.Point clippedPoint = (com.epl.geometry.Point)clipPointCurs.Next(); NUnit.Framework.Assert.IsTrue(clippedPoint != null); // RandomTest(); com.epl.geometry.Polyline _poly = new com.epl.geometry.Polyline(); _poly.StartPath(2, 2); _poly.LineTo(0, 0); com.epl.geometry.Envelope2D _env = new com.epl.geometry.Envelope2D(); _env.SetCoords(2, 1, 5, 3); com.epl.geometry.Polyline _clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(_poly, _env, spatialRef, null); NUnit.Framework.Assert.IsTrue(_clippedPolyline.IsEmpty()); { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 100, 100), false); poly.AddEnvelope(new com.epl.geometry.Envelope2D(5, 5, 95, 95), true); com.epl.geometry.Polygon clippedPoly = (com.epl.geometry.Polygon)clipOp.Execute(poly, new com.epl.geometry.Envelope2D(-10, -10, 110, 50), spatialRef, null); NUnit.Framework.Assert.IsTrue(clippedPoly.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(clippedPoly.GetPointCount() == 8); } }