use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class GeometryGraph method getBoundaryIntersection.
/**
* Get the intersection between the line and the boundary of this geometry.
*
* @param line
* @return
*/
public Geometry getBoundaryIntersection(final LineString line) {
final List<Point> pointIntersections = new ArrayList<>();
final List<LineString> lineIntersections = new ArrayList<>();
final GeometryFactory geometryFactory = getGeometryFactory();
final BoundingBox boundingBox = getBoundingBox(line);
if (boundingBox.intersects(this.boundingBox)) {
final LineString points = line;
final int vertexCount = points.getVertexCount();
final Point fromPoint = points.getPoint(0);
final Point toPoint = points.getPoint(vertexCount - 1);
Point previousPoint = fromPoint;
for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
final Point nextPoint = points.getPoint(vertexIndex);
final LineSegment line1 = new LineSegmentDoubleGF(getGeometryFactory(), previousPoint, nextPoint);
final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, this.maxDistance);
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry segmentIntersection = line1.getIntersection(line2);
if (segmentIntersection instanceof Point) {
final Point intersection = (Point) segmentIntersection;
if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final Node<LineSegment> node = findNode(intersection);
if (node == null) {
pointIntersections.add(geometryFactory.point(intersection));
} else {
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// Intersection not at the start/end of the other line,
// taking
// into account loops
pointIntersections.add(geometryFactory.point(intersection));
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
pointIntersections.add(geometryFactory.point(intersection));
}
}
} else {
// Intersection not at the start/end of the line
pointIntersections.add(geometryFactory.point(intersection));
}
} else if (segmentIntersection instanceof LineSegment) {
lineIntersections.add((LineSegment) segmentIntersection);
}
for (final Point point : line1.vertices()) {
if (line2.distancePoint(point) < this.maxDistance) {
if (point.equals(fromPoint) || point.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final double maxDistance1 = this.maxDistance;
for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// Intersection not at the start/end of the other line,
// taking
// into account loops
pointIntersections.add(geometryFactory.point(point));
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
pointIntersections.add(geometryFactory.point(point));
}
}
} else {
// Intersection not at the start/end of the line
pointIntersections.add(geometryFactory.point(point));
}
}
}
}
previousPoint = nextPoint;
}
}
if (lineIntersections.isEmpty()) {
return geometryFactory.punctual(pointIntersections);
} else {
final List<LineString> mergedLines = LineMerger.merge(lineIntersections);
final Lineal multiLine = geometryFactory.lineal(mergedLines);
if (pointIntersections.isEmpty()) {
return multiLine;
} else {
final Punctual multiPoint = geometryFactory.punctual(pointIntersections);
return multiPoint.union(multiLine);
}
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class EdgeLessThanDistance method test.
@Override
public boolean test(final Edge<LineSegment> edge) {
final LineSegment lineSegment = edge.getObject();
final double distance = lineSegment.distance(this.lineSegment);
if (distance <= this.maxDistance) {
return true;
} else {
return false;
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method getPointsOnEdges.
public Map<Edge<LineSegment>, List<Node<LineSegment>>> getPointsOnEdges(final Graph<LineSegment> graph1, final double tolerance) {
final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = new HashMap<>();
for (final Edge<LineSegment> edge : getEdges()) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
final LineSegment lineSegment = edge.getObject();
final PointOnLineSegment coordinatesFilter = new PointOnLineSegment(lineSegment, tolerance);
final NodeCoordinatesFilter<LineSegment> nodeFilter = new NodeCoordinatesFilter<>(coordinatesFilter);
final NodeDistanceComparator<LineSegment> comparator = new NodeDistanceComparator<>(fromNode);
final List<Node<LineSegment>> nodes = graph1.getNodes(nodeFilter, comparator);
for (final Iterator<Node<LineSegment>> iterator = nodes.iterator(); iterator.hasNext(); ) {
final Node<LineSegment> node = iterator.next();
if (node.equals(2, fromNode)) {
iterator.remove();
} else if (node.equals(2, toNode)) {
iterator.remove();
}
}
if (!nodes.isEmpty()) {
pointsOnEdge1.put(edge, nodes);
}
}
return pointsOnEdge1;
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method splitCrossingEdges.
public void splitCrossingEdges() {
final Comparator<Edge<LineSegment>> comparator = new EdgeAttributeValueComparator<>(INDEX);
forEachEdge(comparator, (edge) -> {
final LineSegment line1 = edge.getObject();
final Predicate<LineSegment> lineFilter = new CrossingLineSegmentFilter(line1);
final Predicate<Edge<LineSegment>> filter = new EdgeObjectFilter<>(lineFilter);
final List<Edge<LineSegment>> edges = getEdges(line1, filter);
if (!edges.isEmpty()) {
final List<Point> points = new ArrayList<>();
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry intersections = line1.getIntersection(line2);
if (intersections instanceof Point) {
final Point intersection = (Point) intersections;
points.add(intersection);
edge2.split(intersection);
}
}
if (!points.isEmpty()) {
edge.splitEdge(points);
}
}
});
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method hasTouchingEdges.
public boolean hasTouchingEdges(final Node<LineSegment> node) {
final GeometryFactory precisionModel = getPrecisionModel();
final List<Edge<LineSegment>> edges = getEdges(node, precisionModel.getScaleXY());
for (final Edge<LineSegment> edge : edges) {
final Point lineStart = edge.getFromNode();
final Point lineEnd = edge.getToNode();
if (LineSegmentUtil.isPointOnLineMiddle(precisionModel, lineStart, lineEnd, node)) {
return true;
}
}
return false;
}
Aggregations