Пример #1
0
 private static void ExportSpatialReference(int export_flags, com.epl.geometry.SpatialReference spatial_reference, com.epl.geometry.JsonWriter json_writer)
 {
     if (spatial_reference != null)
     {
         int wkid = spatial_reference.GetLatestID();
         if (wkid <= 0)
         {
             throw new com.epl.geometry.GeometryException("invalid call");
         }
         json_writer.StartObject();
         json_writer.AddFieldName("type");
         json_writer.AddValueString("name");
         json_writer.AddFieldName("properties");
         json_writer.StartObject();
         json_writer.AddFieldName("name");
         string authority = ((com.epl.geometry.SpatialReferenceImpl)spatial_reference).GetAuthority();
         authority = authority.ToUpper();
         System.Text.StringBuilder crs_identifier = new System.Text.StringBuilder(authority);
         crs_identifier.Append(':');
         crs_identifier.Append(wkid);
         json_writer.AddValueString(crs_identifier.ToString());
         json_writer.EndObject();
         json_writer.EndObject();
     }
     else
     {
         json_writer.AddValueNull();
     }
 }
        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);
        }
        private static void WriteSR(com.epl.geometry.SpatialReference spatialReference, com.epl.geometry.JsonWriter jsonWriter)
        {
            int wkid = spatialReference.GetOldID();

            if (wkid > 0)
            {
                jsonWriter.AddPairObject("spatialReference");
                jsonWriter.AddPairInt("wkid", wkid);
                int latest_wkid = spatialReference.GetLatestID();
                if (latest_wkid > 0 && latest_wkid != wkid)
                {
                    jsonWriter.AddPairInt("latestWkid", latest_wkid);
                }
                jsonWriter.EndObject();
            }
            else
            {
                string wkt = spatialReference.GetText();
                if (wkt != null)
                {
                    jsonWriter.AddPairObject("spatialReference");
                    jsonWriter.AddPairString("wkt", wkt);
                    jsonWriter.EndObject();
                }
            }
        }
Пример #4
0
 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);
 }
Пример #5
0
 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());
     }
 }
Пример #6
0
        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);
        }
        /// <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);
        }