Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <exception cref="com.fasterxml.jackson.core.JsonParseException"/>
        /// <exception cref="System.IO.IOException"/>
        public static int FromJsonToWkid(com.fasterxml.jackson.core.JsonParser parser)
        {
            int wkid = 0;

            if (parser.GetCurrentToken() != com.fasterxml.jackson.core.JsonToken.START_OBJECT)
            {
                return(0);
            }
            while (parser.NextToken() != com.fasterxml.jackson.core.JsonToken.END_OBJECT)
            {
                string fieldName = parser.GetCurrentName();
                if ("wkid".Equals(fieldName))
                {
                    parser.NextToken();
                    wkid = parser.GetIntValue();
                }
            }
            return(wkid);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 /// <exception cref="com.epl.geometry.JsonGeometryException"/>
 public override com.epl.geometry.JsonReader.Token NextToken()
 {
     try
     {
         com.fasterxml.jackson.core.JsonToken token = m_jsonParser.NextToken();
         return(MapToken(token));
     }
     catch (System.Exception ex)
     {
         throw new com.epl.geometry.JsonGeometryException(ex);
     }
 }
Beispiel #6
0
 /// <summary>Creates a JsonReader for the string.</summary>
 /// <remarks>
 /// Creates a JsonReader for the string.
 /// The nextToken is called by this method.
 /// </remarks>
 public static com.epl.geometry.JsonReader CreateFromString(string str)
 {
     try
     {
         com.fasterxml.jackson.core.JsonFactory factory    = new com.fasterxml.jackson.core.JsonFactory();
         com.fasterxml.jackson.core.JsonParser  jsonParser = factory.CreateParser(str);
         jsonParser.NextToken();
         return(new com.epl.geometry.JsonParserReader(jsonParser));
     }
     catch (System.Exception ex)
     {
         throw new com.epl.geometry.JsonGeometryException(ex.Message);
     }
 }
Beispiel #7
0
 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;
     }
 }