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()); }
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); }
/// <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 Test_80() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(3857); NUnit.Framework.Assert.IsTrue(sr.GetID() == 3857); NUnit.Framework.Assert.IsTrue(sr.GetLatestID() == 3857); NUnit.Framework.Assert.IsTrue(sr.GetOldID() == 102100); NUnit.Framework.Assert.IsTrue(sr.GetTolerance() == 0.001); }
/// <exception cref="java.io.ObjectStreamException"/> public void SetSpatialReferenceByValue(com.epl.geometry.SpatialReference sr) { try { if (sr.GetID() > 0) { wkid = sr.GetID(); } else { wkt = sr.GetText(); } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot serialize this geometry"); } }
public virtual void Test() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(102100); NUnit.Framework.Assert.IsTrue(sr.GetID() == 102100); NUnit.Framework.Assert.IsTrue(sr.GetLatestID() == 3857); NUnit.Framework.Assert.IsTrue(sr.GetOldID() == 102100); NUnit.Framework.Assert.IsTrue(sr.GetTolerance() == 0.001); com.epl.geometry.SpatialReference sr84 = com.epl.geometry.SpatialReference.Create(4326); double tol84 = sr84.GetTolerance(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(tol84 - 1e-8) < 1e-8 * 1e-8); }
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 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); }
/// <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); }