private static Polygon getSubPolygon(Polygon polygon, int startIndex, int endIndex) { Polyline boundary = new Polyline(); boundary.startPath(polygon.getPoint(startIndex)); for (int i = startIndex + 1; i < endIndex; i++) { Point current = polygon.getPoint(i); boundary.lineTo(current); } final Polygon newPolygon = new Polygon(); newPolygon.add(boundary, false); return newPolygon; }
private static Point computeLineCentroid(Polyline polyline) { double xSum = 0; double ySum = 0; double weightSum = 0; for (int i = 0; i < polyline.getPathCount(); i++) { Point startPoint = polyline.getPoint(polyline.getPathStart(i)); Point endPoint = polyline.getPoint(polyline.getPathEnd(i) - 1); double dx = endPoint.getX() - startPoint.getX(); double dy = endPoint.getY() - startPoint.getY(); double length = sqrt(dx * dx + dy * dy); weightSum += length; xSum += (startPoint.getX() + endPoint.getX()) * length / 2; ySum += (startPoint.getY() + endPoint.getY()) * length / 2; } return new Point(xSum / weightSum, ySum / weightSum); }
private Geometry densifySegment(Segment geom) { double length = geom.calculateLength2D(); if (length <= m_maxLength) return (Geometry) geom; Polyline polyline = new Polyline(geom.getDescription()); polyline.addSegment(geom, true); return densifyMultiPath((MultiPath) polyline); }
private static boolean polylineOverlapsEnvelope_(Polyline polyline_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); polyline_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_a, env_b, tolerance) || envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; if (env_b.getHeight() > tolerance && env_b.getWidth() > tolerance) return false; // lines cannot overlap areas if (env_b.getHeight() <= tolerance && env_b.getWidth() <= tolerance) return false; // lines cannot overlap points // Treat as polyline Polyline polyline_b = new Polyline(); Point p = new Point(); envelope_b.queryCornerByVal(0, p); polyline_b.startPath(p); envelope_b.queryCornerByVal(2, p); polyline_b.lineTo(p); return linearPathOverlapsLinearPath_(polyline_a, polyline_b, tolerance); }
Polyline polyline = new Polyline(geometry.getDescription()); polyline.addSegment((Segment) geometry, true); return polyline; Polyline polyline = new Polyline(geometry.getDescription()); Point p = new Point(); envelope.queryCornerByVal(0, p); polyline.startPath(p); envelope.queryCornerByVal(2, p); polyline.lineTo(p); return polyline;
return null; MultiPathImpl mp = (MultiPathImpl) m_polyline._getImpl(); int npaths = mp.getPathCount(); if (m_current_path_index < npaths) { && m_current_path_index == m_polyline.getPathCount()) { Polyline pol = m_polyline; m_polyline = null; Polyline tmp_polyline = new Polyline( m_polyline.getDescription()); tmp_polyline.addPath(m_polyline, ind, true); for (int i = ind + 1; i < m_current_path_index; i++) { tmp_polyline.addSegmentsFromPath(m_polyline, i, 0, mp.getSegmentCount(i), false); if (m_current_path_index == m_polyline.getPathCount()) m_polyline = null;
public static Slice stLineString(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) MultiPath multipath = new Polyline(); OGCPoint previousPoint = null; for (int i = 0; i < input.getPositionCount(); i++) {
@Override public Geometry createInstance() { return new Polyline(getDescription()); }
private static Point2D computePolylineCentroid(Polyline polyline) { double xSum = 0; double ySum = 0; double weightSum = 0; Point2D startPoint = new Point2D(); Point2D endPoint = new Point2D(); for (int i = 0; i < polyline.getPathCount(); i++) { polyline.getXY(polyline.getPathStart(i), startPoint); polyline.getXY(polyline.getPathEnd(i) - 1, endPoint); double dx = endPoint.x - startPoint.x; double dy = endPoint.y - startPoint.y; double length = sqrt(dx * dx + dy * dy); weightSum += length; xSum += (startPoint.x + endPoint.x) * length / 2; ySum += (startPoint.y + endPoint.y) * length / 2; } return new Point2D(xSum / weightSum, ySum / weightSum); }
if (!multiType && ((Polyline) geometry).getPathCount() <= 1) { return new OGCLineString((Polyline) geometry, 0, null);
@Override public double length(Polyline p) { double d = 0; for (int i = 1; i < p.getPointCount(); ++i) { d += distance(p.getPoint(i - 1), p.getPoint(i)); } return d; }
Polyline polyline = (Polyline) geom; if (polyline.getPathCount() == 1 && polyline.getPointCount() == 2) { if (!polyline.getXY(0).equals(polyline.getXY(1))) return true; // vacuously true
ProgressTracker progressTracker) { MultiPathImpl polygon_impl_a = (MultiPathImpl) polygon_a._getImpl(); MultiPathImpl polyline_impl_b = (MultiPathImpl) polyline_b._getImpl(); polyline_b.queryEnvelope2D(env_b); env_a.inflate(1000.0 * tolerance, 1000.0 * tolerance); env_b.inflate(1000.0 * tolerance, 1000.0 * tolerance); if (polyline_b.getPointCount() > 10) { _polylineB = (Polyline) Clipper.clip(polyline_b, envInter, tolerance, 0.0); if (_polylineB.isEmpty()) { return false;
private Polyline preparePolyline_(Polyline input_geom) { // Generalize it firstly using 25% of the densification deviation as a // criterion. Polyline generalized_polyline = (Polyline) ((OperatorGeneralize) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.Generalize)).execute( input_geom, m_densify_dist * 0.25, false, m_progress_tracker); int path_point_count = 0; for (int i = 0, npath = generalized_polyline.getPathCount(); i < npath; i++) { path_point_count = Math.max(generalized_polyline.getPathSize(i), path_point_count); } if (path_point_count < 32) { m_bfilter = false; return generalized_polyline; } else { m_bfilter = true; // If we apply a filter to the polyline, then we have to resolve all // self intersections. Polyline simple_polyline = (Polyline) (TopologicalOperations .planarSimplify(generalized_polyline, m_small_tolerance, false, true, m_progress_tracker)); // Operator_factory_local::SaveJSONToTextFileDbg("c:/temp/buffer_simplify.txt", // *simple_polyline, nullptr); return simple_polyline; } }