Search in sources :

Example 6 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector in project com.revolsys.open by revolsys.

the class CGAlgorithmFunctions method segmentIntersection.

public static Geometry segmentIntersection(final Geometry g1, final Geometry g2) {
    final Point[] pt1 = CoordinatesListUtil.getPointArray(g1);
    final Point[] pt2 = CoordinatesListUtil.getPointArray(g2);
    final RobustLineIntersector ri = new RobustLineIntersector();
    ri.computeIntersectionPoints(pt1[0], pt1[1], pt2[0], pt2[1]);
    switch(ri.getIntersectionCount()) {
        case 0:
            // no intersection => return empty point
            return g1.getGeometryFactory().point();
        case 1:
            // return point
            return g1.getGeometryFactory().point(ri.getIntersection(0));
        case 2:
            // return line
            return g1.getGeometryFactory().lineString(new Point[] { ri.getIntersection(0), ri.getIntersection(1) });
    }
    return null;
}
Also used : Point(com.revolsys.geometry.model.Point) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector)

Example 7 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector in project com.revolsys.open by revolsys.

the class NodingFunctions method MCIndexNoding.

public static Geometry MCIndexNoding(final Geometry geom) {
    final List segs = newNodedSegmentStrings(geom);
    final Noder noder = new MCIndexNoder(new IntersectionAdder(new RobustLineIntersector()));
    noder.computeNodes(segs);
    final Collection nodedSegStrings = noder.getNodedSubstrings();
    return fromSegmentStrings(nodedSegStrings);
}
Also used : MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) IntersectionAdder(com.revolsys.geometry.noding.IntersectionAdder) MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) Noder(com.revolsys.geometry.noding.Noder) ScaledNoder(com.revolsys.geometry.noding.ScaledNoder)

Example 8 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector in project com.revolsys.open by revolsys.

the class LineString method isOnLine.

default boolean isOnLine(final double x, final double y) {
    final LineIntersector lineIntersector = new RobustLineIntersector();
    double x1 = getX(0);
    double y1 = getY(0);
    final int vertexCount = getVertexCount();
    for (int i = 1; i < vertexCount; i++) {
        final double x2 = getX(i);
        final double y2 = getY(i);
        if (lineIntersector.computeIntersection(x, y, x1, y1, x2, y2)) {
            return true;
        } else {
            x1 = x2;
            y1 = y2;
        }
    }
    return false;
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector)

Example 9 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector in project com.revolsys.open by revolsys.

the class LineStringUtil method getCrossingIntersection.

/**
 * Get the coordinate where two lines cross, or null if they don't cross.
 *
 * @param line1 The first line.
 * @param line2 The second line
 * @return The coordinate or null if they don't cross
 */
public static Point getCrossingIntersection(final LineString line1, final LineString line2) {
    final RobustLineIntersector intersector = new RobustLineIntersector();
    final LineString coordinates1 = line1;
    final LineString coordinates2 = line2;
    final int numCoordinates1 = coordinates1.getVertexCount();
    final int numCoordinates2 = coordinates2.getVertexCount();
    final Point firstCoord1 = coordinates1.getPoint(0);
    final Point firstCoord2 = coordinates2.getPoint(0);
    final Point lastCoord1 = coordinates1.getPoint(numCoordinates1 - 1);
    final Point lastCoord2 = coordinates2.getPoint(numCoordinates2 - 2);
    Point previousCoord1 = firstCoord1;
    for (int i1 = 1; i1 < numCoordinates1; i1++) {
        final Point currentCoord1 = coordinates1.getPoint(i1);
        Point previousCoord2 = firstCoord2;
        for (int i2 = 1; i2 < numCoordinates2; i2++) {
            final Point currentCoord2 = coordinates2.getPoint(i2);
            intersector.computeIntersectionPoints(previousCoord1, currentCoord1, previousCoord2, currentCoord2);
            final int numIntersections = intersector.getIntersectionCount();
            if (intersector.hasIntersection()) {
                if (intersector.isProper()) {
                    final Point intersection = intersector.getIntersection(0);
                    return intersection;
                } else if (numIntersections == 1) {
                    final Point intersection = intersector.getIntersection(0);
                    if (i1 == 1 || i2 == 1 || i1 == numCoordinates1 - 1 || i2 == numCoordinates2 - 1) {
                        if (!((intersection.equals(2, firstCoord1) || intersection.equals(2, lastCoord1)) && (intersection.equals(2, firstCoord2) || intersection.equals(2, lastCoord2)))) {
                            return intersection;
                        }
                    } else {
                        return intersection;
                    }
                } else if (intersector.isInteriorIntersection()) {
                    for (int i = 0; i < numIntersections; i++) {
                        final Point intersection = intersector.getIntersection(i);
                        if (!Arrays.asList(currentCoord1, previousCoord1, currentCoord2, previousCoord2).contains(intersection)) {
                            return intersection;
                        }
                    }
                }
            }
            previousCoord2 = currentCoord2;
        }
        previousCoord1 = currentCoord1;
    }
    return null;
}
Also used : LineString(com.revolsys.geometry.model.LineString) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 10 with RobustLineIntersector

use of com.revolsys.geometry.algorithm.RobustLineIntersector in project com.revolsys.open by revolsys.

the class IsValidOp method checkValidLinearRing.

/**
 * Checks validity of a LinearRing.
 */
private boolean checkValidLinearRing(final LinearRing ring) {
    boolean valid = true;
    if (checkTooFewVertices(ring, 4)) {
        valid &= checkClosedRing(ring);
        if (isErrorReturn()) {
            return false;
        }
        final GeometryGraph graph = new GeometryGraph(0, ring);
        final LineIntersector li = new RobustLineIntersector();
        graph.computeSelfNodes(li, true);
        valid &= checkNoSelfIntersectingRings(graph);
        return valid;
    }
    return false;
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) GeometryGraph(com.revolsys.geometry.geomgraph.GeometryGraph)

Aggregations

RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)17 Point (com.revolsys.geometry.model.Point)10 LineIntersector (com.revolsys.geometry.algorithm.LineIntersector)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)5 IntersectionAdder (com.revolsys.geometry.noding.IntersectionAdder)3 MCIndexNoder (com.revolsys.geometry.noding.MCIndexNoder)3 Noder (com.revolsys.geometry.noding.Noder)2 ScaledNoder (com.revolsys.geometry.noding.ScaledNoder)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 NonRobustLineIntersector (com.revolsys.geometry.algorithm.NonRobustLineIntersector)1 GeometryGraph (com.revolsys.geometry.geomgraph.GeometryGraph)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 LineString (com.revolsys.geometry.model.LineString)1