// Mirrors wkt private static void ExportPolylineToGeoJson_(int export_flags, com.epl.geometry.Polyline polyline, com.epl.geometry.JsonWriter json_writer) { com.epl.geometry.MultiPathImpl polyline_impl = (com.epl.geometry.MultiPathImpl)polyline._getImpl(); int point_count = polyline_impl.GetPointCount(); int path_count = polyline_impl.GetPathCount(); if (point_count > 0 && path_count == 0) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } int precision = 17 - (31 & (export_flags >> 13)); bool bFixedPoint = (com.epl.geometry.GeoJsonExportFlags.geoJsonExportPrecisionFixedPoint & export_flags) != 0; bool b_export_zs = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportStripZs) == 0; bool b_export_ms = polyline_impl.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"); } com.epl.geometry.AttributeStreamOfDbl position = null; com.epl.geometry.AttributeStreamOfDbl zs = null; com.epl.geometry.AttributeStreamOfDbl ms = null; com.epl.geometry.AttributeStreamOfInt8 path_flags = null; com.epl.geometry.AttributeStreamOfInt32 paths = null; if (point_count > 0) { position = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); path_flags = polyline_impl.GetPathFlagsStreamRef(); paths = polyline_impl.GetPathStreamRef(); if (b_export_zs) { if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z)) { zs = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z); } } if (b_export_ms) { if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M)) { ms = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M); } } } if ((export_flags & com.epl.geometry.GeoJsonExportFlags.geoJsonExportPreferMultiGeometry) == 0 && path_count <= 1) { LineStringTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, json_writer); } else { MultiLineStringTaggedText_(precision, bFixedPoint, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, json_writer); } }
internal static void ExportPolylineToWkt(int export_flags, com.epl.geometry.Polyline polyline, System.Text.StringBuilder @string) { com.epl.geometry.MultiPathImpl polyline_impl = (com.epl.geometry.MultiPathImpl)polyline._getImpl(); int point_count = polyline_impl.GetPointCount(); int path_count = polyline_impl.GetPathCount(); if (point_count > 0 && path_count == 0) { throw new com.epl.geometry.GeometryException("corrupted geometry"); } int precision = 17 - (7 & (export_flags >> 13)); bool b_export_zs = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripZs) == 0; bool b_export_ms = polyline_impl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (export_flags & com.epl.geometry.WktExportFlags.wktExportStripMs) == 0; com.epl.geometry.AttributeStreamOfDbl position = null; com.epl.geometry.AttributeStreamOfDbl zs = null; com.epl.geometry.AttributeStreamOfDbl ms = null; com.epl.geometry.AttributeStreamOfInt8 path_flags = null; com.epl.geometry.AttributeStreamOfInt32 paths = null; if (point_count > 0) { position = (com.epl.geometry.AttributeStreamOfDbl)polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); path_flags = polyline_impl.GetPathFlagsStreamRef(); paths = polyline_impl.GetPathStreamRef(); if (b_export_zs) { if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z)) { zs = (com.epl.geometry.AttributeStreamOfDbl)(polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z)); } } if (b_export_ms) { if (polyline_impl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M)) { ms = (com.epl.geometry.AttributeStreamOfDbl)(polyline_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M)); } } } if ((export_flags & com.epl.geometry.WktExportFlags.wktExportLineString) != 0) { if (path_count > 1) { throw new System.ArgumentException("Cannot export a LineString with specified export flags: " + export_flags); } LineStringTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, @string); } else { MultiLineStringTaggedText_(precision, b_export_zs, b_export_ms, zs, ms, position, path_flags, paths, path_count, @string); } }
/// <summary>Returns true if the given path of the input MultiPath is convex.</summary> /// <remarks> /// Returns true if the given path of the input MultiPath is convex. Returns false otherwise. /// \param multi_path The MultiPath to check if the path is convex. /// \param path_index The path of the MultiPath to check if its convex. /// </remarks> internal static bool IsPathConvex(com.epl.geometry.MultiPath multi_path, int path_index, com.epl.geometry.ProgressTracker progress_tracker) { com.epl.geometry.MultiPathImpl mimpl = (com.epl.geometry.MultiPathImpl)multi_path._getImpl(); int path_start = mimpl.GetPathStart(path_index); int path_end = mimpl.GetPathEnd(path_index); bool bxyclosed = !mimpl.IsClosedPath(path_index) && mimpl.IsClosedPathInXYPlane(path_index); com.epl.geometry.AttributeStreamOfDbl position = (com.epl.geometry.AttributeStreamOfDbl)(mimpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION)); int position_start = 2 * path_start; int position_end = 2 * path_end; if (bxyclosed) { position_end -= 2; } if (position_end - position_start < 6) { return(true); } // This matches the logic for case 1 of the tree hull algorithm. The idea is inductive. We assume we have a convex hull pt_0,...,pt_m, and we see if // a new point (pt_pivot) is among the transitive tournament for pt_0, knowing that pt_pivot comes after pt_m. // We check three conditions: // 1) pt_m->pt_pivot->pt_0 is clockwise (closure across the boundary is convex) // 2) pt_1->pt_pivot->pt_0 is clockwise (the first step forward is convex) (pt_1 is the next point after pt_0) // 3) pt_m->pt_pivot->pt_m_prev is clockwise (the first step backwards is convex) (pt_m_prev is the previous point before pt_m) // If all three of the above conditions are clockwise, then pt_pivot is among the transitive tournament for pt_0, and therefore the polygon pt_0, ..., pt_m, pt_pivot is convex. com.epl.geometry.Point2D pt_0 = new com.epl.geometry.Point2D(); com.epl.geometry.Point2D pt_m = new com.epl.geometry.Point2D(); com.epl.geometry.Point2D pt_pivot = new com.epl.geometry.Point2D(); position.Read(position_start, pt_0); position.Read(position_start + 2, pt_m); position.Read(position_start + 4, pt_pivot); // Initial inductive step com.epl.geometry.ECoordinate det_ec = Determinant_(pt_m, pt_pivot, pt_0); if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value())) { return(false); } com.epl.geometry.Point2D pt_1 = new com.epl.geometry.Point2D(pt_m.x, pt_m.y); com.epl.geometry.Point2D pt_m_prev = new com.epl.geometry.Point2D(); // Assume that pt_0,...,pt_m is convex. Check if the next point, pt_pivot, maintains the convex invariant. for (int i = position_start + 6; i < position_end; i += 2) { pt_m_prev.SetCoords(pt_m); pt_m.SetCoords(pt_pivot); position.Read(i, pt_pivot); det_ec = Determinant_(pt_m, pt_pivot, pt_0); if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value())) { return(false); } det_ec = Determinant_(pt_1, pt_pivot, pt_0); if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value())) { return(false); } det_ec = Determinant_(pt_m, pt_pivot, pt_m_prev); if (det_ec.IsFuzzyZero() || !IsClockwise_(det_ec.Value())) { return(false); } } return(true); }
private static int ExportMultiPathToESRIShape(bool bPolygon, int exportFlags, com.epl.geometry.MultiPath multipath, System.IO.BinaryWriter shapeBuffer) { com.epl.geometry.MultiPathImpl multipathImpl = (com.epl.geometry.MultiPathImpl)multipath._getImpl(); bool bExportZs = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripZs) == 0; bool bExportMs = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripMs) == 0; bool bExportIDs = multipathImpl.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID) && (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportStripIDs) == 0; bool bHasCurves = multipathImpl.HasNonLinearSegments(); bool bArcViewNaNs = (exportFlags & com.epl.geometry.ShapeExportFlags.ShapeExportTrueNaNs) == 0; int partCount = multipathImpl.GetPathCount(); int pointCount = multipathImpl.GetPointCount(); if (!bPolygon) { for (int ipart = 0; ipart < partCount; ipart++) { if (multipath.IsClosedPath(ipart)) { pointCount++; } } } else { pointCount += partCount; } 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 (bHasCurves) { } // to-do: curves if (size >= com.epl.geometry.NumberUtils.IntMax()) { throw new com.epl.geometry.GeometryException("invalid call"); } 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 offset = 0; // Determine the shape type int type; if (!bExportZs && !bExportMs) { if (bExportIDs || bHasCurves) { type = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline; if (bExportIDs) { type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs; } if (bHasCurves) { type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves; } } else { type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygon : com.epl.geometry.ShapeType.ShapePolyline; } } else { if (bExportZs && !bExportMs) { if (bExportIDs || bHasCurves) { type = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline; type |= com.epl.geometry.ShapeModifiers.ShapeHasZs; if (bExportIDs) { type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs; } if (bHasCurves) { type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves; } } else { type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonZ : com.epl.geometry.ShapeType.ShapePolylineZ; } } else { if (bExportMs && !bExportZs) { if (bExportIDs || bHasCurves) { type = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline; type |= com.epl.geometry.ShapeModifiers.ShapeHasMs; if (bExportIDs) { type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs; } if (bHasCurves) { type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves; } } else { type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonM : com.epl.geometry.ShapeType.ShapePolylineM; } } else { if (bExportIDs || bHasCurves) { type = bPolygon ? com.epl.geometry.ShapeType.ShapeGeneralPolygon : com.epl.geometry.ShapeType.ShapeGeneralPolyline; type |= com.epl.geometry.ShapeModifiers.ShapeHasZs | com.epl.geometry.ShapeModifiers.ShapeHasMs; if (bExportIDs) { type |= com.epl.geometry.ShapeModifiers.ShapeHasIDs; } if (bHasCurves) { type |= com.epl.geometry.ShapeModifiers.ShapeHasCurves; } } else { type = bPolygon ? com.epl.geometry.ShapeType.ShapePolygonZM : com.epl.geometry.ShapeType.ShapePolylineZM; } } } } // write type shapeBuffer.Write(type); offset += 4; // write Envelope com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); multipathImpl.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; // to-do: return error if larger than 2^32 - 1 // write pointCount shapeBuffer.Write(pointCount); offset += 4; // write start indices for each part int pointIndexDelta = 0; for (int ipart = 0; ipart < partCount; ipart++) { int istart = multipathImpl.GetPathStart(ipart) + pointIndexDelta; shapeBuffer.Write(istart); offset += 4; if (bPolygon || multipathImpl.IsClosedPath(ipart)) { pointIndexDelta++; } } if (pointCount > 0) { // write xy coordinates com.epl.geometry.AttributeStreamBase positionStream = multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); com.epl.geometry.AttributeStreamOfDbl position = (com.epl.geometry.AttributeStreamOfDbl)positionStream; for (int ipart = 0; ipart < partCount; ipart++) { int partStart = multipathImpl.GetPathStart(ipart); int partEnd = multipathImpl.GetPathEnd(ipart); for (int i = partStart; i < partEnd; i++) { double x = position.Read(2 * i); double y = position.Read(2 * i + 1); shapeBuffer.Write(x); offset += 8; shapeBuffer.Write(y); offset += 8; } // If the part is closed, then we need to duplicate the start // point if (bPolygon || multipathImpl.IsClosedPath(ipart)) { double x = position.Read(2 * partStart); double y = position.Read(2 * partStart + 1); shapeBuffer.Write(x); offset += 8; shapeBuffer.Write(y); offset += 8; } } } // write Zs if (bExportZs) { com.epl.geometry.Envelope1D zInterval = multipathImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0); shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmin) : zInterval.vmin); offset += 8; shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(zInterval.vmax) : zInterval.vmax); offset += 8; if (pointCount > 0) { if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.Z)) { com.epl.geometry.AttributeStreamOfDbl zs = (com.epl.geometry.AttributeStreamOfDbl)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z); for (int ipart = 0; ipart < partCount; ipart++) { int partStart = multipathImpl.GetPathStart(ipart); int partEnd = multipathImpl.GetPathEnd(ipart); for (int i = partStart; i < partEnd; i++) { double z = zs.Read(i); shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(z) : z); offset += 8; } // If the part is closed, then we need to duplicate the // start z if (bPolygon || multipathImpl.IsClosedPath(ipart)) { double z = zs.Read(partStart); shapeBuffer.Write(z); offset += 8; } } } else { double z = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.Z); if (bArcViewNaNs) { z = com.epl.geometry.Interop.TranslateToAVNaN(z); } for (int i = 0; i < pointCount; i++) { shapeBuffer.Write(z); } offset += 8; } } } // write Ms if (bExportMs) { com.epl.geometry.Envelope1D mInterval = multipathImpl.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0); shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmin) : mInterval.vmin); offset += 8; shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(mInterval.vmax) : mInterval.vmax); offset += 8; if (pointCount > 0) { if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.M)) { com.epl.geometry.AttributeStreamOfDbl ms = (com.epl.geometry.AttributeStreamOfDbl)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M); for (int ipart = 0; ipart < partCount; ipart++) { int partStart = multipathImpl.GetPathStart(ipart); int partEnd = multipathImpl.GetPathEnd(ipart); for (int i = partStart; i < partEnd; i++) { double m = ms.Read(i); shapeBuffer.Write(bArcViewNaNs ? com.epl.geometry.Interop.TranslateToAVNaN(m) : m); offset += 8; } // If the part is closed, then we need to duplicate the // start m if (bPolygon || multipathImpl.IsClosedPath(ipart)) { double m = ms.Read(partStart); shapeBuffer.Write(m); offset += 8; } } } else { double m = com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.M); if (bArcViewNaNs) { m = com.epl.geometry.Interop.TranslateToAVNaN(m); } for (int i = 0; i < pointCount; i++) { shapeBuffer.Write(m); } offset += 8; } } } // write Curves if (bHasCurves) { } // to-do: We'll finish this later // write IDs if (bExportIDs) { if (pointCount > 0) { if (multipathImpl._attributeStreamIsAllocated(com.epl.geometry.VertexDescription.Semantics.ID)) { com.epl.geometry.AttributeStreamOfInt32 ids = (com.epl.geometry.AttributeStreamOfInt32)multipathImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID); for (int ipart = 0; ipart < partCount; ipart++) { int partStart = multipathImpl.GetPathStart(ipart); int partEnd = multipathImpl.GetPathEnd(ipart); for (int i = partStart; i < partEnd; i++) { int id = ids.Read(i); shapeBuffer.Write(id); offset += 4; } // If the part is closed, then we need to duplicate the // start id if (bPolygon || multipathImpl.IsClosedPath(ipart)) { int id = ids.Read(partStart); shapeBuffer.Write(id); offset += 4; } } } else { int id = (int)com.epl.geometry.VertexDescription.GetDefaultValue(com.epl.geometry.VertexDescription.Semantics.ID); for (int i = 0; i < pointCount; i++) { shapeBuffer.Write(id); } offset += 4; } } } return(offset); }
private void GeneralizePath(com.epl.geometry.MultiPathImpl mpsrc, int ipath, com.epl.geometry.MultiPathImpl mpdst, com.epl.geometry.Line lineHelper) { if (mpsrc.GetPathSize(ipath) < 2) { return; } int start = mpsrc.GetPathStart(ipath); int end = mpsrc.GetPathEnd(ipath) - 1; com.epl.geometry.AttributeStreamOfDbl xy = (com.epl.geometry.AttributeStreamOfDbl)mpsrc.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); bool bClosed = mpsrc.IsClosedPath(ipath); com.epl.geometry.AttributeStreamOfInt32 stack = new com.epl.geometry.AttributeStreamOfInt32(0); stack.Reserve(mpsrc.GetPathSize(ipath) + 1); com.epl.geometry.AttributeStreamOfInt32 resultStack = new com.epl.geometry.AttributeStreamOfInt32(0); resultStack.Reserve(mpsrc.GetPathSize(ipath) + 1); stack.Add(bClosed ? start : end); stack.Add(start); com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); while (stack.Size() > 1) { int i1 = stack.GetLast(); stack.RemoveLast(); int i2 = stack.GetLast(); mpsrc.GetXY(i1, pt); lineHelper.SetStartXY(pt); mpsrc.GetXY(i2, pt); lineHelper.SetEndXY(pt); int mid = FindGreatestDistance(lineHelper, pt, xy, i1, i2, end); if (mid >= 0) { stack.Add(mid); stack.Add(i1); } else { resultStack.Add(i1); } } if (!bClosed) { resultStack.Add(stack.Get(0)); } int rs_size = resultStack.Size(); int path_size = mpsrc.GetPathSize(ipath); if (rs_size == path_size && rs_size == stack.Size()) { mpdst.AddPath(mpsrc, ipath, true); } else { if (resultStack.Size() > 0) { if (m_bRemoveDegenerateParts && resultStack.Size() <= 2) { if (bClosed || resultStack.Size() == 1) { return; } double d = com.epl.geometry.Point2D.Distance(mpsrc.GetXY(resultStack.Get(0)), mpsrc.GetXY(resultStack.Get(1))); if (d <= m_maxDeviation) { return; } } com.epl.geometry.Point point = new com.epl.geometry.Point(); for (int i = 0, n = resultStack.Size(); i < n; i++) { mpsrc.GetPointByVal(resultStack.Get(i), point); if (i == 0) { mpdst.StartPath(point); } else { mpdst.LineTo(point); } } if (bClosed) { for (int i_1 = resultStack.Size(); i_1 < 3; i_1++) { mpdst.LineTo(point); } mpdst.ClosePathWithLine(); } } } }
internal static com.epl.geometry.MultiPoint CalculatePolylineBoundary_(object impl, com.epl.geometry.ProgressTracker progress_tracker, bool only_check_non_empty_boundary, bool[] not_empty) { if (not_empty != null) { not_empty[0] = false; } com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)impl; com.epl.geometry.MultiPoint dst = null; if (!only_check_non_empty_boundary) { dst = new com.epl.geometry.MultiPoint(mpImpl.GetDescription()); } if (!mpImpl.IsEmpty()) { com.epl.geometry.AttributeStreamOfInt32 indices = new com.epl.geometry.AttributeStreamOfInt32(0); indices.Reserve(mpImpl.GetPathCount() * 2); for (int ipath = 0, nPathCount = mpImpl.GetPathCount(); ipath < nPathCount; ipath++) { int path_size = mpImpl.GetPathSize(ipath); if (path_size > 0 && !mpImpl.IsClosedPathInXYPlane(ipath)) { // closed // paths // of // polyline // do // not // contribute // to // the // boundary. int start = mpImpl.GetPathStart(ipath); indices.Add(start); int end = mpImpl.GetPathEnd(ipath) - 1; indices.Add(end); } } if (indices.Size() > 0) { com.epl.geometry.BucketSort sorter = new com.epl.geometry.BucketSort(); com.epl.geometry.AttributeStreamOfDbl xy = (com.epl.geometry.AttributeStreamOfDbl)(mpImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION)); sorter.Sort(indices, 0, indices.Size(), new com.epl.geometry.Boundary.MultiPathImplBoundarySorter(xy)); com.epl.geometry.Point2D ptPrev = new com.epl.geometry.Point2D(); xy.Read(2 * indices.Get(0), ptPrev); int ind = 0; int counter = 1; com.epl.geometry.Point point = new com.epl.geometry.Point(); com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); for (int i = 1, n = indices.Size(); i < n; i++) { xy.Read(2 * indices.Get(i), pt); if (pt.IsEqual(ptPrev)) { if (indices.Get(ind) > indices.Get(i)) { // remove duplicate point indices.Set(ind, com.epl.geometry.NumberUtils.IntMax()); ind = i; } else { // just for the heck of it, have the first // point in the order to be added to the // boundary. indices.Set(i, com.epl.geometry.NumberUtils.IntMax()); } counter++; } else { if ((counter & 1) == 0) { // remove boundary point indices.Set(ind, com.epl.geometry.NumberUtils.IntMax()); } else { if (only_check_non_empty_boundary) { if (not_empty != null) { not_empty[0] = true; } return(null); } } ptPrev.SetCoords(pt); ind = i; counter = 1; } } if ((counter & 1) == 0) { // remove the point indices.Set(ind, com.epl.geometry.NumberUtils.IntMax()); } else { if (only_check_non_empty_boundary) { if (not_empty != null) { not_empty[0] = true; } return(null); } } if (!only_check_non_empty_boundary) { indices.Sort(0, indices.Size()); for (int i_1 = 0, n = indices.Size(); i_1 < n; i_1++) { if (indices.Get(i_1) == com.epl.geometry.NumberUtils.IntMax()) { break; } mpImpl.GetPointByVal(indices.Get(i_1), point); dst.Add(point); } } } } if (only_check_non_empty_boundary) { return(null); } return(dst); }
private static void ExportPolypathToJson(com.epl.geometry.MultiPath pp, string name, com.epl.geometry.SpatialReference spatialReference, com.epl.geometry.JsonWriter jsonWriter, System.Collections.Generic.IDictionary <string, object> exportProperties) { bool bExportZs = pp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z); bool bExportMs = pp.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(name); if (!pp.IsEmpty()) { int n = pp.GetPathCount(); // rings or paths com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)pp._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); } bool bPolygon = pp is com.epl.geometry.Polygon; com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); for (int i = 0; i < n; i++) { jsonWriter.AddValueArray(); int startindex = pp.GetPathStart(i); int numVertices = pp.GetPathSize(i); double startx = 0.0; double starty = 0.0; double startz = com.epl.geometry.NumberUtils.NaN(); double startm = com.epl.geometry.NumberUtils.NaN(); double z = com.epl.geometry.NumberUtils.NaN(); double m = com.epl.geometry.NumberUtils.NaN(); bool bClosed = pp.IsClosedPath(i); for (int j = startindex; j < startindex + numVertices; j++) { pp.GetXY(j, 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) { z = zs.Get(j); jsonWriter.AddValueDouble(z); } if (bExportMs) { m = ms.Get(j); jsonWriter.AddValueDouble(m); } if (j == startindex && bClosed) { startx = pt.x; starty = pt.y; startz = z; startm = m; } jsonWriter.EndArray(); } // Close the Path/Ring by writing the Point at the start index if (bClosed && (startx != pt.x || starty != pt.y || (bExportZs && !(com.epl.geometry.NumberUtils.IsNaN(startz) && com.epl.geometry.NumberUtils.IsNaN(z)) && startz != z) || (bExportMs && !(com.epl.geometry.NumberUtils.IsNaN(startm) && com.epl.geometry.NumberUtils.IsNaN(m)) && startm != m))) { pp.GetXY(startindex, pt); // getPoint(startindex); 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) { z = zs.Get(startindex); jsonWriter.AddValueDouble(z); } if (bExportMs) { m = ms.Get(startindex); jsonWriter.AddValueDouble(m); } jsonWriter.EndArray(); } jsonWriter.EndArray(); } } jsonWriter.EndArray(); if (spatialReference != null) { WriteSR(spatialReference, jsonWriter); } jsonWriter.EndObject(); }