public virtual void TestEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.SetCoords(100, 200, 250, 300); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).IsEmpty()); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 1, 2); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmax == 2); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 0); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 3, 4); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 0); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 5, 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmax == 2); env.DropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(); env.CopyTo(env1); NUnit.Framework.Assert.IsFalse(env1.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); }
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)))")); }