public static void testDifferenceAndSymmetricDifference() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorDifference differenceOp = (com.esri.core.geometry.OperatorDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.Difference); com.esri.core.geometry.SpatialReference spatialRef = com.esri.core.geometry.SpatialReference .create(102113); com.esri.core.geometry.Polygon polygon1 = makePolygon1(); com.esri.core.geometry.Polygon polygon2 = makePolygon2(); com.esri.core.geometry.Polyline polyline1 = makePolyline1(); com.esri.core.geometry.MultiPoint multipoint1 = makeMultiPoint1(); com.esri.core.geometry.MultiPoint multipoint2 = makeMultiPoint2(); com.esri.core.geometry.MultiPoint multipoint3 = makeMultiPoint3(); com.esri.core.geometry.Point point1 = makePoint1(); com.esri.core.geometry.Point point2 = makePoint2(); com.esri.core.geometry.Envelope envelope1 = makeEnvelope1(); com.esri.core.geometry.Envelope envelope2 = makeEnvelope2(); com.esri.core.geometry.Envelope envelope3 = makeEnvelope3(); com.esri.core.geometry.Polygon outputPolygon = (com.esri.core.geometry.Polygon)differenceOp .execute(polygon1, polygon2, spatialRef, null); double area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); { com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Geometry baseGeom = new com.esri.core.geometry.Point(point_1 .getX(), point_1.getY()); com.esri.core.geometry.Geometry comparisonGeom = new com.esri.core.geometry.Point (point_2.getX(), point2.getY()); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Geometry geom = differenceOp.execute(baseGeom, comparisonGeom , sr, null); } com.esri.core.geometry.OperatorSymmetricDifference symDifferenceOp = (com.esri.core.geometry.OperatorSymmetricDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference); outputPolygon = (com.esri.core.geometry.Polygon)symDifferenceOp.execute(polygon1, polygon2, spatialRef, null); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 150) <= 0.001); com.esri.core.geometry.Polyline outputPolyline = (com.esri.core.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.esri.core.geometry.MultiPoint outputMultiPoint = (com.esri.core.geometry.MultiPoint )differenceOp.execute(multipoint1, polygon1, spatialRef, null); int pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1 , point1, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1 , point2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 4); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , point1, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , point2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon1, envelope1 , spatialRef, null)); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon2, envelope2 , spatialRef, null)); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); outputPolyline = (com.esri.core.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.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint2 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 6); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint3 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 0); com.esri.core.geometry.Point outputPoint = (com.esri.core.geometry.Point)(differenceOp .execute(point1, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(!outputPoint.isEmpty()); outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point2, envelope2 , spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint.isEmpty()); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(envelope3, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty()); outputPolygon = (com.esri.core.geometry.Polygon)(symDifferenceOp.execute(envelope3 , envelope3, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty()); outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point1, polygon1 , spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint != null); }
public static void testPointTypes() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorDifference difference = (com.esri.core.geometry.OperatorDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.Difference); com.esri.core.geometry.OperatorSymmetricDifference sym_difference = (com.esri.core.geometry.OperatorSymmetricDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference); { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.000000009, 0.000000009); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.00000002, 0.00000002); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, point_1, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_2.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.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.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(1, 1); point_2.setXY(0.000000009, 0.000000009); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.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.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.create( 4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.isEmpty()); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(1, 1); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.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.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.create( 4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(multi_point_1, point_2, com.esri.core.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.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(0, 0); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.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.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.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.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.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.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); } { // multi_point/envelope com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.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.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, envelope_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty() && differenced_1 == multi_point_1 ); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.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.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty() && differenced_1 == multi_point_1 ); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.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.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polygon_2, com.esri.core.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.esri.core.geometry.Point)(difference.execute(point_1, polygon_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); point_1.setXY(0, 0); polygon_2.startPath(1, 0); polygon_2.lineTo(0, 1); polygon_2.lineTo(1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polygon_2, com.esri.core.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.esri.core.geometry.Point)(difference.execute(point_1, polygon_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); } { // point/envelope com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.geometry.Envelope( ); point_1.setXY(0, 0); envelope_2.setCoords(-1, -1, 1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, envelope_2, com.esri.core.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.esri.core.geometry.Point)(difference.execute(point_1, envelope_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polyline com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polyline polyline_2 = new com.esri.core.geometry.Polyline( ); point_1.setXY(0, 0); polyline_2.startPath(-1, 0); polyline_2.lineTo(1, 0); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polyline_2, com.esri.core.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.esri.core.geometry.Point)(difference.execute(point_1, polyline_2 , com.esri.core.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.esri.core.geometry.Point)(difference.execute(point_1, polyline_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } }