/// <summary>The output of this method can be only used for debugging.</summary> /// <remarks>The output of this method can be only used for debugging. It is subject to change without notice.</remarks> // public override string ToString() // { // string snippet = com.epl.geometry.OperatorExportToJson.Local().Execute(GetSpatialReference(), GetGeometry()); // if (snippet.Length > 200) // { // return snippet.Substring(0, 197 - 0) + "... (" + snippet.Length + " characters)"; // } // else // { // return snippet; // } // } public override bool Equals(object other) { if (other == null) { return(false); } if (other == this) { return(true); } if (other.GetType() != GetType()) { return(false); } com.epl.geometry.MapGeometry omg = (com.epl.geometry.MapGeometry)other; com.epl.geometry.SpatialReference sr = GetSpatialReference(); com.epl.geometry.Geometry g = GetGeometry(); com.epl.geometry.SpatialReference osr = omg.GetSpatialReference(); com.epl.geometry.Geometry og = omg.GetGeometry(); if (sr != osr) { if (sr == null || !sr.Equals(osr)) { return(false); } } if (g != og) { if (g == null || !g.Equals(og)) { return(false); } } return(true); }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestCR181369() { // CR181369 bool bAnswer = true; string jsonStringPointAndWKT = "{\"x\":10.0,\"y\":20.0,\"spatialReference\":{\"wkt\" : \"PROJCS[\\\"NAD83_UTM_zone_15N\\\",GEOGCS[\\\"GCS_North_American_1983\\\",DATUM[\\\"D_North_American_1983\\\",SPHEROID[\\\"GRS_1980\\\",6378137.0,298.257222101]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]],PROJECTION[\\\"Transverse_Mercator\\\"],PARAMETER[\\\"false_easting\\\",500000.0],PARAMETER[\\\"false_northing\\\",0.0],PARAMETER[\\\"central_meridian\\\",-93.0],PARAMETER[\\\"scale_factor\\\",0.9996],PARAMETER[\\\"latitude_of_origin\\\",0.0],UNIT[\\\"Meter\\\",1.0]]\"} }"; com.fasterxml.jackson.core.JsonParser jsonParserPointAndWKT = factory.CreateParser(jsonStringPointAndWKT); com.epl.geometry.MapGeometry mapGeom2 = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPointAndWKT); string jsonStringPointAndWKT2 = com.epl.geometry.GeometryEngine.GeometryToJson(mapGeom2.GetSpatialReference(), mapGeom2.GetGeometry()); com.fasterxml.jackson.core.JsonParser jsonParserPointAndWKT2 = factory.CreateParser(jsonStringPointAndWKT2); com.epl.geometry.MapGeometry mapGeom3 = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPointAndWKT2); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Point)mapGeom2.GetGeometry()).GetX() == ((com.epl.geometry.Point)mapGeom3.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Point)mapGeom2.GetGeometry()).GetY() == ((com.epl.geometry.Point)mapGeom3.GetGeometry()).GetY()); string s1 = mapGeom2.GetSpatialReference().GetText(); string s2 = mapGeom3.GetSpatialReference().GetText(); NUnit.Framework.Assert.IsTrue(s1.Equals(s2)); int id2 = mapGeom2.GetSpatialReference().GetID(); int id3 = mapGeom3.GetSpatialReference().GetID(); NUnit.Framework.Assert.IsTrue(id2 == id3); if (!CheckResultSpatialRef(mapGeom3, mapGeom2.GetSpatialReference().GetID(), 0)) { bAnswer = false; } return(bAnswer); }
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 TestGeometryToJSONOldID() { // CR com.epl.geometry.Polygon geom = new com.epl.geometry.Polygon(); geom.StartPath(new com.epl.geometry.Point(-113, 34)); geom.LineTo(new com.epl.geometry.Point(-105, 34)); geom.LineTo(new com.epl.geometry.Point(-108, 40)); string outputPolygon = com.epl.geometry.GeometryEngine.GeometryToJson(com.epl.geometry.SpatialReference.Create(3857), geom); // Test // WKID // == // -1 string correctPolygon = "{\"rings\":[[[-113,34],[-105,34],[-108,40],[-113,34]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; NUnit.Framework.Assert.IsTrue(outputPolygon.Equals(correctPolygon)); com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jp = jf.CreateJsonParser(outputPolygon); jp.NextToken(); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp); int srId = mg.GetSpatialReference().GetID(); int srOldId = mg.GetSpatialReference().GetOldID(); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 3857); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetLatestID() == 3857); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetOldID() == 102100); }
internal virtual bool CheckResultSpatialRef(com.epl.geometry.MapGeometry mapGeometry, int expectWki1, int expectWki2) { com.epl.geometry.SpatialReference sr = mapGeometry.GetSpatialReference(); string Wkt = sr.GetText(); int wki1 = sr.GetLatestID(); if (!(wki1 == expectWki1 || wki1 == expectWki2)) { return(false); } if (!(Wkt != null && Wkt.Length > 0)) { return(false); } com.epl.geometry.SpatialReference sr2 = com.epl.geometry.SpatialReference.Create(Wkt); int wki2 = sr2.GetID(); if (expectWki2 > 0) { if (!(wki2 == expectWki1 || wki2 == expectWki2)) { return(false); } } else { if (!(wki2 == expectWki1)) { return(false); } } return(true); }
public virtual void TestMultiPoint() { com.epl.geometry.MultiPoint multiPoint1 = new com.epl.geometry.MultiPoint(); multiPoint1.Add(-97.06138, 32.837); multiPoint1.Add(-97.06133, 32.836); multiPoint1.Add(-97.06124, 32.834); multiPoint1.Add(-97.06127, 32.832); { com.fasterxml.jackson.core.JsonParser mPointWgs84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, multiPoint1)); com.epl.geometry.MapGeometry mPointWgs84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(mPointWgs84Parser); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPointCount() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(0).GetX() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(0).GetY() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(0).GetY()); int lastIndex = multiPoint1.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(lastIndex).GetX() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(lastIndex).GetY() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPointWgs84MP.GetSpatialReference().GetID()); com.epl.geometry.MultiPoint mPointEmpty = new com.epl.geometry.MultiPoint(); string mPointEmptyString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, mPointEmpty); mPointWgs84Parser = factory.CreateJsonParser(mPointEmptyString); mPointWgs84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(mPointWgs84Parser); NUnit.Framework.Assert.IsTrue(mPointWgs84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPointWgs84MP.GetSpatialReference().GetID()); } }
public virtual void TestWKB2() { // JSON -> GEOM -> WKB // String strPolygon1 = // "{\"xmin\":-1.16605115291E7,\"ymin\":4925189.941699997,\"xmax\":-1.16567772126E7,\"ymax\":4928658.771399997,\"spatialReference\":{\"wkid\":102100}}"; string strPolygon1 = "{\"rings\" : [ [ [-1.16605115291E7,4925189.941699997], [-1.16567772126E7,4925189.941699997], [-1.16567772126E7,4928658.771399997], [-1.16605115291E7,4928658.771399997], [-1.16605115291E7,4925189.941699997] ] ], \"spatialReference\" : {\"wkid\" : 102100}}"; com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(strPolygon1); com.epl.geometry.Geometry geom = mapGeom.GetGeometry(); // simplifying geom com.epl.geometry.OperatorSimplify operatorSimplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(102100); geom = operatorSimplify.Execute(geom, sr, true, null); com.epl.geometry.OperatorExportToWkb operatorExport = (com.epl.geometry.OperatorExportToWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ExportToWkb); System.IO.MemoryStream byteBuffer = operatorExport.Execute(0, geom, null); byte[] wkb = ((byte[])byteBuffer.Array()); // // checking WKB correctness // WKBReader jtsReader = new WKBReader(); // com.vividsolutions.jts.geom.Geometry jtsGeom = jtsReader.read(wkb); // System.out.println("jtsGeom = " + jtsGeom); // WKB -> GEOM -> JSON com.epl.geometry.OperatorImportFromWkb operatorImport = (com.epl.geometry.OperatorImportFromWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ImportFromWkb); geom = operatorImport.Execute(0, com.epl.geometry.Geometry.Type.Polygon, System.IO.MemoryStream.Wrap(wkb), null); NUnit.Framework.Assert.IsTrue(!geom.IsEmpty()); }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestMultiPoint() { bool bAnswer = true; com.epl.geometry.MultiPoint multiPoint1 = new com.epl.geometry.MultiPoint(); multiPoint1.Add(-97.06138, 32.837); multiPoint1.Add(-97.06133, 32.836); multiPoint1.Add(-97.06124, 32.834); multiPoint1.Add(-97.06127, 32.832); { string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, multiPoint1); com.fasterxml.jackson.core.JsonParser mPointWgs84Parser = factory.CreateParser(s); com.epl.geometry.MapGeometry mPointWgs84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(mPointWgs84Parser); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPointCount() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(0).GetX() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(0).GetY() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(0).GetY()); int lastIndex = multiPoint1.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(lastIndex).GetX() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(multiPoint1.GetPoint(lastIndex).GetY() == ((com.epl.geometry.MultiPoint)mPointWgs84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPointWgs84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(mPointWgs84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.MultiPoint p = new com.epl.geometry.MultiPoint(); 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,\"points\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.Add(10.0, 20.0, 30.0); p.Add(20.0, 40.0, 60.0); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"points\":[[10,20,30,null],[20,40,60,null]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { string points = "{\"hasM\" : false, \"hasZ\" : true, \"uncle remus\" : null, \"points\" : [ [0,0,1], [0.0,10.0,1], [10.0,10.0,1], [10.0,0.0,1, 6666] ],\"spatialReference\" : {\"wkid\" : 4326}}"; com.epl.geometry.MapGeometry mp = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(points)); com.epl.geometry.MultiPoint multipoint = (com.epl.geometry.MultiPoint)mp.GetGeometry(); NUnit.Framework.Assert.IsTrue(multipoint.GetPointCount() == 4); com.epl.geometry.Point2D point2d; point2d = multipoint.GetXY(0); NUnit.Framework.Assert.IsTrue(point2d.x == 0.0 && point2d.y == 0.0); point2d = multipoint.GetXY(1); NUnit.Framework.Assert.IsTrue(point2d.x == 0.0 && point2d.y == 10.0); point2d = multipoint.GetXY(2); NUnit.Framework.Assert.IsTrue(point2d.x == 10.0 && point2d.y == 10.0); point2d = multipoint.GetXY(3); NUnit.Framework.Assert.IsTrue(point2d.x == 10.0 && point2d.y == 0.0); NUnit.Framework.Assert.IsTrue(multipoint.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(!multipoint.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); double z = multipoint.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0); NUnit.Framework.Assert.IsTrue(z == 1); com.epl.geometry.SpatialReference spatial_reference = mp.GetSpatialReference(); NUnit.Framework.Assert.IsTrue(spatial_reference.GetID() == 4326); } return(bAnswer); }
public virtual void TestOldCRS() { string inputStr = "{\"type\":\"Polygon\",\"coordinates\":[[[-180,-90],[180,-90],[180,90],[-180,90],[-180,-90]]], \"crs\":\"EPSG:4267\"}"; com.epl.geometry.MapGeometry mg = com.epl.geometry.OperatorImportFromGeoJson.Local().Execute(com.epl.geometry.GeoJsonImportFlags.geoJsonImportDefaults, com.epl.geometry.Geometry.Type.Unknown, inputStr, null); string result = com.epl.geometry.GeometryEngine.GeometryToGeoJson(mg.GetSpatialReference(), mg.GetGeometry()); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[-180,-90],[180,-90],[180,90],[-180,90],[-180,-90]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4267\"}}}", result); }
public virtual void Test3DPoint() { string jsonString3DPt = "{\"x\" : -118.15, \"y\" : 33.80, \"z\" : 10.0, \"spatialReference\" : {\"wkid\" : 4326}}"; com.fasterxml.jackson.core.JsonParser jsonParser3DPt = factory.CreateParser(jsonString3DPt); com.epl.geometry.MapGeometry point3DMP = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParser3DPt); NUnit.Framework.Assert.IsTrue(-118.15 == ((com.epl.geometry.Point)point3DMP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(33.80 == ((com.epl.geometry.Point)point3DMP.GetGeometry()).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == point3DMP.GetSpatialReference().GetID()); }
public virtual void Test3DPoint2() { { com.epl.geometry.Point point1 = new com.epl.geometry.Point(10.0, 20.0); com.fasterxml.jackson.core.JsonParser pointWebMerc2Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc2, point1)); com.epl.geometry.MapGeometry pointWebMerc2MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc2Parser); NUnit.Framework.Assert.IsTrue(point1.GetX() == ((com.epl.geometry.Point)pointWebMerc2MP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(point1.GetY() == ((com.epl.geometry.Point)pointWebMerc2MP.GetGeometry()).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWebMerc2.GetLatestID() == pointWebMerc2MP.GetSpatialReference().GetLatestID()); } }
public static void TestContainsFailureCR186456() { string str = "{\"rings\":[[[406944.399999999,287461.450000001],[406947.750000011,287462.299999997],[406946.44999999,287467.450000001],[406943.050000005,287466.550000005],[406927.799999992,287456.849999994],[406926.949999996,287456.599999995],[406924.800000005,287455.999999998],[406924.300000007,287455.849999999],[406924.200000008,287456.099999997],[406923.450000011,287458.449999987],[406922.999999987,287459.800000008],[406922.29999999,287462.099999998],[406921.949999991,287463.449999992],[406921.449999993,287465.050000011],[406920.749999996,287466.700000004],[406919.800000001,287468.599999996],[406919.050000004,287469.99999999],[406917.800000009,287471.800000008],[406916.04999999,287473.550000001],[406915.449999993,287473.999999999],[406913.700000001,287475.449999993],[406913.300000002,287475.899999991],[406912.050000008,287477.250000011],[406913.450000002,287478.150000007],[406915.199999994,287478.650000005],[406915.999999991,287478.800000005],[406918.300000007,287479.200000003],[406920.649999997,287479.450000002],[406923.100000013,287479.550000001],[406925.750000001,287479.450000002],[406928.39999999,287479.150000003],[406929.80000001,287478.950000004],[406932.449999998,287478.350000006],[406935.099999987,287477.60000001],[406938.699999998,287476.349999989],[406939.649999994,287473.949999999],[406939.799999993,287473.949999999],[406941.249999987,287473.75],[406942.700000007,287473.250000002],[406943.100000005,287473.100000003],[406943.950000001,287472.750000004],[406944.799999998,287472.300000006],[406944.999999997,287472.200000007],[406946.099999992,287471.200000011],[406946.299999991,287470.950000012],[406948.00000001,287468.599999996],[406948.10000001,287468.399999997],[406950.100000001,287465.050000011],[406951.949999993,287461.450000001],[406952.049999993,287461.300000001],[406952.69999999,287459.900000007],[406953.249999987,287458.549999987],[406953.349999987,287458.299999988],[406953.650000012,287457.299999992],[406953.900000011,287456.349999996],[406954.00000001,287455.300000001],[406954.00000001,287454.750000003],[406953.850000011,287453.750000008],[406953.550000012,287452.900000011],[406953.299999987,287452.299999988],[406954.500000008,287450.299999996],[406954.00000001,287449.000000002],[406953.399999987,287447.950000006],[406953.199999988,287447.550000008],[406952.69999999,287446.850000011],[406952.149999992,287446.099999988],[406951.499999995,287445.499999991],[406951.149999996,287445.249999992],[406950.449999999,287444.849999994],[406949.600000003,287444.599999995],[406949.350000004,287444.549999995],[406948.250000009,287444.499999995],[406947.149999987,287444.699999994],[406946.849999989,287444.749999994],[406945.899999993,287444.949999993],[406944.999999997,287445.349999991],[406944.499999999,287445.64999999],[406943.650000003,287446.349999987],[406942.900000006,287447.10000001],[406942.500000008,287447.800000007],[406942.00000001,287448.700000003],[406941.600000011,287449.599999999],[406941.350000013,287450.849999994],[406941.350000013,287451.84999999],[406941.450000012,287452.850000012],[406941.750000011,287453.850000007],[406941.800000011,287454.000000007],[406942.150000009,287454.850000003],[406942.650000007,287455.6],[406943.150000005,287456.299999997],[406944.499999999,287457.299999992],[406944.899999997,287457.599999991],[406945.299999995,287457.949999989],[406944.399999999,287461.450000001],[406941.750000011,287461.999999998],[406944.399999999,287461.450000001]],[[406944.399999999,287461.450000001],[406947.750000011,287462.299999997],[406946.44999999,287467.450000001],[406943.050000005,287466.550000005],[406927.799999992,287456.849999994],[406944.399999999,287461.450000001]]]}"; com.fasterxml.jackson.core.JsonFactory jsonFactory = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jsonParser = jsonFactory.CreateParser(str); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParser); bool res = com.epl.geometry.GeometryEngine.Contains(mg.GetGeometry(), mg.GetGeometry(), null); NUnit.Framework.Assert.IsTrue(res); }
public virtual void TestPolygonWithEmptyWKT_NoWKI() { string jsonStringPg = "{ \"rings\" :[ [ [-97.06138,32.837], [-97.06133,32.836], " + "[-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ], " + "[ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ]], " + "\"spatialReference\" : {\"wkt\" : \"\"}}"; com.fasterxml.jackson.core.JsonParser jsonParserPg = factory.CreateParser(jsonStringPg); jsonParserPg.NextToken(); com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPg); com.epl.geometry.Utils.ShowProjectedGeometryInfo(mapGeom); com.epl.geometry.SpatialReference sr = mapGeom.GetSpatialReference(); NUnit.Framework.Assert.IsTrue(sr == null); }
public virtual void TestOnlyWKI() { string jsonStringSR = "{\"wkid\" : 4326}"; com.fasterxml.jackson.core.JsonParser jsonParserSR = factory.CreateJsonParser(jsonStringSR); jsonParserSR.NextToken(); com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserSR); com.epl.geometry.Utils.ShowProjectedGeometryInfo(mapGeom); com.epl.geometry.SpatialReference sr = mapGeom.GetSpatialReference(); NUnit.Framework.Assert.IsTrue(sr == null); }
public virtual void TestEmptyPolygon() { com.epl.geometry.Polygon p = new com.epl.geometry.Polygon(); com.epl.geometry.OperatorExportToGeoJson exporter = (com.epl.geometry.OperatorExportToGeoJson)factory.GetOperator(com.epl.geometry.Operator.Type.ExportToGeoJson); string result = exporter.Execute(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[]}", result); com.epl.geometry.MapGeometry imported = com.epl.geometry.OperatorImportFromGeoJson.Local().Execute(0, com.epl.geometry.Geometry.Type.Unknown, result, null); NUnit.Framework.Assert.IsTrue(imported.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(imported.GetGeometry().GetType() == com.epl.geometry.Geometry.Type.Polygon); }
public virtual void TestMultiPolygon() { com.fasterxml.jackson.core.JsonFactory jsonFactory = new com.fasterxml.jackson.core.JsonFactory(); //String geoJsonPolygon = "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100,-100],[-100,100],[100,100],[100,-100],[-100,-100]],[[-90,-90],[90,90],[-90,90],[90,-90],[-90,-90]]],[[[-10.0,-10.0],[-10.0,10.0],[10.0,10.0],[10.0,-10.0],[-10.0,-10.0]]]]}"; string esriJsonPolygon = "{\"rings\": [[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[-90, -90], [90, 90], [-90, 90], [90, -90], [-90, -90]], [[-10, -10], [-10, 10], [10, 10], [10, -10], [-10, -10]]]}"; com.fasterxml.jackson.core.JsonParser parser = jsonFactory.CreateParser(esriJsonPolygon); com.epl.geometry.MapGeometry parsedPoly = com.epl.geometry.GeometryEngine.JsonToGeometry(parser); //MapGeometry parsedPoly = GeometryEngine.geometryFromGeoJson(jsonPolygon, 0, Geometry.Type.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)parsedPoly.GetGeometry(); com.epl.geometry.OperatorExportToGeoJson exporter = (com.epl.geometry.OperatorExportToGeoJson)factory.GetOperator(com.epl.geometry.Operator.Type.ExportToGeoJson); //String result = exporter.execute(parsedPoly.getGeometry()); string result = exporter.Execute(poly); NUnit.Framework.Assert.AreEqual("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100,-100],[100,-100],[100,100],[-100,100],[-100,-100]],[[-90,-90],[90,-90],[-90,90],[90,90],[-90,-90]]],[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]]}", result); }
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; } }
public virtual void TestWKB() { // JSON -> GEOM -> WKB string strPolygon1 = "{\"xmin\":-1.1663479012889031E7,\"ymin\":4919777.494405342,\"xmax\":-1.1658587043078788E7,\"ymax\":4924669.464215587,\"spatialReference\":{\"wkid\":102100}}"; // String strPolygon1 = // "{\"rings\":[[[-119.152450421001,38.4118009590513],[-119.318825070203,38.5271086243914],[-119.575687062955,38.7029101298904],[-119.889341639399,38.9222515603984],[-119.995254694357,38.9941061536377],[-119.995150114198,39.0634913594691],[-119.994541258334,39.1061318056708],[-119.995527335641,39.1587132866355],[-119.995304181493,39.3115454332125],[-119.996011479298,39.4435009764511],[-119.996165311172,39.7206108077274],[-119.996324660047,41.1775662656441],[-119.993459369715,41.9892049531992],[-119.351692186077,41.9888529749781],[-119.3109421304,41.9891353872811],[-118.185316829038,41.9966370981387],[-117.018864363596,41.9947941808341],[-116.992313337997,41.9947945094663],[-115.947544658193,41.9945994628997],[-115.024862911148,41.996506455953],[-114.269471632824,41.9959242345073],[-114.039072662345,41.9953908974688],[-114.038151248682,40.9976868405942],[-114.038108189376,40.1110466529553],[-114.039844684228,39.9087788600023],[-114.040105338584,39.5386849268845],[-114.044267501155,38.6789958815881],[-114.045090206153,38.5710950539539],[-114.047272999176,38.1376524399918],[-114.047260595159,37.5984784866001],[-114.043939384154,36.9965379371421],[-114.043716435713,36.8418489458647],[-114.037392074194,36.2160228969702],[-114.045105557286,36.1939778840226],[-114.107775185788,36.1210907070504],[-114.12902308363,36.041730493896],[-114.206768869568,36.0172554164834],[-114.233472615347,36.0183310595897],[-114.307587598189,36.0622330993643],[-114.303857056018,36.0871084040611],[-114.316095374696,36.1114380366653],[-114.344233941709,36.1374802520568],[-114.380803116644,36.1509912717765],[-114.443945697733,36.1210532841897],[-114.466613475422,36.1247112590539],[-114.530573568745,36.1550902046725],[-114.598935242024,36.1383354528834],[-114.621610747198,36.1419666834504],[-114.712761724737,36.1051810523675],[-114.728150311069,36.0859627711604],[-114.728966012834,36.0587530361083],[-114.717673567756,36.0367580437018],[-114.736212493583,35.9876483502758],[-114.699275906446,35.9116119537412],[-114.661600122152,35.8804735854242],[-114.662462095522,35.8709599070091],[-114.689867343369,35.8474424944766],[-114.682739704595,35.7647034175617],[-114.688820027649,35.7325957399896],[-114.665091345861,35.6930994107107],[-114.668486064922,35.6563989882404],[-114.654065925137,35.6465840800053],[-114.6398667219,35.6113485698329],[-114.653134321223,35.5848331056108],[-114.649792053474,35.5466373866597],[-114.672215155693,35.5157541647721],[-114.645396168451,35.4507608261463],[-114.589584275424,35.3583787306827],[-114.587889840369,35.30476812919],[-114.559583045727,35.2201828714608],[-114.561039964054,35.1743461616313],[-114.572255261053,35.1400677445931],[-114.582616239058,35.1325604694085],[-114.626440825485,35.1339067529872],[-114.6359090842,35.1186557767895],[-114.595631971944,35.0760579746697],[-114.633779872695,35.0418633504303],[-114.621068606189,34.9989144286133],[-115.626197382816,35.7956983148418],[-115.88576934392,36.0012259572723],[-117.160423771838,36.9595941441767],[-117.838686423167,37.457298239715],[-118.417419755966,37.8866767486211],[-119.152450421001,38.4118009590513]]], \"spatialReference\":{\"wkid\":4326}}"; com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(strPolygon1); com.epl.geometry.Geometry geom = mapGeom.GetGeometry(); com.epl.geometry.OperatorExportToWkb operatorExport = (com.epl.geometry.OperatorExportToWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ExportToWkb); System.IO.MemoryStream byteBuffer = operatorExport.Execute(0, geom, null); byte[] wkb = ((byte[])byteBuffer.Array()); // WKB -> GEOM -> JSON com.epl.geometry.OperatorImportFromWkb operatorImport = (com.epl.geometry.OperatorImportFromWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ImportFromWkb); geom = operatorImport.Execute(0, com.epl.geometry.Geometry.Type.Polygon, System.IO.MemoryStream.Wrap(wkb), null); // geom = operatorImport.execute(0, Geometry.Type.Polygon, // byteBuffer); string outputPolygon1 = com.epl.geometry.GeometryEngine.GeometryToJson(-1, geom); }
public virtual void TestEnvelope() { com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope(); envelope.SetCoords(-109.55, 25.76, -86.39, 49.94); { com.fasterxml.jackson.core.JsonParser envelopeWGS84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, envelope)); com.epl.geometry.MapGeometry envelopeWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelope.IsEmpty() == envelopeWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(envelope.GetXMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMax()); NUnit.Framework.Assert.IsTrue(envelope.GetYMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMax()); NUnit.Framework.Assert.IsTrue(envelope.GetXMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMin()); NUnit.Framework.Assert.IsTrue(envelope.GetYMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMin()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == envelopeWGS84MP.GetSpatialReference().GetID()); com.epl.geometry.Envelope emptyEnvelope = new com.epl.geometry.Envelope(); string emptyEnvString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyEnvelope); envelopeWGS84Parser = factory.CreateJsonParser(emptyEnvString); envelopeWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelopeWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == envelopeWGS84MP.GetSpatialReference().GetID()); } }
public virtual void Test3DPoint1() { com.epl.geometry.Point point1 = new com.epl.geometry.Point(10.0, 20.0); com.epl.geometry.Point pointEmpty = new com.epl.geometry.Point(); { com.fasterxml.jackson.core.JsonParser pointWebMerc1Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, point1)); com.epl.geometry.MapGeometry pointWebMerc1MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc1Parser); NUnit.Framework.Assert.IsTrue(point1.GetX() == ((com.epl.geometry.Point)pointWebMerc1MP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(point1.GetY() == ((com.epl.geometry.Point)pointWebMerc1MP.GetGeometry()).GetY()); int srIdOri = spatialReferenceWebMerc1.GetID(); int srIdAfter = pointWebMerc1MP.GetSpatialReference().GetID(); NUnit.Framework.Assert.IsTrue(srIdOri == srIdAfter || srIdAfter == 3857); pointWebMerc1Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(null, point1)); pointWebMerc1MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc1Parser); NUnit.Framework.Assert.IsTrue(null == pointWebMerc1MP.GetSpatialReference()); string pointEmptyString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, pointEmpty); pointWebMerc1Parser = factory.CreateJsonParser(pointEmptyString); pointWebMerc1MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc1Parser); NUnit.Framework.Assert.IsTrue(pointWebMerc1MP.GetGeometry().IsEmpty()); int srIdOri2 = spatialReferenceWebMerc1.GetID(); int srIdAfter2 = pointWebMerc1MP.GetSpatialReference().GetID(); NUnit.Framework.Assert.IsTrue(srIdOri2 == srIdAfter2 || srIdAfter2 == 3857); } }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestPolyline() { bool bAnswer = true; com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(); polyline.StartPath(-97.06138, 32.837); polyline.LineTo(-97.06133, 32.836); polyline.LineTo(-97.06124, 32.834); polyline.LineTo(-97.06127, 32.832); polyline.StartPath(-97.06326, 32.759); polyline.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polylinePathsWgs84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polyline)); com.epl.geometry.MapGeometry mPolylineWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polylinePathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polyline.GetPointCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polyline.GetPoint(0).GetX() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polyline.GetPoint(0).GetY() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polyline.GetPathCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount(0) == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polyline.GetSegmentCount(1) == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polyline.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polyline.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polyline.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polyline)mPolylineWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolylineWGS84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(mPolylineWGS84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.Polyline p = new com.epl.geometry.Polyline(); 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,\"paths\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.StartPath(0, 0); p.LineTo(0, 1); p.StartPath(2, 2); p.LineTo(3, 3); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 5); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"paths\":[[[0,0,3,null],[0,1,0,5]],[[2,2,0,null],[3,3,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { string paths = "{\"hasZ\" : true, \"paths\" : [ [ [0.0, 0.0,3], [0, 10.0,3], [10.0, 10.0,3, 6666], [10.0, 0.0,3, 6666] ], [ [1.0, 1,3], [1.0, 9.0,3], [9.0, 9.0,3], [1.0, 9.0,3] ] ], \"spatialReference\" : {\"wkid\" : 4326}, \"hasM\" : false}"; com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(paths)); com.epl.geometry.Polyline p = (com.epl.geometry.Polyline)mapGeometry.GetGeometry(); NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 2); int count = p.GetPathCount(); NUnit.Framework.Assert.IsTrue(p.GetPointCount() == 8); NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); double z = p.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0); NUnit.Framework.Assert.IsTrue(z == 3); double length = p.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 54.0) <= 0.001); com.epl.geometry.SpatialReference spatial_reference = mapGeometry.GetSpatialReference(); NUnit.Framework.Assert.IsTrue(spatial_reference.GetID() == 4326); } return(bAnswer); }
internal static void ShowProjectedGeometryInfo(com.epl.geometry.MapGeometry mapGeom) { return; }
public virtual void TestSpatialRef() { // String jsonStringPt = // "{\"x\":-20037508.342787,\"y\":20037508.342787},\"spatialReference\":{\"wkid\":102100}}"; string jsonStringPt = "{\"x\":10.0,\"y\":20.0,\"spatialReference\":{\"wkid\": 102100}}"; // 102100 string jsonStringPt2 = "{\"x\":10.0,\"y\":20.0,\"spatialReference\":{\"wkid\":4326}}"; string jsonStringMpt = "{ \"points\" : [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], \"spatialReference\" : {\"wkid\" : 4326}}"; // 4326 string jsonStringMpt3D = "{\"hasZs\" : true,\"points\" : [ [-97.06138,32.837,35.0], [-97.06133,32.836,35.1], [-97.06124,32.834,35.2], [-97.06127,32.832,35.3] ],\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringPl = "{\"paths\" : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], [ [-97.06326,32.759], [-97.06298,32.755] ]],\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringPl3D = "{\"hasMs\" : true,\"paths\" : [[ [-97.06138,32.837,5], [-97.06133,32.836,6], [-97.06124,32.834,7], [-97.06127,32.832,8] ],[ [-97.06326,32.759], [-97.06298,32.755] ]],\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringPg = "{ \"rings\" :[ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ], [ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ]], \"spatialReference\" : {\"wkt\" : \"\"}}"; string jsonStringPg3D = "{\"hasZs\" : true,\"hasMs\" : true,\"rings\" : [ [ [-97.06138, 32.837, 35.1, 4], [-97.06133, 32.836, 35.2, 4.1], [-97.06124, 32.834, 35.3, 4.2], [-97.06127, 32.832, 35.2, 44.3], [-97.06138, 32.837, 35.1, 4] ],[ [-97.06326, 32.759, 35.4], [-97.06298, 32.755, 35.5], [-97.06153, 32.749, 35.6], [-97.06326, 32.759, 35.4] ]],\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringPg2 = "{ \"spatialReference\" : {\"wkid\" : 4326}, \"rings\" : [[[-118.35,32.81],[-118.42,32.806],[-118.511,32.892],[-118.35,32.81]]]}"; string jsonStringPg3 = "{ \"spatialReference\": {\"layerName\":\"GAS_POINTS\",\"name\":null,\"sdesrid\":102100,\"wkid\":102100,\"wkt\":null}}"; string jsonString2SpatialReferences = "{ \"spatialReference\": {\"layerName\":\"GAS_POINTS\",\"name\":null,\"sdesrid\":102100,\"wkid\":102100,\"wkt\":\"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137,298.257223563]],PRIMEM[\\\"Greenwich\\\",0],UNIT[\\\"Degree\\\",0.017453292519943295]]\"}}"; string jsonString2SpatialReferences2 = "{ \"spatialReference\": {\"layerName\":\"GAS_POINTS\",\"name\":null,\"sdesrid\":10,\"wkid\":10,\"wkt\":\"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137,298.257223563]],PRIMEM[\\\"Greenwich\\\",0],UNIT[\\\"Degree\\\",0.017453292519943295]]\"}}"; string jsonStringSR = "{\"wkid\" : 4326}"; string jsonStringEnv = "{\"xmin\" : -109.55, \"ymin\" : 25.76, \"xmax\" : -86.39, \"ymax\" : 49.94,\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringHongKon = "{\"xmin\" : -122.55, \"ymin\" : 37.65, \"xmax\" : -122.28, \"ymax\" : 37.84,\"spatialReference\" : {\"wkid\" : 4326}}"; string jsonStringWKT = " {\"wkt\" : \"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137,298.257223563]],PRIMEM[\\\"Greenwich\\\",0],UNIT[\\\"Degree\\\",0.017453292519943295]]\"}"; string jsonStringInvalidWKID = "{\"x\":10.0,\"y\":20.0},\"spatialReference\":{\"wkid\":35253523}}"; string jsonStringOregon = "{\"xmin\":7531831.219849482,\"ymin\":585702.9799639136,\"xmax\":7750143.589982405,\"ymax\":733289.6299999952,\"spatialReference\":{\"wkid\":102726}}"; com.fasterxml.jackson.core.JsonParser jsonParserPt = factory.CreateJsonParser(jsonStringPt); com.fasterxml.jackson.core.JsonParser jsonParserMpt = factory.CreateJsonParser(jsonStringMpt); com.fasterxml.jackson.core.JsonParser jsonParserMpt3D = factory.CreateJsonParser(jsonStringMpt3D); com.fasterxml.jackson.core.JsonParser jsonParserPl = factory.CreateJsonParser(jsonStringPl); com.fasterxml.jackson.core.JsonParser jsonParserPl3D = factory.CreateJsonParser(jsonStringPl3D); com.fasterxml.jackson.core.JsonParser jsonParserPg = factory.CreateJsonParser(jsonStringPg); com.fasterxml.jackson.core.JsonParser jsonParserPg3D = factory.CreateJsonParser(jsonStringPg3D); com.fasterxml.jackson.core.JsonParser jsonParserPg2 = factory.CreateJsonParser(jsonStringPg2); com.fasterxml.jackson.core.JsonParser jsonParserSR = factory.CreateJsonParser(jsonStringSR); com.fasterxml.jackson.core.JsonParser jsonParserEnv = factory.CreateJsonParser(jsonStringEnv); com.fasterxml.jackson.core.JsonParser jsonParserPg3 = factory.CreateJsonParser(jsonStringPg3); com.fasterxml.jackson.core.JsonParser jsonParserCrazy1 = factory.CreateJsonParser(jsonString2SpatialReferences); com.fasterxml.jackson.core.JsonParser jsonParserCrazy2 = factory.CreateJsonParser(jsonString2SpatialReferences2); com.fasterxml.jackson.core.JsonParser jsonParserInvalidWKID = factory.CreateJsonParser(jsonStringInvalidWKID); com.fasterxml.jackson.core.JsonParser jsonParseHongKon = factory.CreateJsonParser(jsonStringHongKon); com.fasterxml.jackson.core.JsonParser jsonParseOregon = factory.CreateJsonParser(jsonStringOregon); com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPt); // showProjectedGeometryInfo(mapGeom); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 102100); com.epl.geometry.MapGeometry mapGeomOregon = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParseOregon); NUnit.Framework.Assert.IsTrue(mapGeomOregon.GetSpatialReference().GetID() == 102726); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserMpt); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 4326); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserMpt3D); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 4326); { NUnit.Framework.Assert.IsTrue(((com.epl.geometry.MultiPoint)mapGeom.GetGeometry()).GetPoint(0).GetX() == -97.06138); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.MultiPoint)mapGeom.GetGeometry()).GetPoint(0).GetY() == 32.837); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.MultiPoint)mapGeom.GetGeometry()).GetPoint(3).GetX() == -97.06127); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.MultiPoint)mapGeom.GetGeometry()).GetPoint(3).GetY() == 32.832); } // showProjectedGeometryInfo(mapGeom); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPl); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 4326); // showProjectedGeometryInfo(mapGeom); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPl3D); { // [[ [-97.06138,32.837,5], [-97.06133,32.836,6], // [-97.06124,32.834,7], [-97.06127,32.832,8] ], // [ [-97.06326,32.759], [-97.06298,32.755] ]]"; NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(0).GetX() == -97.06138); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(0).GetY() == 32.837); int lastIndex = ((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(lastIndex).GetX() == -97.06298); // -97.06153, // 32.749 NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(lastIndex).GetY() == 32.755); int lastIndexFirstLine = ((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPathEnd(0) - 1; NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(lastIndexFirstLine).GetX() == -97.06127); // -97.06153, // 32.749 NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polyline)mapGeom.GetGeometry()).GetPoint(lastIndexFirstLine).GetY() == 32.832); } mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPg); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference() == null); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPg3D); { NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polygon)mapGeom.GetGeometry()).GetPoint(0).GetX() == -97.06138); NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polygon)mapGeom.GetGeometry()).GetPoint(0).GetY() == 32.837); int lastIndex = ((com.epl.geometry.Polygon)mapGeom.GetGeometry()).GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polygon)mapGeom.GetGeometry()).GetPoint(lastIndex).GetX() == -97.06153); // -97.06153, // 32.749 NUnit.Framework.Assert.IsTrue(((com.epl.geometry.Polygon)mapGeom.GetGeometry()).GetPoint(lastIndex).GetY() == 32.749); } mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPg2); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 4326); // showProjectedGeometryInfo(mapGeom); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserPg3); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 102100); // showProjectedGeometryInfo(mapGeom); // mapGeom = GeometryEngine.jsonToGeometry(jsonParserCrazy1); // Assert.assertTrue(mapGeom.getSpatialReference().getText().equals("")); // showProjectedGeometryInfo(mapGeom); mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserEnv); NUnit.Framework.Assert.IsTrue(mapGeom.GetSpatialReference().GetID() == 4326); // showProjectedGeometryInfo(mapGeom); try { com.epl.geometry.GeometryEngine.JsonToGeometry(jsonParserInvalidWKID); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue("Should not throw for invalid wkid", false); } }
public SimpleMapGeometryCursor(com.epl.geometry.MapGeometry geom) { m_geom = geom; m_index = -1; m_count = 1; }
public static com.epl.geometry.ogc.OGCGeometry FromJson(string @string) { com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(com.epl.geometry.JsonParserReader.CreateFromString(@string)); return(com.epl.geometry.ogc.OGCGeometry.CreateFromEsriGeometry(mapGeom.GetGeometry(), mapGeom.GetSpatialReference())); }
internal static com.epl.geometry.MapGeometry ImportFromJsonParser(int gt, com.epl.geometry.JsonReader parser) { com.epl.geometry.MapGeometry mp; try { if (!com.epl.geometry.JSONUtils.IsObjectStart(parser)) { return(null); } bool bFoundSpatial_reference = false; bool bFoundHasZ = false; bool bFoundHasM = false; bool bFoundPolygon = false; bool bFoundPolyline = false; bool bFoundMultiPoint = false; bool bFoundX = false; bool bFoundY = false; bool bFoundZ = false; bool bFoundM = false; bool bFoundXMin = false; bool bFoundYMin = false; bool bFoundXMax = false; bool bFoundYMax = false; bool bFoundZMin = false; bool bFoundZMax = false; bool bFoundMMin = false; bool bFoundMMax = false; double x = com.epl.geometry.NumberUtils.NaN(); double y = com.epl.geometry.NumberUtils.NaN(); double z = com.epl.geometry.NumberUtils.NaN(); double m = com.epl.geometry.NumberUtils.NaN(); double xmin = com.epl.geometry.NumberUtils.NaN(); double ymin = com.epl.geometry.NumberUtils.NaN(); double xmax = com.epl.geometry.NumberUtils.NaN(); double ymax = com.epl.geometry.NumberUtils.NaN(); double zmin = com.epl.geometry.NumberUtils.NaN(); double zmax = com.epl.geometry.NumberUtils.NaN(); double mmin = com.epl.geometry.NumberUtils.NaN(); double mmax = com.epl.geometry.NumberUtils.NaN(); bool bHasZ = false; bool bHasM = false; com.epl.geometry.AttributeStreamOfDbl @as = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.AttributeStreamOfDbl bs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.Geometry geometry = null; com.epl.geometry.SpatialReference spatial_reference = null; while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_OBJECT) { string name = parser.CurrentString(); parser.NextToken(); if (!bFoundSpatial_reference && name.Equals("spatialReference")) { bFoundSpatial_reference = true; if (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.START_OBJECT) { spatial_reference = com.epl.geometry.SpatialReference.FromJson(parser); } else { if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.VALUE_NULL) { throw new com.epl.geometry.GeometryException("failed to parse spatial reference: object or null is expected"); } } } else { if (!bFoundHasZ && name.Equals("hasZ")) { bFoundHasZ = true; bHasZ = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundHasM && name.Equals("hasM")) { bFoundHasM = true; bHasM = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundPolygon && name.Equals("rings") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polygon)) { bFoundPolygon = true; geometry = ImportFromJsonMultiPath(true, parser, @as, bs); continue; } else { if (!bFoundPolyline && name.Equals("paths") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polyline)) { bFoundPolyline = true; geometry = ImportFromJsonMultiPath(false, parser, @as, bs); continue; } else { if (!bFoundMultiPoint && name.Equals("points") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.MultiPoint)) { bFoundMultiPoint = true; geometry = ImportFromJsonMultiPoint(parser, @as, bs); continue; } else { if (!bFoundX && name.Equals("x") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundX = true; x = ReadDouble(parser); } else { if (!bFoundY && name.Equals("y") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundY = true; y = ReadDouble(parser); } else { if (!bFoundZ && name.Equals("z") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundZ = true; z = ReadDouble(parser); } else { if (!bFoundM && name.Equals("m") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundM = true; m = ReadDouble(parser); } } } } } } } } } } if (!bFoundXMin && name.Equals("xmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMin = true; xmin = ReadDouble(parser); } else { if (!bFoundYMin && name.Equals("ymin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMin = true; ymin = ReadDouble(parser); } else { if (!bFoundMMin && name.Equals("mmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMin = true; mmin = ReadDouble(parser); } else { if (!bFoundZMin && name.Equals("zmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMin = true; zmin = ReadDouble(parser); } else { if (!bFoundXMax && name.Equals("xmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMax = true; xmax = ReadDouble(parser); } else { if (!bFoundYMax && name.Equals("ymax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMax = true; ymax = ReadDouble(parser); } else { if (!bFoundMMax && name.Equals("mmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMax = true; mmax = ReadDouble(parser); } else { if (!bFoundZMax && name.Equals("zmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMax = true; zmax = ReadDouble(parser); } else { Windup(parser); } } } } } } } } } if (bFoundPolygon || bFoundPolyline || bFoundMultiPoint) { System.Diagnostics.Debug.Assert((geometry != null)); com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl(); com.epl.geometry.AttributeStreamBase zs = null; com.epl.geometry.AttributeStreamBase ms = null; if (bHasZ) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); zs = @as; } if (bHasM) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); ms = !bHasZ ? @as : bs; } if (bHasZ && zs != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs); } if (bHasM && ms != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms); } mvImpl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll); } else { if (bFoundX || bFoundY || bFoundY || bFoundZ) { if (com.epl.geometry.NumberUtils.IsNaN(y)) { x = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Point p = new com.epl.geometry.Point(x, y); if (bFoundZ) { p.SetZ(z); } if (bFoundM) { p.SetM(m); } geometry = p; } else { if (bFoundXMin || bFoundYMin || bFoundXMax || bFoundYMax || bFoundZMin || bFoundZMax || bFoundMMin || bFoundMMax) { if (com.epl.geometry.NumberUtils.IsNaN(ymin) || com.epl.geometry.NumberUtils.IsNaN(xmax) || com.epl.geometry.NumberUtils.IsNaN(ymax)) { xmin = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(xmin, ymin, xmax, ymax); if (bFoundZMin && bFoundZMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, zmin, zmax); } if (bFoundMMin && bFoundMMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, mmin, mmax); } geometry = e; } } } mp = new com.epl.geometry.MapGeometry(geometry, spatial_reference); } catch (System.Exception) { return(null); } return(mp); }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestPoint() { bool bAnswer = true; com.epl.geometry.Point point1 = new com.epl.geometry.Point(10.0, 20.0); com.epl.geometry.Point pointEmpty = new com.epl.geometry.Point(); { com.fasterxml.jackson.core.JsonParser pointWebMerc1Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, point1)); com.epl.geometry.MapGeometry pointWebMerc1MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc1Parser); NUnit.Framework.Assert.IsTrue(point1.GetX() == ((com.epl.geometry.Point)pointWebMerc1MP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(point1.GetY() == ((com.epl.geometry.Point)pointWebMerc1MP.GetGeometry()).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWebMerc1.GetID() == pointWebMerc1MP.GetSpatialReference().GetID() || pointWebMerc1MP.GetSpatialReference().GetID() == 3857); if (!CheckResultSpatialRef(pointWebMerc1MP, 102100, 3857)) { bAnswer = false; } pointWebMerc1Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(null, point1)); pointWebMerc1MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc1Parser); NUnit.Framework.Assert.IsTrue(null == pointWebMerc1MP.GetSpatialReference()); if (pointWebMerc1MP.GetSpatialReference() != null) { if (!CheckResultSpatialRef(pointWebMerc1MP, 102100, 3857)) { bAnswer = false; } } string pointEmptyString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, pointEmpty); pointWebMerc1Parser = factory.CreateParser(pointEmptyString); } com.fasterxml.jackson.core.JsonParser pointWebMerc2Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc2, point1)); com.epl.geometry.MapGeometry pointWebMerc2MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWebMerc2Parser); NUnit.Framework.Assert.IsTrue(point1.GetX() == ((com.epl.geometry.Point)pointWebMerc2MP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(point1.GetY() == ((com.epl.geometry.Point)pointWebMerc2MP.GetGeometry()).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWebMerc2.GetLatestID() == pointWebMerc2MP.GetSpatialReference().GetLatestID()); if (!CheckResultSpatialRef(pointWebMerc2MP, spatialReferenceWebMerc2.GetLatestID(), 0)) { bAnswer = false; } { com.fasterxml.jackson.core.JsonParser pointWgs84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, point1)); com.epl.geometry.MapGeometry pointWgs84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(pointWgs84Parser); NUnit.Framework.Assert.IsTrue(point1.GetX() == ((com.epl.geometry.Point)pointWgs84MP.GetGeometry()).GetX()); NUnit.Framework.Assert.IsTrue(point1.GetY() == ((com.epl.geometry.Point)pointWgs84MP.GetGeometry()).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == pointWgs84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(pointWgs84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.Point p = new com.epl.geometry.Point(); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":null,\"y\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":null,\"y\":null,\"z\":null,\"m\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { com.epl.geometry.Point p = new com.epl.geometry.Point(10.0, 20.0, 30.0); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":10,\"y\":20,\"z\":30,\"m\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { // import string s = "{\"x\":0.0,\"y\":1.0,\"z\":5.0,\"m\":11.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; com.fasterxml.jackson.core.JsonParser parser = factory.CreateParser(s); com.epl.geometry.MapGeometry map_pt = com.epl.geometry.GeometryEngine.JsonToGeometry(parser); com.epl.geometry.Point pt = (com.epl.geometry.Point)map_pt.GetGeometry(); NUnit.Framework.Assert.IsTrue(pt.GetX() == 0.0); NUnit.Framework.Assert.IsTrue(pt.GetY() == 1.0); NUnit.Framework.Assert.IsTrue(pt.GetZ() == 5.0); NUnit.Framework.Assert.IsTrue(pt.GetM() == 11.0); } { string s = "{\"x\" : 5.0, \"y\" : null, \"spatialReference\" : {\"wkid\" : 4326}} "; com.fasterxml.jackson.core.JsonParser parser = factory.CreateParser(s); com.epl.geometry.MapGeometry map_pt = com.epl.geometry.GeometryEngine.JsonToGeometry(parser); com.epl.geometry.Point pt = (com.epl.geometry.Point)map_pt.GetGeometry(); NUnit.Framework.Assert.IsTrue(pt.IsEmpty()); com.epl.geometry.SpatialReference spatial_reference = map_pt.GetSpatialReference(); NUnit.Framework.Assert.IsTrue(spatial_reference.GetID() == 4326); } 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()); } } } } }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestEnvelope() { bool bAnswer = true; com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope(); envelope.SetCoords(-109.55, 25.76, -86.39, 49.94); { com.fasterxml.jackson.core.JsonParser envelopeWGS84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, envelope)); com.epl.geometry.MapGeometry envelopeWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelope.IsEmpty() == envelopeWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(envelope.GetXMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMax()); NUnit.Framework.Assert.IsTrue(envelope.GetYMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMax()); NUnit.Framework.Assert.IsTrue(envelope.GetXMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMin()); NUnit.Framework.Assert.IsTrue(envelope.GetYMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMin()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == envelopeWGS84MP.GetSpatialReference().GetID()); if (!CheckResultSpatialRef(envelopeWGS84MP, 4326, 0)) { bAnswer = false; } } { // export com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(); e.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); e.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":null,\"ymin\":null,\"xmax\":null,\"ymax\":null,\"zmin\":null,\"zmax\":null,\"mmin\":null,\"mmax\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); e.SetCoords(0, 1, 2, 3); com.epl.geometry.Envelope1D z = new com.epl.geometry.Envelope1D(); com.epl.geometry.Envelope1D m = new com.epl.geometry.Envelope1D(); z.SetCoords(5, 7); m.SetCoords(11, 13); e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, z); e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, m); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":0,\"ymin\":1,\"xmax\":2,\"ymax\":3,\"zmin\":5,\"zmax\":7,\"mmin\":11,\"mmax\":13,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { // import string s = "{\"xmin\":0.0,\"ymin\":1.0,\"xmax\":2.0,\"ymax\":3.0,\"zmin\":5.0,\"zmax\":7.0,\"mmin\":11.0,\"mmax\":13.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; com.fasterxml.jackson.core.JsonParser parser = factory.CreateParser(s); com.epl.geometry.MapGeometry map_env = com.epl.geometry.GeometryEngine.JsonToGeometry(parser); com.epl.geometry.Envelope env = (com.epl.geometry.Envelope)map_env.GetGeometry(); com.epl.geometry.Envelope1D z = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0); com.epl.geometry.Envelope1D m = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0); NUnit.Framework.Assert.IsTrue(z.vmin == 5.0); NUnit.Framework.Assert.IsTrue(z.vmax == 7.0); NUnit.Framework.Assert.IsTrue(m.vmin == 11.0); NUnit.Framework.Assert.IsTrue(m.vmax == 13.0); } { string s = "{ \"zmin\" : 33, \"xmin\" : -109.55, \"zmax\" : 53, \"ymin\" : 25.76, \"xmax\" : -86.39, \"ymax\" : 49.94, \"mmax\" : 13}"; com.fasterxml.jackson.core.JsonParser parser = factory.CreateParser(s); com.epl.geometry.MapGeometry map_env = com.epl.geometry.GeometryEngine.JsonToGeometry(parser); com.epl.geometry.Envelope env = (com.epl.geometry.Envelope)map_env.GetGeometry(); com.epl.geometry.Envelope2D e = new com.epl.geometry.Envelope2D(); env.QueryEnvelope2D(e); NUnit.Framework.Assert.IsTrue(e.xmin == -109.55 && e.ymin == 25.76 && e.xmax == -86.39 && e.ymax == 49.94); com.epl.geometry.Envelope1D e1D; NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); e1D = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(e1D.vmin == 33 && e1D.vmax == 53); NUnit.Framework.Assert.IsTrue(!env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); } return(bAnswer); }
/// <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); }