Search in sources :

Example 71 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class SnapTransformer method snapToSelf.

/**
 * Snaps the vertices in the component {@link LineString}s
 * of the source geometry
 * to the vertices of the same geometry.
 * Allows optionally cleaning the result to ensure it is
 * topologically valid
 * (which fixes issues such as topology collapses in polygonal inputs).
 *
 *@param snapTolerance the snapping tolerance
 *@param cleanResult whether the result should be made valid
 * @return a new snapped Geometry
 */
public Geometry snapToSelf(final double snapTolerance, final boolean cleanResult) {
    final Collection<Point> snapPoints = extractTargetCoordinates(this.srcGeom);
    if (snapPoints.isEmpty()) {
        return this.srcGeom;
    } else {
        final SnapTransformer snapTrans = new SnapTransformer(snapTolerance, snapPoints, true);
        final Geometry snappedGeom = snapTrans.transform(this.srcGeom);
        Geometry result = snappedGeom;
        if (cleanResult && result instanceof Polygonal) {
            // TODO: use better cleaning approach
            result = snappedGeom.buffer(0);
        }
        return result;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point)

Example 72 with Point

use of com.revolsys.geometry.model.Point 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 73 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class SnapTransformer method transformPoint.

@Override
protected Point transformPoint(final Point point) {
    final double x = point.getX();
    final double y = point.getY();
    final Point snapVert = findSnapForVertex(x, y);
    if (snapVert == null) {
        return point;
    } else {
        return snapVert;
    }
}
Also used : Point(com.revolsys.geometry.model.Point)

Example 74 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class FuzzyPointLocator method isWithinToleranceOfBoundary.

private boolean isWithinToleranceOfBoundary(final Point pt) {
    final double x = pt.getX();
    final double y = pt.getY();
    for (int i = 0; i < this.linework.getGeometryCount(); i++) {
        final LineString line = (LineString) this.linework.getGeometry(i);
        for (int j = 0; j < line.getVertexCount() - 1; j++) {
            final double x1 = line.getX(j);
            final double y1 = line.getY(j + 1);
            final double x2 = line.getX(j);
            final double y2 = line.getY(j + 1);
            final double dist = LineSegmentUtil.distanceLinePoint(x1, y1, x2, y2, x, y);
            if (dist <= this.boundaryDistanceTolerance) {
                return true;
            }
        }
    }
    return false;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 75 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class DistanceWithLocation method computePointLine.

private boolean computePointLine(final Point point, final LineString line) {
    final BoundingBox boundingBox = line.getBoundingBox();
    if (this.minDistance == Double.MAX_VALUE || boundingBox.distance(point) <= this.minDistance) {
        for (final Segment segment : line.segments()) {
            final double distance = segment.distancePoint(point);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                final Point closestPoint = segment.closestPoint(point);
                final int segmentIndex = segment.getSegmentIndex();
                this.minDistanceLocation1 = new GeometryLocation(point, 0, point);
                this.minDistanceLocation2 = new GeometryLocation(line, segmentIndex, closestPoint);
                if (this.minDistance <= this.terminateDistance) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment) Point(com.revolsys.geometry.model.Point)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14