/// <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);
        }
示例#2
0
 public virtual void TestMultiPoint()
 {
     com.epl.geometry.MultiPoint mp = new com.epl.geometry.MultiPoint();
     mp.Add(new com.epl.geometry.Point(100, 200));
     mp.Add(new com.epl.geometry.Point(101, 201));
     mp.Add(new com.epl.geometry.Point(102, 202));
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0)));
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 1);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 2);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 0);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 11);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0, 21);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0, 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == 0);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0, -11);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0, -21);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0, -31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     mp.DropAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     com.epl.geometry.MultiPoint mp1 = new com.epl.geometry.MultiPoint();
     mp.CopyTo(mp1);
     NUnit.Framework.Assert.IsFalse(mp1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     mp1.DropAllAttributes();
     mp1.MergeVertexDescription(mp.GetDescription());
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 0);
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0)));
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == 0);
 }
        private static void ExportMultiPointToJson(com.epl.geometry.MultiPoint mpt, com.epl.geometry.SpatialReference spatialReference, com.epl.geometry.JsonWriter jsonWriter, System.Collections.Generic.IDictionary <string, object> exportProperties)
        {
            bool bExportZs    = mpt.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
            bool bExportMs    = mpt.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M);
            bool bPositionAsF = false;
            int  decimals     = 17;

            if (exportProperties != null)
            {
                object numberOfDecimalsXY = exportProperties["numberOfDecimalsXY"];
                if (numberOfDecimalsXY != null && numberOfDecimalsXY is java.lang.Number)
                {
                    bPositionAsF = true;
                    decimals     = ((java.lang.Number)numberOfDecimalsXY);
                }
            }
            jsonWriter.StartObject();
            if (bExportZs)
            {
                jsonWriter.AddPairBoolean("hasZ", true);
            }
            if (bExportMs)
            {
                jsonWriter.AddPairBoolean("hasM", true);
            }
            jsonWriter.AddPairArray("points");
            if (!mpt.IsEmpty())
            {
                com.epl.geometry.MultiPointImpl mpImpl = (com.epl.geometry.MultiPointImpl)mpt._getImpl();
                // get impl
                // for
                // faster
                // access
                com.epl.geometry.AttributeStreamOfDbl zs = null;
                com.epl.geometry.AttributeStreamOfDbl ms = null;
                if (bExportZs)
                {
                    zs = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                }
                if (bExportMs)
                {
                    ms = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                }
                com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                int n = mpt.GetPointCount();
                for (int i = 0; i < n; i++)
                {
                    mpt.GetXY(i, pt);
                    jsonWriter.AddValueArray();
                    if (bPositionAsF)
                    {
                        jsonWriter.AddValueDouble(pt.x, decimals, true);
                        jsonWriter.AddValueDouble(pt.y, decimals, true);
                    }
                    else
                    {
                        jsonWriter.AddValueDouble(pt.x);
                        jsonWriter.AddValueDouble(pt.y);
                    }
                    if (bExportZs)
                    {
                        double z = zs.Get(i);
                        jsonWriter.AddValueDouble(z);
                    }
                    if (bExportMs)
                    {
                        double m = ms.Get(i);
                        jsonWriter.AddValueDouble(m);
                    }
                    jsonWriter.EndArray();
                }
            }
            jsonWriter.EndArray();
            if (spatialReference != null)
            {
                WriteSR(spatialReference, jsonWriter);
            }
            jsonWriter.EndObject();
        }