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); }
/// <summary>Creates the symmetric difference of two geometries.</summary> /// <remarks> /// Creates the symmetric difference of two geometries. /// See OperatorSymmetricDifference. /// </remarks> /// <param name="leftGeometry">is one of the Geometry instances in the XOR operation.</param> /// <param name="rightGeometry">is one of the Geometry instances in the XOR operation.</param> /// <param name="spatialReference">The spatial reference of the geometries.</param> /// <returns>Returns the result of the symmetric difference.</returns> public static com.epl.geometry.Geometry SymmetricDifference(com.epl.geometry.Geometry leftGeometry, com.epl.geometry.Geometry rightGeometry, com.epl.geometry.SpatialReference spatialReference) { com.epl.geometry.OperatorSymmetricDifference op = (com.epl.geometry.OperatorSymmetricDifference)factory.GetOperator(com.epl.geometry.Operator.Type.SymmetricDifference); com.epl.geometry.Geometry result = op.Execute(leftGeometry, rightGeometry, spatialReference, null); return(result); }
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); } }