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); } }
public static void TestImportExportWktMultiPolygon() { com.esri.core.geometry.OperatorImportFromWkt importerWKT = (com.esri.core.geometry.OperatorImportFromWkt)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromWkt); com.esri.core.geometry.OperatorExportToWkt exporterWKT = (com.esri.core.geometry.OperatorExportToWkt)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToWkt); com.esri.core.geometry.Polygon polygon; string wktString; com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D(); com.esri.core.geometry.WktParser wktParser = new com.esri.core.geometry.WktParser(); // Test Import from MultiPolygon wktString = "Multipolygon M empty"; polygon = (com.esri.core.geometry.Polygon)importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.IsEmpty()); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); polygon = (com.esri.core.geometry.Polygon)com.esri.core.geometry.GeometryEngine.GeometryFromWkt(wktString, 0, com.esri.core.geometry.Geometry.Type.Unknown); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.IsEmpty()); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); wktString = exporterWKT.Execute(0, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON M EMPTY")); wktString = com.esri.core.geometry.GeometryEngine.GeometryToWkt(polygon, 0); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON M EMPTY")); wktString = "Multipolygon Z (empty, (empty, (10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3), empty, (10 10 1, 12 12 1)), empty, ((90 90 88, 60 90 7, 60 60 7), empty, (70 70 7, 80 80 7, 70 80 7, 70 70 7)), empty)"; polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); polygon.QueryEnvelope2D(envelope); NUnit.Framework.Assert.IsTrue(envelope.xmin == 10 && envelope.xmax == 90 && envelope.ymin == 10 && envelope.ymax == 90); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 14); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 5); // assertTrue(polygon.calculate_area_2D() > 0.0); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); double z = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0); NUnit.Framework.Assert.IsTrue(z == 5); // Test Export to WKT MultiPolygon wktString = exporterWKT.Execute(0, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3, 12 12 3, 12 12 3), (10 10 1, 12 12 1, 10 10 1)), ((90 90 88, 60 90 7, 60 60 7, 90 90 88), (70 70 7, 70 80 7, 80 80 7, 70 70 7)))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } // Test import Polygon wktString = "POLYGON z (EMPTY, EMPTY, (10 10 5, 10 20 5, 20 20 5, 20 10 5), (12 12 3), EMPTY, (10 10 1, 12 12 1), EMPTY, (60 60 7, 60 90 7, 90 90 7, 60 60 7), EMPTY, (70 70 7, 70 80 7, 80 80 7), EMPTY)"; polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 14); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 5); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); // Test Export to WKT Polygon wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportPolygon, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z ((10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3, 12 12 3, 12 12 3), (10 10 1, 12 12 1, 10 10 1), (60 60 7, 60 90 7, 90 90 7, 60 60 7), (70 70 7, 70 80 7, 80 80 7, 70 70 7))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); polygon.QueryEnvelope(env); wktString = exporterWKT.Execute(0, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z ((10 10 1, 90 10 7, 90 90 1, 10 90 7, 10 10 1))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((10 10 1, 90 10 7, 90 90 1, 10 90 7, 10 10 1)))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } env.SetEmpty(); wktString = exporterWKT.Execute(0, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z EMPTY")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z EMPTY")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = "MULTIPOLYGON (((5 10, 8 10, 10 10, 10 0, 0 0, 0 10, 2 10, 5 10)))"; // ring // is // oriented // clockwise polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.CalculateArea2D() > 0); wktString = "MULTIPOLYGON Z (((90 10 7, 10 10 1, 10 90 7, 90 90 1, 90 10 7)))"; // ring // is // oriented // clockwise polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 4); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(polygon.CalculateArea2D() > 0); wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((90 10 7, 90 90 1, 10 90 7, 10 10 1, 90 10 7)))")); }