use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class CoordinatesListUtil method containsWithinTolerance.
/**
* <p>
* Check within a given tolerance that the LINESTRING defined by points2 is
* contained within the points1.
* </p>
* <p>
* The algorithm is as follows:
* <ol>
* <li>Find all coordinates from points2 that are within the tolerance from
* the line segments of points1.</li>
* <li>Find all coordinates from points1 that are within the tolerance from
* the line segments of points2.</li>
* <li>Split all the line sgements of points1 that were matched in step 1.</li>
* <li>Split all the line sgements of points2 that were matched in step 2.</li>
* <li>Line is contained if all line segments from point2 have matching lines
* in points1.</li>
* </ol>
*
* @param points1
* @param points2
* @param tolerance
* @return
*/
public static boolean containsWithinTolerance(final LineString points1, final LineString points2, final double tolerance) {
final LineStringGraph graph1 = new LineStringGraph(points1);
final LineStringGraph graph2 = new LineStringGraph(points2);
graph1.forEachNode((node) -> movePointsWithinTolerance(null, graph2, tolerance, node));
graph1.forEachNode((node) -> movePointsWithinTolerance(null, graph1, tolerance, node));
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = graph1.getPointsOnEdges(graph2, tolerance);
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge2 = graph2.getPointsOnEdges(graph1, tolerance);
graph1.splitEdges(pointsOnEdge1);
graph2.splitEdges(pointsOnEdge2);
for (final Edge<LineSegment> edge : graph2.getEdges()) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
if (!graph1.hasEdgeBetween(fromNode, toNode)) {
return false;
}
}
return true;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class CoordinatesListUtil method intersection.
public static List<LineString> intersection(final GeometryFactory geometryFactory, final LineString points1, final LineString points2, final double maxDistance) {
final LineStringGraph graph1 = new LineStringGraph(points1);
graph1.setPrecisionModel(geometryFactory);
final LineStringGraph graph2 = new LineStringGraph(points2);
graph2.setPrecisionModel(geometryFactory);
final Map<Point, Point> movedNodes = new HashMap<>();
graph1.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph2, maxDistance, node));
graph2.forEachNode((node) -> movePointsWithinTolerance(movedNodes, graph1, maxDistance, node));
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = graph1.getPointsOnEdges(graph2, maxDistance);
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge2 = graph2.getPointsOnEdges(graph1, maxDistance);
graph1.splitEdges(pointsOnEdge1);
graph2.splitEdges(pointsOnEdge2);
Point startPoint = points1.getPoint(0);
if (movedNodes.containsKey(startPoint)) {
startPoint = movedNodes.get(startPoint);
}
Point endPoint = points1.getPoint(points1.getVertexCount() - 1);
if (movedNodes.containsKey(endPoint)) {
endPoint = movedNodes.get(endPoint);
}
final List<LineString> intersections = new ArrayList<>();
final List<Point> currentCoordinates = new ArrayList<>();
Node<LineSegment> previousNode = graph1.getNode(startPoint);
do {
final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
if (outEdges.isEmpty()) {
previousNode = null;
} else if (outEdges.size() > 1) {
throw new IllegalArgumentException("Cannot handle overlaps\n" + points1 + "\n " + points2);
} else {
final Edge<LineSegment> edge = outEdges.get(0);
final LineSegment line = edge.getObject();
final Node<LineSegment> nextNode = edge.getToNode();
if (graph2.hasEdgeBetween(previousNode, nextNode)) {
if (currentCoordinates.size() == 0) {
currentCoordinates.add(line.getPoint(0));
}
currentCoordinates.add(line.getPoint(1));
} else {
if (currentCoordinates.size() > 0) {
final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
intersections.add(points);
currentCoordinates.clear();
}
}
previousNode = nextNode;
}
} while (previousNode != null && !endPoint.equals(2, startPoint));
if (currentCoordinates.size() > 0) {
final LineString points = new LineStringDouble(points1.getAxisCount(), currentCoordinates);
intersections.add(points);
}
return intersections;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class TaggedLineString method extractCoordinates.
private static Point[] extractCoordinates(final List<LineSegment> segs) {
final Point[] pts = new Point[segs.size() + 1];
LineSegment seg = null;
for (int i = 0; i < segs.size(); i++) {
seg = segs.get(i);
pts[i] = seg.getP0();
}
// add last point
pts[pts.length - 1] = seg.getP1();
return pts;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class TaggedLineStringSimplifier method flatten.
/**
* Flattens a section of the taggedLine between
* indexes <code>start</code> and <code>end</code>,
* replacing them with a taggedLine between the endpoints.
* The input and output indexes are updated
* to reflect this.
*
* @param start the start index of the flattened section
* @param end the end index of the flattened section
* @return the new segment created
*/
private LineSegment flatten(final int start, final int end) {
// make a new segment for the simplified geometry
final Point p0 = this.line.getVertex(start);
final Point p1 = this.line.getVertex(end);
final LineSegment newSeg = new LineSegmentDouble(p0, p1);
// update the indexes
remove(this.taggedLine, start, end);
this.outputIndex.add(newSeg);
return newSeg;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineSegmentTest method assertIntersection3d.
public void assertIntersection3d(final Point line1Start, final Point line1End, final Point line2Start, final Point line2End, final Geometry expectedIntersection) {
final LineSegment line1 = new LineSegmentDoubleGF(GEOMETRY_FACTORY_3D, line1Start, line1End);
final LineSegment line2 = new LineSegmentDoubleGF(GEOMETRY_FACTORY_3D, line2Start, line2End);
final Geometry intersection = line1.getIntersection(line2);
if (!TestUtil.equalsExact(3, intersection, expectedIntersection)) {
TestUtil.failNotEquals("Equals Exact", expectedIntersection, intersection);
}
}
Aggregations