public static void TestWkbImportOnPostgresST() { try { java.sql.Connection con = java.sql.DriverManager.GetConnection("jdbc:postgresql://tb.esri.com:5432/new_gdb", "tb", "tb"); com.epl.geometry.OperatorFactoryLocal factory = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorImportFromWkb operatorImport = (com.epl.geometry.OperatorImportFromWkb)factory.GetOperator(com.epl.geometry.Operator.Type.ImportFromWkb); string stmt = "SELECT objectid,sde.st_asbinary(shape) FROM new_gdb.tb.interstates a WHERE objectid IN (2) AND (a.shape IS NULL OR sde.st_geometrytype(shape)::text IN ('ST_MULTILINESTRING','ST_LINESTRING')) LIMIT 1000"; java.sql.PreparedStatement ps = con.PrepareStatement(stmt); java.sql.ResultSet rs = ps.ExecuteQuery(); while (rs.Next()) { byte[] rsWkbGeom = rs.GetBytes(2); com.epl.geometry.Geometry geomBorg = null; if (rsWkbGeom != null) { geomBorg = operatorImport.Execute(0, com.epl.geometry.Geometry.Type.Unknown, System.IO.MemoryStream.Wrap(rsWkbGeom), null); } } ps.Close(); con.Close(); } catch (System.Exception) { } }
public static void TestPolygon9(com.epl.geometry.SpatialReference spatialReference) { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorCut opCut = (com.epl.geometry.OperatorCut)engine.GetOperator(com.epl.geometry.Operator.Type.Cut); com.epl.geometry.Polygon cut; int path_count; int point_count; double area; com.epl.geometry.Polygon polygon9 = MakePolygon9(); com.epl.geometry.Polyline cutter9 = MakePolygonCutter9(); com.epl.geometry.GeometryCursor cursor = opCut.Execute(false, polygon9, cutter9, spatialReference, null); cut = (com.epl.geometry.Polygon)cursor.Next(); path_count = cut.GetPathCount(); point_count = cut.GetPointCount(); area = cut.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(path_count == 3); NUnit.Framework.Assert.IsTrue(point_count == 12); NUnit.Framework.Assert.IsTrue(area == 150); cut = (com.epl.geometry.Polygon)cursor.Next(); path_count = cut.GetPathCount(); point_count = cut.GetPointCount(); area = cut.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(path_count == 3); NUnit.Framework.Assert.IsTrue(point_count == 12); NUnit.Framework.Assert.IsTrue(area == 150); cut = (com.epl.geometry.Polygon)cursor.Next(); NUnit.Framework.Assert.IsTrue(cut == null); }
public static void Test2() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorGeneralize op = (com.epl.geometry.OperatorGeneralize)engine.GetOperator(com.epl.geometry.Operator.Type.Generalize); com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(); polyline.StartPath(0, 0); polyline.LineTo(1, 1); polyline.LineTo(2, 0); polyline.LineTo(3, 2); polyline.LineTo(4, 1); polyline.LineTo(5, 0); polyline.LineTo(5, 10); polyline.LineTo(0, 10); com.epl.geometry.Geometry geom = op.Execute(polyline, 2, true, null); com.epl.geometry.Polyline p = (com.epl.geometry.Polyline)geom; com.epl.geometry.Point2D[] points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 4); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 0); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); NUnit.Framework.Assert.IsTrue(points[3].x == 0 && points[3].y == 10); com.epl.geometry.Geometry geom1 = op.Execute(geom, 5, false, null); p = (com.epl.geometry.Polyline)geom1; points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 2); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 0 && points[1].y == 10); geom1 = op.Execute(geom, 5, true, null); p = (com.epl.geometry.Polyline)geom1; points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 2); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 0 && points[1].y == 10); }
internal static com.epl.geometry.Geometry PolylineMinusArea_(com.epl.geometry.Geometry geometry, com.epl.geometry.Geometry area, int area_type, com.epl.geometry.SpatialReference sr, com.epl.geometry.ProgressTracker progress_tracker) { // construct the complement of the Polygon (or Envelope) com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope(); geometry.QueryEnvelope(envelope); com.epl.geometry.Envelope2D env_2D = new com.epl.geometry.Envelope2D(); area.QueryEnvelope2D(env_2D); envelope.Merge(env_2D); double dw = 0.1 * envelope.GetWidth(); double dh = 0.1 * envelope.GetHeight(); envelope.Inflate(dw, dh); com.epl.geometry.Polygon complement = new com.epl.geometry.Polygon(); complement.AddEnvelope(envelope, false); com.epl.geometry.MultiPathImpl complementImpl = (com.epl.geometry.MultiPathImpl)(complement._getImpl()); if (area_type == com.epl.geometry.Geometry.GeometryType.Polygon) { com.epl.geometry.MultiPathImpl polygonImpl = (com.epl.geometry.MultiPathImpl)(area._getImpl()); complementImpl.Add(polygonImpl, true); } else { complementImpl.AddEnvelope((com.epl.geometry.Envelope)(area), true); } com.epl.geometry.OperatorFactoryLocal projEnv = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorIntersection operatorIntersection = (com.epl.geometry.OperatorIntersection)projEnv.GetOperator(com.epl.geometry.Operator.Type.Intersection); com.epl.geometry.Geometry difference = operatorIntersection.Execute(geometry, complement, sr, progress_tracker); return(difference); }
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 static void TestGetXCorrectCR185697() { 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.Polyline polylineCR = MakePolylineCR(); com.epl.geometry.SimpleGeometryCursor polylineCursCR = new com.epl.geometry.SimpleGeometryCursor(polylineCR); com.epl.geometry.SpatialReference gcsWGS84 = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Envelope2D envelopeCR = new com.epl.geometry.Envelope2D(); envelopeCR.xmin = -180; envelopeCR.xmax = 180; envelopeCR.ymin = -90; envelopeCR.ymax = 90; // CR com.epl.geometry.Polyline clippedPolylineCR = (com.epl.geometry.Polyline)clipOp.Execute(polylineCR, envelopeCR, gcsWGS84, null); com.epl.geometry.Point pointResult = new com.epl.geometry.Point(); clippedPolylineCR.GetPointByVal(0, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == -180); clippedPolylineCR.GetPointByVal(1, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == -90); clippedPolylineCR.GetPointByVal(2, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 0); clippedPolylineCR.GetPointByVal(3, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 100); clippedPolylineCR.GetPointByVal(4, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 170); clippedPolylineCR.GetPointByVal(5, pointResult); NUnit.Framework.Assert.IsTrue(pointResult.GetX() == 180); }
public static void TestConsiderTouch2(com.epl.geometry.SpatialReference spatialReference) { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorCut opCut = (com.epl.geometry.OperatorCut)engine.GetOperator(com.epl.geometry.Operator.Type.Cut); com.epl.geometry.Polyline polyline2 = MakePolyline2(); com.epl.geometry.Polyline cutter2 = MakePolylineCutter2(); com.epl.geometry.GeometryCursor cursor = opCut.Execute(true, polyline2, cutter2, spatialReference, null); com.epl.geometry.Polyline cut; int pathCount; int segmentCount; double length; cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 4); NUnit.Framework.Assert.IsTrue(segmentCount == 4); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 5.74264068) <= 0.001); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 6); NUnit.Framework.Assert.IsTrue(segmentCount == 8); NUnit.Framework.Assert.IsTrue(length == 6.75); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 0.5) <= 0.001); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 0.25) <= 0.001); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 1) <= 0.001); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 1.41421356) <= 0.001); cut = (com.epl.geometry.Polyline)cursor.Next(); NUnit.Framework.Assert.IsTrue(cut == null); }
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 static void TestProximity2D_3() { com.epl.geometry.OperatorFactoryLocal factory = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorProximity2D proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(new com.epl.geometry.Point(-120, 22)); polygon.LineTo(new com.epl.geometry.Point(-120, 10)); polygon.LineTo(new com.epl.geometry.Point(-110, 10)); polygon.LineTo(new com.epl.geometry.Point(-110, 22)); com.epl.geometry.Point point = new com.epl.geometry.Point(); point.SetXY(-110, 20); com.epl.geometry.Proximity2DResult result = proximity.GetNearestCoordinate(polygon, point, false); com.epl.geometry.Point point2 = new com.epl.geometry.Point(); point2.SetXY(-120, 12); com.epl.geometry.Proximity2DResult[] results = proximity.GetNearestVertices(polygon, point2, 10, 12); }
public static void TestClipAttributes() { 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.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(30, 30); polygon.LineTo(60, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(10, 0, 50, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 100); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996); // 20.0 NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 20); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 40); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 80); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 100); } { 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, 40); polygon.LineTo(20, 40); polygon.LineTo(20, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 180); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(0, 10, 20, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 15); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 30); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 150); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 165); } }
public static void TestConsiderTouch1(com.epl.geometry.SpatialReference spatialReference) { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorCut opCut = (com.epl.geometry.OperatorCut)engine.GetOperator(com.epl.geometry.Operator.Type.Cut); com.epl.geometry.Polyline polyline1 = MakePolyline1(); com.epl.geometry.Polyline cutter1 = MakePolylineCutter1(); com.epl.geometry.GeometryCursor cursor = opCut.Execute(true, polyline1, cutter1, spatialReference, null); com.epl.geometry.Polyline cut; int pathCount; int segmentCount; double length; cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 4); NUnit.Framework.Assert.IsTrue(segmentCount == 4); NUnit.Framework.Assert.IsTrue(length == 6); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 6); NUnit.Framework.Assert.IsTrue(segmentCount == 8); NUnit.Framework.Assert.IsTrue(length == 12); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(length == 1); cut = (com.epl.geometry.Polyline)cursor.Next(); pathCount = cut.GetPathCount(); segmentCount = cut.GetSegmentCount(); length = cut.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(segmentCount == 1); NUnit.Framework.Assert.IsTrue(length == 1); cut = (com.epl.geometry.Polyline)cursor.Next(); NUnit.Framework.Assert.IsTrue(cut == null); }
public virtual void TestProximity_2D_1() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorProximity2D proximityOp = (com.epl.geometry.OperatorProximity2D)engine.GetOperator(com.epl.geometry.Operator.Type.Proximity2D); com.epl.geometry.Point inputPoint = new com.epl.geometry.Point(3, 2); com.epl.geometry.Point point0 = new com.epl.geometry.Point(2.75, 2); // Point point1 = new Point(3, 2.5); // Point point2 = new Point(3.75, 2); // Point point3 = new Point(2.25, 2.5); // Point point4 = new Point(4, 2.25); // GetNearestVertices for Polygon (Native and DotNet) com.epl.geometry.Polygon polygon = MakePolygon(); com.epl.geometry.Proximity2DResult[] resultArray = com.epl.geometry.GeometryEngine.GetNearestVertices(polygon, inputPoint, 2.0, 8); NUnit.Framework.Assert.IsTrue(resultArray.Length == 8); double lastdistance; double distance; com.epl.geometry.Proximity2DResult result0 = resultArray[0]; lastdistance = result0.GetDistance(); NUnit.Framework.Assert.IsTrue(lastdistance <= 2.0); com.epl.geometry.Proximity2DResult result1 = resultArray[1]; distance = result1.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result2 = resultArray[2]; distance = result2.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result3 = resultArray[3]; distance = result3.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result4 = resultArray[4]; distance = result4.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result5 = resultArray[5]; distance = result5.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result6 = resultArray[6]; distance = result6.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.epl.geometry.Proximity2DResult result7 = resultArray[7]; distance = result7.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); // lastdistance = distance; // Point[] coordinates = polygon.get.getCoordinates2D(); // int pointCount = polygon.getPointCount(); // // int hits = 0; // for (int i = 0; i < pointCount; i++) // { // Point ipoint = coordinates[i]; // distance = Point::Distance(ipoint, inputPoint); // // if (distance < lastdistance) // hits++; // } // assertTrue(hits < 8); // GetNearestVertices for Point com.epl.geometry.Point point = MakePoint(); resultArray = com.epl.geometry.GeometryEngine.GetNearestVertices(point, inputPoint, 1.0, 1); NUnit.Framework.Assert.IsTrue(resultArray.Length == 1); result0 = resultArray[0]; com.epl.geometry.Point resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY()); // GetNearestVertex for Polygon result0 = com.epl.geometry.GeometryEngine.GetNearestVertex(polygon, inputPoint); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point0.GetX() && resultPoint0.GetY() == point0.GetY()); // GetNearestVertex for Point result0 = com.epl.geometry.GeometryEngine.GetNearestVertex(point, inputPoint); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY()); // GetNearestCoordinate for Polygon com.epl.geometry.Polygon polygon2 = MakePolygon2(); result0 = com.epl.geometry.GeometryEngine.GetNearestCoordinate(polygon2, inputPoint, true); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == inputPoint.GetX() && resultPoint0.GetY() == inputPoint.GetY()); // GetNearestCoordinate for Polyline com.epl.geometry.Polyline polyline = MakePolyline(); result0 = com.epl.geometry.GeometryEngine.GetNearestCoordinate(polyline, inputPoint, true); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == 0.0 && resultPoint0.GetY() == 2.0); com.epl.geometry.Polygon pp = new com.epl.geometry.Polygon(); pp.StartPath(0, 0); pp.LineTo(0, 10); pp.LineTo(10, 10); pp.LineTo(10, 0); inputPoint.SetXY(15, -5); result0 = proximityOp.GetNearestCoordinate(pp, inputPoint, true, true); bool is_right = result0.IsRightSide(); NUnit.Framework.Assert.IsTrue(!is_right); }
public static void TestDifferenceAndSymmetricDifference() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorDifference differenceOp = (com.epl.geometry.OperatorDifference)engine.GetOperator(com.epl.geometry.Operator.Type.Difference); com.epl.geometry.SpatialReference spatialRef = com.epl.geometry.SpatialReference.Create(102113); com.epl.geometry.Polygon polygon1 = MakePolygon1(); com.epl.geometry.Polygon polygon2 = MakePolygon2(); com.epl.geometry.Polyline polyline1 = MakePolyline1(); com.epl.geometry.MultiPoint multipoint1 = MakeMultiPoint1(); com.epl.geometry.MultiPoint multipoint2 = MakeMultiPoint2(); com.epl.geometry.MultiPoint multipoint3 = MakeMultiPoint3(); com.epl.geometry.Point point1 = MakePoint1(); com.epl.geometry.Point point2 = MakePoint2(); com.epl.geometry.Envelope envelope1 = MakeEnvelope1(); com.epl.geometry.Envelope envelope2 = MakeEnvelope2(); com.epl.geometry.Envelope envelope3 = MakeEnvelope3(); com.epl.geometry.Polygon outputPolygon = (com.epl.geometry.Polygon)differenceOp.Execute(polygon1, polygon2, spatialRef, null); double area = outputPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001); { com.epl.geometry.Point point_1 = new com.epl.geometry.Point(-130, 10); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(-130, 10); com.epl.geometry.Geometry baseGeom = new com.epl.geometry.Point(point_1.GetX(), point_1.GetY()); com.epl.geometry.Geometry comparisonGeom = new com.epl.geometry.Point(point_2.GetX(), point2.GetY()); com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Geometry geom = differenceOp.Execute(baseGeom, comparisonGeom, sr, null); } com.epl.geometry.OperatorSymmetricDifference symDifferenceOp = (com.epl.geometry.OperatorSymmetricDifference)engine.GetOperator(com.epl.geometry.Operator.Type.SymmetricDifference); outputPolygon = (com.epl.geometry.Polygon)symDifferenceOp.Execute(polygon1, polygon2, spatialRef, null); area = outputPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 150) <= 0.001); com.epl.geometry.Polyline outputPolyline = (com.epl.geometry.Polyline)differenceOp.Execute(polyline1, polygon1, spatialRef, null); double length = outputPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length * length - 50) < 0.001); com.epl.geometry.MultiPoint outputMultiPoint = (com.epl.geometry.MultiPoint)differenceOp.Execute(multipoint1, polygon1, spatialRef, null); int pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.epl.geometry.MultiPoint)(symDifferenceOp.Execute(multipoint1, point1, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.epl.geometry.MultiPoint)(symDifferenceOp.Execute(multipoint1, point2, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 4); outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, point1, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, point2, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(polygon1, envelope1, spatialRef, null)); area = outputPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001); outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(polygon2, envelope2, spatialRef, null)); area = outputPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 75) <= 0.001); outputPolyline = (com.epl.geometry.Polyline)(differenceOp.Execute(polyline1, envelope2, spatialRef, null)); length = outputPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length * length - 50) <= 0.001); outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint1, envelope2, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint2, envelope2, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 6); outputMultiPoint = (com.epl.geometry.MultiPoint)(differenceOp.Execute(multipoint3, envelope2, spatialRef, null)); pointCount = outputMultiPoint.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 0); com.epl.geometry.Point outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point1, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(!outputPoint.IsEmpty()); outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point2, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint.IsEmpty()); outputPolygon = (com.epl.geometry.Polygon)(differenceOp.Execute(envelope3, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.IsEmpty()); outputPolygon = (com.epl.geometry.Polygon)(symDifferenceOp.Execute(envelope3, envelope3, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.IsEmpty()); outputPoint = (com.epl.geometry.Point)(differenceOp.Execute(point1, polygon1, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint != null); }
public static void TestPointTypes() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorDifference difference = (com.epl.geometry.OperatorDifference)engine.GetOperator(com.epl.geometry.Operator.Type.Difference); com.epl.geometry.OperatorSymmetricDifference sym_difference = (com.epl.geometry.OperatorSymmetricDifference)engine.GetOperator(com.epl.geometry.Operator.Type.SymmetricDifference); { // point/point com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.000000009, 0.000000009); com.epl.geometry.Point differenced = (com.epl.geometry.Point)(difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.IsEmpty()); com.epl.geometry.MultiPoint sym_differenced = (com.epl.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // point/point com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.000000009, 0.0); com.epl.geometry.Point differenced = (com.epl.geometry.Point)(difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.IsEmpty()); com.epl.geometry.MultiPoint sym_differenced = (com.epl.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // point/point com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.00000002, 0.00000002); com.epl.geometry.Point differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); com.epl.geometry.Point differenced_2 = (com.epl.geometry.Point)(difference.Execute(point_2, point_1, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_2.IsEmpty()); com.epl.geometry.MultiPoint sym_differenced = (com.epl.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.IsEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(0).x == 0 && sym_differenced.GetXY(0).y == 0); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(1).x == 0.00000002 && sym_differenced.GetXY(1).y == 0.00000002); } { // multi_point/point com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); point_2.SetXY(0.000000009, 0.000000009); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 1 && differenced_1.GetXY(0).y == 1); com.epl.geometry.Point differenced_2 = (com.epl.geometry.Point)(difference.Execute(point_2, multi_point_1, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.IsEmpty()); } { // multi_point/point com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); point_2.SetXY(0.000000009, 0.0); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 1.0 && differenced_1.GetXY(0).y == 1.0); com.epl.geometry.Point differenced_2 = (com.epl.geometry.Point)(difference.Execute(point_2, multi_point_1, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.IsEmpty()); com.epl.geometry.MultiPoint sym_differenced = (com.epl.geometry.MultiPoint)(sym_difference.Execute(multi_point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.IsEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(0).x == 1 && sym_differenced.GetXY(0).y == 1); } { // multi_point/point com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Point point_2 = new com.epl.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); point_2.SetXY(0.000000009, 0.0); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); com.epl.geometry.MultiPoint sym_differenced = (com.epl.geometry.MultiPoint)(sym_difference.Execute(multi_point_1, point_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // multi_point/polygon com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Polygon polygon_2 = new com.epl.geometry.Polygon(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); multi_point_1.Add(2, 2); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 2 && differenced_1.GetXY(0).y == 2); } { // multi_point/polygon com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Polygon polygon_2 = new com.epl.geometry.Polygon(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); } { // multi_point/envelope com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Envelope envelope_2 = new com.epl.geometry.Envelope(); multi_point_1.Add(-2, 0); multi_point_1.Add(0, 2); multi_point_1.Add(2, 0); multi_point_1.Add(0, -2); envelope_2.SetCoords(-1, -1, 1, 1); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, envelope_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty() && differenced_1 == multi_point_1); } { // multi_point/polygon com.epl.geometry.MultiPoint multi_point_1 = new com.epl.geometry.MultiPoint(); com.epl.geometry.Polygon polygon_2 = new com.epl.geometry.Polygon(); multi_point_1.Add(2, 2); multi_point_1.Add(2, 2); multi_point_1.Add(-2, -2); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.epl.geometry.MultiPoint differenced_1 = (com.epl.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty() && differenced_1 == multi_point_1); } { // point/polygon com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Polygon polygon_2 = new com.epl.geometry.Polygon(); point_1.SetXY(0, 0); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.epl.geometry.Point differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); polygon_2.SetEmpty(); polygon_2.StartPath(1, 1); polygon_2.LineTo(1, 2); polygon_2.LineTo(2, 2); polygon_2.LineTo(2, 1); differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polygon com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Polygon polygon_2 = new com.epl.geometry.Polygon(); point_1.SetXY(0, 0); polygon_2.StartPath(1, 0); polygon_2.LineTo(0, 1); polygon_2.LineTo(1, 1); com.epl.geometry.Point differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); point_1.SetEmpty(); point_1.SetXY(0.5, 0.5); polygon_2.SetEmpty(); polygon_2.StartPath(1, 0); polygon_2.LineTo(0, 1); polygon_2.LineTo(1, 1); differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polygon_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); } { // point/envelope com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Envelope envelope_2 = new com.epl.geometry.Envelope(); point_1.SetXY(0, 0); envelope_2.SetCoords(-1, -1, 1, 1); com.epl.geometry.Point differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, envelope_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); envelope_2.SetEmpty(); envelope_2.SetCoords(1, 1, 2, 2); differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, envelope_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polyline com.epl.geometry.Point point_1 = new com.epl.geometry.Point(); com.epl.geometry.Polyline polyline_2 = new com.epl.geometry.Polyline(); point_1.SetXY(0, 0); polyline_2.StartPath(-1, 0); polyline_2.LineTo(1, 0); com.epl.geometry.Point differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polyline_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); polyline_2.SetEmpty(); polyline_2.StartPath(1, 0); polyline_2.LineTo(2, 0); differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polyline_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); polyline_2.SetEmpty(); polyline_2.StartPath(-1, -1); polyline_2.LineTo(-1, 1); polyline_2.LineTo(1, 1); polyline_2.LineTo(1, -1); differenced_1 = (com.epl.geometry.Point)(difference.Execute(point_1, polyline_2, com.epl.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } }
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); } }