//This is a writeReplace class for Envelope /// <exception cref="java.io.ObjectStreamException"/> public virtual object ReadResolve() { com.epl.geometry.Envelope env = null; if (descriptionBitMask == -1) { return(null); } try { com.epl.geometry.VertexDescription vd = com.epl.geometry.VertexDescriptionDesignerImpl.GetVertexDescription(descriptionBitMask); env = new com.epl.geometry.Envelope(vd); if (attribs != null) { env.SetCoords(attribs[0], attribs[1], attribs[2], attribs[3]); 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++) { env.SetInterval(semantics, ord, attribs[index++], attribs[index++]); } } } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot read geometry from stream"); } return(env); }
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); }
// Checked vs. Jan 11, 2011 /// <param name="bExact"> /// True, when the exact envelope need to be calculated and false /// for the loose one. /// </param> protected internal virtual void _updateAllDirtyIntervals(bool bExact) { _verifyAllStreams(); if (_hasDirtyFlag(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyIntervals)) { if (null == m_envelope) { m_envelope = new com.epl.geometry.Envelope(m_description); } else { m_envelope.AssignVertexDescription(m_description); } if (IsEmpty()) { m_envelope.SetEmpty(); return; } _updateXYImpl(bExact); // efficient method for xy's // now go through other attribues. for (int attributeIndex = 1; attributeIndex < m_description.GetAttributeCount(); attributeIndex++) { int semantics = m_description._getSemanticsImpl(attributeIndex); int ncomps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); com.epl.geometry.AttributeStreamBase stream = m_vertexAttributes[attributeIndex]; for (int iord = 0; iord < ncomps; iord++) { com.epl.geometry.Envelope1D interval = new com.epl.geometry.Envelope1D(); interval.SetEmpty(); for (int i = 0; i < m_pointCount; i++) { double value = stream.ReadAsDbl(i * ncomps + iord); // some // optimization // is // possible // if // non-virtual // method // is // used interval.Merge(value); } m_envelope.SetInterval(semantics, iord, interval); } } if (bExact) { _setDirtyFlag(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyIntervals, false); } } }
public override void QueryEnvelope(com.epl.geometry.Envelope env) { env.SetEmpty(); env.AssignVertexDescription(m_description); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); QueryEnvelope2D(env2D); env.SetEnvelope2D(env2D); for (int i = 1, n = m_description.GetAttributeCount(); i < n; i++) { int semantics = m_description.GetSemantics(i); for (int iord = 0, nord = com.epl.geometry.VertexDescription.GetComponentCount(semantics); i < nord; i++) { com.epl.geometry.Envelope1D interval = QueryInterval(semantics, iord); env.SetInterval(semantics, iord, interval); } } }
internal static com.epl.geometry.MapGeometry ImportFromJsonParser(int gt, com.epl.geometry.JsonReader parser) { com.epl.geometry.MapGeometry mp; try { if (!com.epl.geometry.JSONUtils.IsObjectStart(parser)) { return(null); } bool bFoundSpatial_reference = false; bool bFoundHasZ = false; bool bFoundHasM = false; bool bFoundPolygon = false; bool bFoundPolyline = false; bool bFoundMultiPoint = false; bool bFoundX = false; bool bFoundY = false; bool bFoundZ = false; bool bFoundM = false; bool bFoundXMin = false; bool bFoundYMin = false; bool bFoundXMax = false; bool bFoundYMax = false; bool bFoundZMin = false; bool bFoundZMax = false; bool bFoundMMin = false; bool bFoundMMax = false; double x = com.epl.geometry.NumberUtils.NaN(); double y = com.epl.geometry.NumberUtils.NaN(); double z = com.epl.geometry.NumberUtils.NaN(); double m = com.epl.geometry.NumberUtils.NaN(); 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(); bool bHasZ = false; bool bHasM = false; com.epl.geometry.AttributeStreamOfDbl @as = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.AttributeStreamOfDbl bs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); com.epl.geometry.Geometry geometry = null; com.epl.geometry.SpatialReference spatial_reference = null; while (parser.NextToken() != com.epl.geometry.JsonReader.Token.END_OBJECT) { string name = parser.CurrentString(); parser.NextToken(); if (!bFoundSpatial_reference && name.Equals("spatialReference")) { bFoundSpatial_reference = true; if (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.START_OBJECT) { spatial_reference = com.epl.geometry.SpatialReference.FromJson(parser); } else { if (parser.CurrentToken() != com.epl.geometry.JsonReader.Token.VALUE_NULL) { throw new com.epl.geometry.GeometryException("failed to parse spatial reference: object or null is expected"); } } } else { if (!bFoundHasZ && name.Equals("hasZ")) { bFoundHasZ = true; bHasZ = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundHasM && name.Equals("hasM")) { bFoundHasM = true; bHasM = (parser.CurrentToken() == com.epl.geometry.JsonReader.Token.VALUE_TRUE); } else { if (!bFoundPolygon && name.Equals("rings") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polygon)) { bFoundPolygon = true; geometry = ImportFromJsonMultiPath(true, parser, @as, bs); continue; } else { if (!bFoundPolyline && name.Equals("paths") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Polyline)) { bFoundPolyline = true; geometry = ImportFromJsonMultiPath(false, parser, @as, bs); continue; } else { if (!bFoundMultiPoint && name.Equals("points") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.MultiPoint)) { bFoundMultiPoint = true; geometry = ImportFromJsonMultiPoint(parser, @as, bs); continue; } else { if (!bFoundX && name.Equals("x") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundX = true; x = ReadDouble(parser); } else { if (!bFoundY && name.Equals("y") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundY = true; y = ReadDouble(parser); } else { if (!bFoundZ && name.Equals("z") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundZ = true; z = ReadDouble(parser); } else { if (!bFoundM && name.Equals("m") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Point)) { bFoundM = true; m = ReadDouble(parser); } } } } } } } } } } if (!bFoundXMin && name.Equals("xmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMin = true; xmin = ReadDouble(parser); } else { if (!bFoundYMin && name.Equals("ymin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMin = true; ymin = ReadDouble(parser); } else { if (!bFoundMMin && name.Equals("mmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMin = true; mmin = ReadDouble(parser); } else { if (!bFoundZMin && name.Equals("zmin") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMin = true; zmin = ReadDouble(parser); } else { if (!bFoundXMax && name.Equals("xmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundXMax = true; xmax = ReadDouble(parser); } else { if (!bFoundYMax && name.Equals("ymax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundYMax = true; ymax = ReadDouble(parser); } else { if (!bFoundMMax && name.Equals("mmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundMMax = true; mmax = ReadDouble(parser); } else { if (!bFoundZMax && name.Equals("zmax") && (gt == com.epl.geometry.Geometry.GeometryType.Unknown || gt == com.epl.geometry.Geometry.GeometryType.Envelope)) { bFoundZMax = true; zmax = ReadDouble(parser); } else { Windup(parser); } } } } } } } } } if (bFoundPolygon || bFoundPolyline || bFoundMultiPoint) { System.Diagnostics.Debug.Assert((geometry != null)); com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl(); com.epl.geometry.AttributeStreamBase zs = null; com.epl.geometry.AttributeStreamBase ms = null; if (bHasZ) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); zs = @as; } if (bHasM) { geometry.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); ms = !bHasZ ? @as : bs; } if (bHasZ && zs != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs); } if (bHasM && ms != null) { mvImpl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms); } mvImpl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll); } else { if (bFoundX || bFoundY || bFoundY || bFoundZ) { if (com.epl.geometry.NumberUtils.IsNaN(y)) { x = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Point p = new com.epl.geometry.Point(x, y); if (bFoundZ) { p.SetZ(z); } if (bFoundM) { p.SetM(m); } geometry = p; } else { if (bFoundXMin || bFoundYMin || bFoundXMax || bFoundYMax || bFoundZMin || bFoundZMax || bFoundMMin || bFoundMMax) { if (com.epl.geometry.NumberUtils.IsNaN(ymin) || com.epl.geometry.NumberUtils.IsNaN(xmax) || com.epl.geometry.NumberUtils.IsNaN(ymax)) { xmin = com.epl.geometry.NumberUtils.NaN(); } com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(xmin, ymin, xmax, ymax); if (bFoundZMin && bFoundZMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, zmin, zmax); } if (bFoundMMin && bFoundMMax) { e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, mmin, mmax); } geometry = e; } } } mp = new com.epl.geometry.MapGeometry(geometry, spatial_reference); } catch (System.Exception) { return(null); } return(mp); }
/// <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); }