예제 #1
0
 public virtual void TestReplaceNaNs()
 {
     com.epl.geometry.Envelope env = new com.epl.geometry.Envelope();
     com.epl.geometry.Point    pt  = new com.epl.geometry.Point();
     pt.SetXY(1, 2);
     pt.SetZ(double.NaN);
     pt.QueryEnvelope(env);
     pt.ReplaceNaNs(com.epl.geometry.VertexDescription.Semantics.Z, 5);
     NUnit.Framework.Assert.IsTrue(pt.Equals(new com.epl.geometry.Point(1, 2, 5)));
     NUnit.Framework.Assert.IsTrue(env.HasZ());
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).IsEmpty());
     env.ReplaceNaNs(com.epl.geometry.VertexDescription.Semantics.Z, 5);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).Equals(new com.epl.geometry.Envelope1D(5, 5)));
 }
예제 #2
0
        // Mirrors wkt
        private static void ExportEnvelopeToGeoJson_(int export_flags, com.epl.geometry.Envelope envelope, com.epl.geometry.JsonWriter json_writer)
        {
            int  precision   = 17 - (31 & (export_flags >> 13));
            bool bFixedPoint = (com.epl.geometry.GeoJsonExportFlags.geoJsonExportPrecisionFixedPoint & export_flags) != 0;
            bool b_export_zs = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripZs) == 0;
            bool b_export_ms = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripMs) == 0;

            if (!b_export_zs && b_export_ms)
            {
                throw new System.ArgumentException("invalid argument");
            }
            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();

            if (!envelope.IsEmpty())
            {
                xmin = envelope.GetXMin();
                ymin = envelope.GetYMin();
                xmax = envelope.GetXMax();
                ymax = envelope.GetYMax();
                com.epl.geometry.Envelope1D interval;
                if (b_export_zs)
                {
                    interval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                    zmin     = interval.vmin;
                    zmax     = interval.vmax;
                }
                if (b_export_ms)
                {
                    interval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                    mmin     = interval.vmin;
                    mmax     = interval.vmax;
                }
            }
            if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportPreferMultiGeometry) == 0)
            {
                PolygonTaggedTextFromEnvelope_(precision, bFixedPoint, b_export_zs, b_export_ms, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax, json_writer);
            }
            else
            {
                MultiPolygonTaggedTextFromEnvelope_(precision, bFixedPoint, b_export_zs, b_export_ms, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax, json_writer);
            }
        }
예제 #3
0
 /// <summary>Merges this envelope with the extent of the given envelope.</summary>
 /// <remarks>
 /// Merges this envelope with the extent of the given envelope. If this
 /// envelope is empty, the coordinates of the given envelope
 /// are assigned. If the given envelope is empty, this envelope is unchanged.
 /// </remarks>
 /// <param name="other">The envelope to merge.</param>
 public virtual void Merge(com.epl.geometry.Envelope other)
 {
     _touch();
     if (other.IsEmpty())
     {
         return;
     }
     com.epl.geometry.VertexDescription otherVD = other.m_description;
     if (otherVD != m_description)
     {
         MergeVertexDescription(otherVD);
     }
     m_envelope.Merge(other.m_envelope);
     for (int iattrib = 1, nattrib = otherVD.GetAttributeCount(); iattrib < nattrib; iattrib++)
     {
         int semantics = otherVD.GetSemantics(iattrib);
         int ncomps    = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
         for (int iord = 0; iord < ncomps; iord++)
         {
             com.epl.geometry.Envelope1D intervalOther = other.QueryInterval(semantics, iord);
             com.epl.geometry.Envelope1D interval      = QueryInterval(semantics, iord);
             interval.Merge(intervalOther);
             SetInterval(semantics, iord, interval);
         }
     }
 }
예제 #4
0
 public virtual void TestEnvelope()
 {
     com.epl.geometry.Envelope env = new com.epl.geometry.Envelope();
     env.SetCoords(100, 200, 250, 300);
     NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     env.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0).IsEmpty());
     env.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, 1, 2);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0).vmin == 1);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0).vmax == 2);
     NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     env.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
     NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmin == 0);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmax == 0);
     env.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, 3, 4);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmin == 3);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmax == 4);
     NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     env.AddAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
     NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmin == 0);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmax == 0);
     env.SetInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0, 5, 6);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmin == 5);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmax == 6);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmin == 3);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmax == 4);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0).vmin == 1);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0).vmax == 2);
     env.DropAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmin == 5);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmax == 6);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmin == 3);
     NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmax == 4);
     com.epl.geometry.Envelope env1 = new com.epl.geometry.Envelope();
     env.CopyTo(env1);
     NUnit.Framework.Assert.IsFalse(env1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmin == 5);
     NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0).vmax == 6);
     NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmin == 3);
     NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0).vmax == 4);
 }
        internal static void ExportEnvelopeToWkt(int export_flags, com.epl.geometry.Envelope envelope, System.Text.StringBuilder @string)
        {
            int    precision   = 17 - (7 & (export_flags >> 13));
            bool   b_export_zs = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripZs) == 0;
            bool   b_export_ms = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripMs) == 0;
            double xmin        = com.epl.geometry.NumberUtils.TheNaN;
            double ymin        = com.epl.geometry.NumberUtils.TheNaN;
            double xmax        = com.epl.geometry.NumberUtils.TheNaN;
            double ymax        = com.epl.geometry.NumberUtils.TheNaN;
            double zmin        = com.epl.geometry.NumberUtils.TheNaN;
            double zmax        = com.epl.geometry.NumberUtils.TheNaN;
            double mmin        = com.epl.geometry.NumberUtils.TheNaN;
            double mmax        = com.epl.geometry.NumberUtils.TheNaN;

            com.epl.geometry.Envelope1D interval;
            if (!envelope.IsEmpty())
            {
                xmin = envelope.GetXMin();
                ymin = envelope.GetYMin();
                xmax = envelope.GetXMax();
                ymax = envelope.GetYMax();
                if (b_export_zs)
                {
                    interval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                    zmin     = interval.vmin;
                    zmax     = interval.vmax;
                }
                if (b_export_ms)
                {
                    interval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                    mmin     = interval.vmin;
                    mmax     = interval.vmax;
                }
            }
            if ((export_flags & com.epl.geometry.WktExportFlags.wktExportMultiPolygon) != 0)
            {
                MultiPolygonTaggedTextFromEnvelope_(precision, b_export_zs, b_export_ms, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax, @string);
            }
            else
            {
                PolygonTaggedTextFromEnvelope_(precision, b_export_zs, b_export_ms, xmin, ymin, xmax, ymax, zmin, zmax, mmin, mmax, @string);
            }
        }
 // Checked vs. Jan 11, 2011
 public override com.epl.geometry.Envelope1D QueryInterval(int semantics, int ordinate)
 {
     com.epl.geometry.Envelope1D env = new com.epl.geometry.Envelope1D();
     if (IsEmptyImpl())
     {
         env.SetEmpty();
         return(env);
     }
     _updateAllDirtyIntervals(true);
     return(m_envelope.QueryInterval(semantics, ordinate));
 }
예제 #7
0
 /// <exception cref="java.io.ObjectStreamException"/>
 public virtual void SetGeometryByValue(com.epl.geometry.Envelope env)
 {
     try
     {
         attribs = null;
         if (env == null)
         {
             descriptionBitMask = -1;
         }
         com.epl.geometry.VertexDescription vd = env.GetDescription();
         descriptionBitMask = vd.m_semanticsBitArray;
         if (env.IsEmpty())
         {
             return;
         }
         attribs    = new double[vd.GetTotalComponentCount() * 2];
         attribs[0] = env.GetXMin();
         attribs[1] = env.GetYMin();
         attribs[2] = env.GetXMax();
         attribs[3] = env.GetYMax();
         int index = 4;
         for (int i = 1, n = vd.GetAttributeCount(); i < n; i++)
         {
             int semantics = vd.GetSemantics(i);
             int comps     = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
             for (int ord = 0; ord < comps; ord++)
             {
                 com.epl.geometry.Envelope1D e = env.QueryInterval(semantics, ord);
                 attribs[index++] = e.vmin;
                 attribs[index++] = e.vmax;
             }
         }
     }
     catch (System.Exception)
     {
         throw new System.IO.InvalidDataException("Cannot serialize this geometry");
     }
 }
        // return -1;
        private static int ExportEnvelopeToESRIShape(int exportFlags, com.epl.geometry.Envelope envelope, System.IO.BinaryWriter shapeBuffer)
        {
            bool bExportZs    = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripZs) == 0;
            bool bExportMs    = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripMs) == 0;
            bool bExportIDs   = envelope.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripIDs) == 0;
            bool bArcViewNaNs = (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportTrueNaNs) == 0;
            bool bEmpty       = envelope.IsEmpty();
            int  partCount    = bEmpty ? 0 : 1;
            int  pointCount   = bEmpty ? 0 : 5;
            int  size         = (4) + (4 * 8) + (4) + (4) + (partCount * 4) + pointCount * 2 * 8;

            /* type */
            /* envelope */
            /* part count */
            /* point count */
            /* start indices */
            /* xy coordinates */
            if (bExportZs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* zs */
            if (bExportMs)
            {
                size += (2 * 8) + (pointCount * 8);
            }
            /* min max */
            /* ms */
            if (bExportIDs)
            {
                size += (pointCount * 4);
            }
            /* ids */
            if (shapeBuffer == null)
            {
                return(size);
            }
            else
            {
                if (((System.IO.MemoryStream)shapeBuffer.BaseStream).Capacity < size)
                {
                    throw new com.epl.geometry.GeometryException("buffer is too small");
                }
            }
            int type;

            // Determine the shape type
            if (!bExportZs && !bExportMs)
            {
                if (bExportIDs)
                {
                    type = com.epl.geometry.ShapeType.ShapeGeneralPolygon | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                }
                else
                {
                    type = com.epl.geometry.ShapeType.ShapePolygon;
                }
            }
            else
            {
                if (bExportZs && !bExportMs)
                {
                    if (bExportIDs)
                    {
                        type = com.epl.geometry.ShapeType.ShapeGeneralPolygon | com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                    }
                    else
                    {
                        type = com.epl.geometry.ShapeType.ShapePolygonZ;
                    }
                }
                else
                {
                    if (bExportMs && !bExportZs)
                    {
                        if (bExportIDs)
                        {
                            type = com.epl.geometry.ShapeType.ShapeGeneralPolygon | com.epl.geometry.ShapeModifiers.ShapeHasMs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                        }
                        else
                        {
                            type = com.epl.geometry.ShapeType.ShapePolygonM;
                        }
                    }
                    else
                    {
                        if (bExportIDs)
                        {
                            type = com.epl.geometry.ShapeType.ShapeGeneralPolygon | com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasMs | com.epl.geometry.ShapeModifiers.ShapeHasIDs;
                        }
                        else
                        {
                            type = com.epl.geometry.ShapeType.ShapePolygonZM;
                        }
                    }
                }
            }
            int offset = 0;

            // write type
            shapeBuffer.Write(type);
            offset += 4;
            // write Envelope
            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            envelope.QueryEnvelope2D(env);
            // calls _VerifyAllStreams
            shapeBuffer.Write(env.xmin);
            offset += 8;
            shapeBuffer.Write(env.ymin);
            offset += 8;
            shapeBuffer.Write(env.xmax);
            offset += 8;
            shapeBuffer.Write(env.ymax);
            offset += 8;
            // write part count
            shapeBuffer.Write(partCount);
            offset += 4;
            // write pointCount
            shapeBuffer.Write(pointCount);
            offset += 4;
            if (!bEmpty)
            {
                // write start index
                shapeBuffer.Write(0);
                offset += 4;
                // write xy coordinates
                shapeBuffer.Write(env.xmin);
                offset += 8;
                shapeBuffer.Write(env.ymin);
                offset += 8;
                shapeBuffer.Write(env.xmin);
                offset += 8;
                shapeBuffer.Write(env.ymax);
                offset += 8;
                shapeBuffer.Write(env.xmax);
                offset += 8;
                shapeBuffer.Write(env.ymax);
                offset += 8;
                shapeBuffer.Write(env.xmax);
                offset += 8;
                shapeBuffer.Write(env.ymin);
                offset += 8;
                shapeBuffer.Write(env.xmin);
                offset += 8;
                shapeBuffer.Write(env.ymin);
                offset += 8;
            }
            // write Zs
            if (bExportZs)
            {
                com.epl.geometry.Envelope1D zInterval;
                zInterval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                double zmin = bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmin) : zInterval.vmin;
                double zmax = bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmax) : zInterval.vmax;
                // write min max values
                shapeBuffer.Write(zmin);
                offset += 8;
                shapeBuffer.Write(zmax);
                offset += 8;
                if (!bEmpty)
                {
                    // write arbitrary z values
                    shapeBuffer.Write(zmin);
                    offset += 8;
                    shapeBuffer.Write(zmax);
                    offset += 8;
                    shapeBuffer.Write(zmin);
                    offset += 8;
                    shapeBuffer.Write(zmax);
                    offset += 8;
                    shapeBuffer.Write(zmin);
                    offset += 8;
                }
            }
            // write Ms
            if (bExportMs)
            {
                com.epl.geometry.Envelope1D mInterval;
                mInterval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                double mmin = bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmin) : mInterval.vmin;
                double mmax = bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmax) : mInterval.vmax;
                // write min max values
                shapeBuffer.Write(mmin);
                offset += 8;
                shapeBuffer.Write(mmax);
                offset += 8;
                if (!bEmpty)
                {
                    // write arbitrary m values
                    shapeBuffer.Write(mmin);
                    offset += 8;
                    shapeBuffer.Write(mmax);
                    offset += 8;
                    shapeBuffer.Write(mmin);
                    offset += 8;
                    shapeBuffer.Write(mmax);
                    offset += 8;
                    shapeBuffer.Write(mmin);
                    offset += 8;
                }
            }
            // write IDs
            if (bExportIDs && !bEmpty)
            {
                com.epl.geometry.Envelope1D idInterval;
                idInterval = envelope.QueryInterval(com.epl.geometry.VertexDescription.Semantics.ID, 0);
                int idmin = (int)idInterval.vmin;
                int idmax = (int)idInterval.vmax;
                // write arbitrary id values
                shapeBuffer.Write(idmin);
                offset += 4;
                shapeBuffer.Write(idmax);
                offset += 4;
                shapeBuffer.Write(idmin);
                offset += 4;
                shapeBuffer.Write(idmax);
                offset += 4;
                shapeBuffer.Write(idmin);
                offset += 4;
            }
            return(offset);
        }
        /// <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);
        }
        private static void ExportEnvelopeToJson(com.epl.geometry.Envelope env, com.epl.geometry.SpatialReference spatialReference, com.epl.geometry.JsonWriter jsonWriter, System.Collections.Generic.IDictionary <string, object> exportProperties)
        {
            bool bExportZs    = env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
            bool bExportMs    = env.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 (env.IsEmpty())
            {
                jsonWriter.AddPairNull("xmin");
                jsonWriter.AddPairNull("ymin");
                jsonWriter.AddPairNull("xmax");
                jsonWriter.AddPairNull("ymax");
                if (bExportZs)
                {
                    jsonWriter.AddPairNull("zmin");
                    jsonWriter.AddPairNull("zmax");
                }
                if (bExportMs)
                {
                    jsonWriter.AddPairNull("mmin");
                    jsonWriter.AddPairNull("mmax");
                }
            }
            else
            {
                if (bPositionAsF)
                {
                    jsonWriter.AddPairDouble("xmin", env.GetXMin(), decimals, true);
                    jsonWriter.AddPairDouble("ymin", env.GetYMin(), decimals, true);
                    jsonWriter.AddPairDouble("xmax", env.GetXMax(), decimals, true);
                    jsonWriter.AddPairDouble("ymax", env.GetYMax(), decimals, true);
                }
                else
                {
                    jsonWriter.AddPairDouble("xmin", env.GetXMin());
                    jsonWriter.AddPairDouble("ymin", env.GetYMin());
                    jsonWriter.AddPairDouble("xmax", env.GetXMax());
                    jsonWriter.AddPairDouble("ymax", env.GetYMax());
                }
                if (bExportZs)
                {
                    com.epl.geometry.Envelope1D z = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                    jsonWriter.AddPairDouble("zmin", z.vmin);
                    jsonWriter.AddPairDouble("zmax", z.vmax);
                }
                if (bExportMs)
                {
                    com.epl.geometry.Envelope1D m = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                    jsonWriter.AddPairDouble("mmin", m.vmin);
                    jsonWriter.AddPairDouble("mmax", m.vmax);
                }
            }
            if (spatialReference != null)
            {
                WriteSR(spatialReference, jsonWriter);
            }
            jsonWriter.EndObject();
        }