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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations