use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class LineMatchGraph method getMatchedLinesList.
public List<LineString> getMatchedLinesList(final int index1, final int index2) {
final List<LineString> lines = new ArrayList<>();
final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
for (Node<LineSegmentMatch> currentNode : getStartNodes(index2)) {
final List<Point> coordinates = new ArrayList<>();
while (currentNode != null) {
Node<LineSegmentMatch> nextNode = null;
final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
for (final Edge<LineSegmentMatch> edge : edges) {
final LineSegmentMatch lineSegmentMatch = edge.getObject();
if (lineSegmentMatch.hasSegment(index2) && !processedEdges.contains(edge)) {
if (lineSegmentMatch.hasMatches(index1, index2)) {
if (coordinates.isEmpty()) {
final Point startCoordinate = currentNode;
coordinates.add(startCoordinate);
}
final Node<LineSegmentMatch> toNode = edge.getToNode();
final Point toCoordinate = toNode;
coordinates.add(toCoordinate);
} else {
newLine(lines, coordinates);
coordinates.clear();
}
processedEdges.add(edge);
nextNode = edge.getToNode();
}
}
currentNode = nextNode;
}
newLine(lines, coordinates);
}
return lines;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class GraphProcessor method process.
@Override
protected void process(final Channel<Record> in, final Channel<Record> out, final Record object) {
final Geometry geometry = object.getGeometry();
if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
this.graph.addEdge(object, line);
} else {
if (out != null) {
out.write(object);
}
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class BoundingBoxIntersectsEdgeVisitor method getEdges.
public static <T> List<Edge<T>> getEdges(final Graph<T> graph, final Edge<T> edge, final double maxDistance) {
final CreateListVisitor<Edge<T>> results = new CreateListVisitor<>();
final LineString line = edge.getLineString();
BoundingBox boundingBox = line.getBoundingBox();
boundingBox = boundingBox.expand(maxDistance);
final BoundingBoxIntersectsEdgeVisitor<T> visitor = new BoundingBoxIntersectsEdgeVisitor<>(boundingBox, results);
final IdObjectIndex<Edge<T>> index = graph.getEdgeIndex();
index.forEach(boundingBox, visitor);
final List<Edge<T>> list = results.getList();
list.remove(edge);
return list;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class EdgeIntersectsLinearlyEdgeVisitor method accept.
@Override
public void accept(final Edge<T> edge2) {
if (edge2 != this.edge) {
final LineString line1 = this.edge.getLineString();
final LineString line2 = edge2.getLineString();
final BoundingBox envelope1 = line1.getBoundingBox();
final BoundingBox envelope2 = line2.getBoundingBox();
if (envelope1.intersects(envelope2)) {
final IntersectionMatrix relate = line1.relate(line2);
if (relate.get(0, 0) == Dimension.L) {
this.matchVisitor.accept(edge2);
}
}
}
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class EdgeIntersectsLinearlyEdgeVisitor method getEdges.
public static <T> List<Edge<T>> getEdges(final Graph<T> graph, final Edge<T> edge) {
final CreateListVisitor<Edge<T>> results = new CreateListVisitor<>();
final LineString line = edge.getLineString();
final BoundingBox env = line.getBoundingBox();
final IdObjectIndex<Edge<T>> index = graph.getEdgeIndex();
index.forEach(env, new EdgeIntersectsLinearlyEdgeVisitor<>(edge, results));
final List<Edge<T>> edges = results.getList();
Collections.sort(edges);
return edges;
}
Aggregations