public static void CompareGeometryContent(com.epl.geometry.MultiPoint geom1, com.epl.geometry.MultiPoint geom2) { // Geometry types NUnit.Framework.Assert.IsTrue(geom1.GetType().Value() == geom2.GetType().Value()); // Envelopes com.epl.geometry.Envelope env1 = new com.epl.geometry.Envelope(); geom1.QueryEnvelope(env1); com.epl.geometry.Envelope env2 = new com.epl.geometry.Envelope(); geom2.QueryEnvelope(env2); NUnit.Framework.Assert.IsTrue(env1.GetXMin() == env2.GetXMin() && env1.GetXMax() == env2.GetXMax() && env1.GetYMin() == env2.GetYMin() && env1.GetYMax() == env2.GetYMax()); // Point count int pointCount1 = geom1.GetPointCount(); int pointCount2 = geom2.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2); com.epl.geometry.Point point1; com.epl.geometry.Point point2; for (int i = 0; i < pointCount1; i++) { point1 = geom1.GetPoint(i); point2 = geom2.GetPoint(i); double x1 = point1.GetX(); double x2 = point2.GetX(); NUnit.Framework.Assert.IsTrue(x1 == x2); double y1 = point1.GetY(); double y2 = point2.GetY(); NUnit.Framework.Assert.IsTrue(y1 == y2); } }
public static void TestClipIssue258243() { com.epl.geometry.Polygon poly1 = new com.epl.geometry.Polygon(); poly1.StartPath(21.476191371901479, 41.267022001907215); poly1.LineTo(59.669186665158051, 36.62700518555863); poly1.LineTo(20.498578117352313, 30.363180148246094); poly1.LineTo(18.342565836615044, 46.303295352085627); poly1.LineTo(17.869569458621626, 23.886816966894159); poly1.LineTo(19.835465558090434, 20); poly1.LineTo(18.83911285048551, 43.515995498114791); poly1.LineTo(20.864485260298004, 20.235921201027757); poly1.LineTo(18.976127544787012, 20); poly1.LineTo(34.290201277718218, 61.801369014954794); poly1.LineTo(20.734727419368866, 20); poly1.LineTo(18.545865698148113, 20); poly1.LineTo(19.730260558565515, 20); poly1.LineTo(19.924806216827005, 23.780315893949187); poly1.LineTo(21.675168105421452, 36.699924873001258); poly1.LineTo(22.500527828912158, 43.703424859922983); poly1.LineTo(42.009527116514818, 36.995486982256089); poly1.LineTo(24.469729873835782, 58.365871758247039); poly1.LineTo(24.573736036545878, 36.268390409195824); poly1.LineTo(22.726502169802746, 20); poly1.LineTo(23.925834885228145, 20); poly1.LineTo(25.495346880936729, 20); poly1.LineTo(23.320941499288317, 20); poly1.LineTo(24.05655665646276, 28.659578774758632); poly1.LineTo(23.205940789341135, 38.491506888710504); poly1.LineTo(21.472847203385509, 53.057228182018044); poly1.LineTo(25.04257681654104, 20); poly1.LineTo(25.880572351149542, 25.16102863979474); poly1.LineTo(26.756283333879658, 20); poly1.LineTo(21.476191371901479, 41.267022001907215); com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793); try { com.epl.geometry.Geometry output_geom = com.epl.geometry.OperatorClip.Local().Execute(poly1, env, com.epl.geometry.SpatialReference.Create(4326), null); com.epl.geometry.Envelope envPoly = new com.epl.geometry.Envelope(); poly1.QueryEnvelope(envPoly); com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(env); e.Intersect(envPoly); com.epl.geometry.Envelope clippedEnv = new com.epl.geometry.Envelope(); output_geom.QueryEnvelope(clippedEnv); NUnit.Framework.Assert.IsTrue(System.Math.Abs(clippedEnv.GetXMin() - e.GetXMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMin() - e.GetYMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetXMax() - e.GetXMax()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMax() - e.GetYMax()) < 1e-10); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue(false); } }
// 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); } }
internal virtual com.epl.geometry.Point _snapClip(com.epl.geometry.Point pt, com.epl.geometry.Envelope env) { double x = pt.GetX(); if (x < env.GetXMin()) { x = env.GetXMin(); } if (x > env.GetXMax()) { x = env.GetXMax(); } double y = pt.GetY(); if (y < env.GetYMin()) { y = env.GetYMin(); } if (y > env.GetYMax()) { y = env.GetYMax(); } return(new com.epl.geometry.Point(x, y)); }
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); } }
public virtual void TestEnvelope() { 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.CreateJsonParser(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()); com.epl.geometry.Envelope emptyEnvelope = new com.epl.geometry.Envelope(); string emptyEnvString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyEnvelope); envelopeWGS84Parser = factory.CreateJsonParser(emptyEnvString); envelopeWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelopeWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == envelopeWGS84MP.GetSpatialReference().GetID()); } }
/// <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"); } }
/// <summary>Calculates the clipped geometry from a target geometry using an envelope.</summary> /// <remarks> /// Calculates the clipped geometry from a target geometry using an envelope. /// See OperatorClip. /// </remarks> /// <param name="geometry">The geometry to be clipped.</param> /// <param name="envelope">The envelope used to clip.</param> /// <param name="spatialReference">The spatial reference of the geometries.</param> /// <returns>The geometry created by clipping.</returns> public static com.epl.geometry.Geometry Clip(com.epl.geometry.Geometry geometry, com.epl.geometry.Envelope envelope, com.epl.geometry.SpatialReference spatialReference) { com.epl.geometry.OperatorClip op = (com.epl.geometry.OperatorClip)factory.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Geometry result = op.Execute(geometry, com.epl.geometry.Envelope2D.Construct(envelope.GetXMin(), envelope.GetYMin(), envelope.GetXMax(), envelope.GetYMax()), spatialReference, null); return(result); }
internal static bool IsConvex_(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker) { if (geom.IsEmpty()) { return(true); } // vacuously true com.epl.geometry.Geometry.Type type = geom.GetType(); if (type == com.epl.geometry.Geometry.Type.Point) { return(true); } // vacuously true if (type == com.epl.geometry.Geometry.Type.Envelope) { com.epl.geometry.Envelope envelope = (com.epl.geometry.Envelope)geom; if (envelope.GetXMin() == envelope.GetXMax() || envelope.GetYMin() == envelope.GetYMax()) { return(false); } return(true); } if (com.epl.geometry.MultiPath.IsSegment(type.Value())) { com.epl.geometry.Segment segment = (com.epl.geometry.Segment)geom; if (segment.GetStartXY().Equals(segment.GetEndXY())) { return(false); } return(true); } // true, but we will upgrade to a Polyline for the ConvexHull operation if (type == com.epl.geometry.Geometry.Type.MultiPoint) { com.epl.geometry.MultiPoint multi_point = (com.epl.geometry.MultiPoint)geom; if (multi_point.GetPointCount() == 1) { return(true); } // vacuously true, but we will downgrade to a Point for the ConvexHull operation return(false); } if (type == com.epl.geometry.Geometry.Type.Polyline) { com.epl.geometry.Polyline polyline = (com.epl.geometry.Polyline)geom; if (polyline.GetPathCount() == 1 && polyline.GetPointCount() == 2) { if (!polyline.GetXY(0).Equals(polyline.GetXY(1))) { return(true); } } // vacuously true return(false); } // create convex hull com.epl.geometry.Polygon polygon = (com.epl.geometry.Polygon)geom; if (polygon.GetPathCount() != 1 || polygon.GetPointCount() < 3) { return(false); } return(com.epl.geometry.ConvexHull.IsPathConvex(polygon, 0, progress_tracker)); }
/// <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(); }