public virtual void TestPolygon() { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(-97.06138, 32.837); polygon.LineTo(-97.06133, 32.836); polygon.LineTo(-97.06124, 32.834); polygon.LineTo(-97.06127, 32.832); polygon.StartPath(-97.06326, 32.759); polygon.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon)); com.epl.geometry.MapGeometry mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polygon.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); com.epl.geometry.Polygon emptyPolygon = new com.epl.geometry.Polygon(); string emptyPolygonString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyPolygon); polygonPathsWgs84Parser = factory.CreateJsonParser(emptyPolygonString); mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(mPolygonWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); } }
public virtual void TestMP2onCR175871() { com.epl.geometry.Polygon pg = new com.epl.geometry.Polygon(); pg.StartPath(-50, 10); pg.LineTo(-50, 12); pg.LineTo(-45, 12); pg.LineTo(-45, 10); com.epl.geometry.Polygon pg1 = new com.epl.geometry.Polygon(); pg1.StartPath(-45, 10); pg1.LineTo(-40, 10); pg1.LineTo(-40, 8); pg.Add(pg1, false); com.epl.geometry.SpatialReference spatialReference = com.epl.geometry.SpatialReference.Create(4326); try { string jSonStr = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReference, pg); com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jp = jf.CreateJsonParser(jSonStr); jp.NextToken(); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp); com.epl.geometry.Geometry gm = mg.GetGeometry(); NUnit.Framework.Assert.AreEqual(com.epl.geometry.Geometry.Type.Polygon, gm.GetType()); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 4326); com.epl.geometry.Polygon pgNew = (com.epl.geometry.Polygon)gm; NUnit.Framework.Assert.AreEqual(pgNew.GetPathCount(), pg.GetPathCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetPointCount(), pg.GetPointCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetSegmentCount(), pg.GetSegmentCount()); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(0).GetX(), pg.GetPoint(0).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetX(), pg.GetPoint(1).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetX(), pg.GetPoint(2).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetX(), pg.GetPoint(3).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(0).GetY(), pg.GetPoint(0).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetY(), pg.GetPoint(1).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetY(), pg.GetPoint(2).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetY(), pg.GetPoint(3).GetY(), 0.000000001); } catch (System.Exception ex) { string err = ex.Message; System.Console.Out.Write(err); throw; } }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestPolygon() { bool bAnswer = true; com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(-97.06138, 32.837); polygon.LineTo(-97.06133, 32.836); polygon.LineTo(-97.06124, 32.834); polygon.LineTo(-97.06127, 32.832); polygon.StartPath(-97.06326, 32.759); polygon.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon)); com.epl.geometry.MapGeometry mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polygon.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(mPolygonWGS84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.Polygon p = new com.epl.geometry.Polygon(); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.StartPath(0, 0); p.LineTo(0, 1); p.LineTo(4, 4); p.StartPath(2, 2); p.LineTo(3, 3); p.LineTo(7, 8); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 7); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 5); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 5); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[[[0,0,3,null],[0,1,0,7],[4,4,0,5],[0,0,3,null]],[[2,2,0,null],[3,3,0,null],[7,8,0,5],[2,2,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { // Test Import Polygon from Polygon string rings = "{\"hasZ\": true, \"rings\" : [ [ [0,0, 5], [0.0, 10.0, 5], [10.0,10.0, 5, 66666], [10.0,0.0, 5] ], [ [12, 12] ], [ [13 , 17], [13 , 17] ], [ [1.0, 1.0, 5, 66666], [9.0,1.0, 5], [9.0,9.0, 5], [1.0,9.0, 5], [1.0, 1.0, 5] ] ] }"; com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(rings)); com.epl.geometry.Polygon p = (com.epl.geometry.Polygon)mapGeometry.GetGeometry(); double area = p.CalculateArea2D(); double length = p.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 4); int count = p.GetPointCount(); NUnit.Framework.Assert.IsTrue(count == 15); NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); } return(bAnswer); }
private static void ShowProjectedGeometryInfo(com.epl.geometry.MapGeometry mapGeom) { System.Console.Out.WriteLine("\n"); com.epl.geometry.MapGeometry geom = mapGeom; // while ((geom = geomCursor.next()) != null) { if (geom.GetGeometry() is com.epl.geometry.Point) { com.epl.geometry.Point pnt = (com.epl.geometry.Point)geom.GetGeometry(); System.Console.Out.WriteLine("Point(" + pnt.GetX() + " , " + pnt.GetY() + ")"); if (geom.GetSpatialReference() == null) { System.Console.Out.WriteLine("No spatial reference"); } else { System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } } else { if (geom.GetGeometry() is com.epl.geometry.MultiPoint) { com.epl.geometry.MultiPoint mp = (com.epl.geometry.MultiPoint)geom.GetGeometry(); System.Console.Out.WriteLine("Multipoint has " + mp.GetPointCount() + " points."); System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } else { if (geom.GetGeometry() is com.epl.geometry.Polygon) { com.epl.geometry.Polygon mp = (com.epl.geometry.Polygon)geom.GetGeometry(); System.Console.Out.WriteLine("Polygon has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts."); if (mp.GetPathCount() > 1) { System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1)); System.Console.Out.WriteLine("Part end of 2nd segment : " + mp.GetPathEnd(1)); System.Console.Out.WriteLine("Part size of 2nd segment : " + mp.GetPathSize(1)); int start = mp.GetPathStart(1); int end = mp.GetPathEnd(1); for (int i = start; i < end; i++) { com.epl.geometry.Point pp = mp.GetPoint(i); System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")"); } } System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } else { if (geom.GetGeometry() is com.epl.geometry.Polyline) { com.epl.geometry.Polyline mp = (com.epl.geometry.Polyline)geom.GetGeometry(); System.Console.Out.WriteLine("Polyline has " + mp.GetPointCount() + " points and " + mp.GetPathCount() + " parts."); System.Console.Out.WriteLine("Part start of 2nd segment : " + mp.GetPathStart(1)); System.Console.Out.WriteLine("Part end of 2nd segment : " + mp.GetPathEnd(1)); System.Console.Out.WriteLine("Part size of 2nd segment : " + mp.GetPathSize(1)); int start = mp.GetPathStart(1); int end = mp.GetPathEnd(1); for (int i = start; i < end; i++) { com.epl.geometry.Point pp = mp.GetPoint(i); System.Console.Out.WriteLine("Point(" + i + ") = (" + pp.GetX() + ", " + pp.GetY() + ")"); } System.Console.Out.WriteLine("wkid: " + geom.GetSpatialReference().GetID()); } } } } }