Search in sources :

Example 6 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class EdgeRing method computePoints.

/**
 * Collect all the points from the DirectedEdges of this ring into a contiguous list
 */
private void computePoints(final DirectedEdge start) {
    final LineStringEditor points = new LineStringEditor(2, 10);
    this.startDe = start;
    DirectedEdge de = start;
    boolean isFirstEdge = true;
    do {
        // Assert.isTrue(de != null, "found null Directed Edge");
        if (de == null) {
            throw new TopologyException("Found null DirectedEdge");
        }
        if (de.getEdgeRing() == this) {
            throw new TopologyException("Directed Edge visited twice during ring-building at " + de.getCoordinate());
        }
        this.edges.add(de);
        final Label label = de.getLabel();
        if (!label.isArea()) {
            throw new IllegalStateException("Label is not an area");
        }
        mergeLabel(label);
        addPoints(points, de.getEdge(), de.isForward(), isFirstEdge);
        isFirstEdge = false;
        setEdgeRing(de, this);
        de = getNext(de);
    } while (de != this.startDe);
    this.ring = points.newLinearRing();
    this.isHole = this.ring.isCounterClockwise();
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 7 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class Clipper method clip.

public static LineString clip(final LineString line, final double line1x1, final double line1y1, final double line1x2, final double line1y2) {
    final LineStringEditor result = new LineStringEditor(line.getGeometryFactory(), line.getVertexCount());
    line.forEachSegment((line2x1, line2y1, line2x2, line2y2) -> {
        if (isInside(line1x1, line1y1, line1x2, line1y2, line2x2, line2y2)) {
            if (!isInside(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1)) {
                addIntersection(result, line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
            }
            result.appendVertex(line2x2, line2y2);
        } else if (isInside(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1)) {
            addIntersection(result, line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
        }
    });
    if (!result.isClosed() && !result.isEmpty()) {
        result.appendVertex(result.getX(0), result.getY(0));
    }
    return result;
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 8 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class SnapTransformer method snapSegments.

/**
 * Snap segments of the source to nearby snap vertices.
 * Source segments are "cracked" at a snap vertex.
 * A single input segment may be snapped several times
 * to different snap vertices.
 * <p>
 * For each distinct snap vertex, at most one source segment
 * is snapped to.  This prevents "cracking" multiple segments
 * at the same point, which would likely cause
 * topology collapse when being used on polygonal linework.
 *
 * @param newCoordinates the coordinates of the source linestring to be snapped
 * @param snapPoints the target snap vertices
 */
private LineString snapSegments(LineString line) {
    LineStringEditor newLine = null;
    for (final Point snapPoint : this.snapPoints) {
        final int index = findSegmentIndexToSnap(snapPoint, line);
        /**
         * If a segment to snap to was found, "crack" it at the snap pt.
         * The new pt is inserted immediately into the src segment list,
         * so that subsequent snapping will take place on the modified segments.
         * Duplicate points are not added.
         */
        if (index >= 0) {
            if (newLine == null) {
                if (line instanceof LineStringEditor) {
                    newLine = (LineStringEditor) line;
                } else {
                    newLine = LineStringEditor.newLineStringEditor(line);
                    line = newLine;
                }
            }
            newLine.insertVertex(index + 1, snapPoint, false);
        }
    }
    if (newLine == null) {
        return line;
    } else {
        return newLine;
    }
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor) Point(com.revolsys.geometry.model.Point)

Example 9 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class LineString method newGeometryEditor.

@Override
default LineStringEditor newGeometryEditor(final int axisCount) {
    final LineStringEditor geometryEditor = newGeometryEditor();
    geometryEditor.setAxisCount(axisCount);
    return geometryEditor;
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Example 10 with LineStringEditor

use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.

the class LineString method editLine.

default LineString editLine(final Consumer<LineStringEditor> edit) {
    final LineStringEditor editor = newGeometryEditor();
    edit.accept(editor);
    if (editor.isModified()) {
        return editor.newGeometry();
    } else {
        return this;
    }
}
Also used : LineStringEditor(com.revolsys.geometry.model.editor.LineStringEditor)

Aggregations

LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)35 LineString (com.revolsys.geometry.model.LineString)13 Test (org.junit.Test)13 Point (com.revolsys.geometry.model.Point)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 ArrayList (java.util.ArrayList)3 TopologyException (com.revolsys.geometry.model.TopologyException)1 AbstractPoint (com.revolsys.geometry.model.impl.AbstractPoint)1 PreparedLineString (com.revolsys.geometry.model.prep.PreparedLineString)1 ArcLineString (com.revolsys.record.io.format.saif.geometry.ArcLineString)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1