use of com.revolsys.geometry.graph.Node in project com.revolsys.open by revolsys.
the class LineStringGraph method getLines.
public List<LineString> getLines() {
removeDuplicateEdges();
final EdgeAttributeValueComparator<LineSegment> comparator = new EdgeAttributeValueComparator<>("INDEX");
final List<LineString> lines = new ArrayList<>();
final List<Point> points = new ArrayList<>();
final Consumer<Edge<LineSegment>> action = new Consumer<Edge<LineSegment>>() {
private Node<LineSegment> previousNode = null;
@Override
public void accept(final Edge<LineSegment> edge) {
final LineSegment lineSegment = edge.getObject();
if (lineSegment.getLength() > 0) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
if (this.previousNode == null) {
points.add(lineSegment.getPoint(0));
points.add(lineSegment.getPoint(1));
} else if (fromNode == this.previousNode) {
if (edge.getLength() > 0) {
points.add(toNode);
}
} else {
if (points.size() > 1) {
final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
lines.add(line);
}
points.clear();
;
points.add(lineSegment.getPoint(0));
points.add(lineSegment.getPoint(1));
}
if (points.size() > 1) {
final int toDegree = toNode.getDegree();
if (toDegree != 2) {
final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
lines.add(line);
points.clear();
;
points.add(toNode);
}
}
this.previousNode = toNode;
}
}
};
forEachEdge(comparator, action);
if (points.size() > 1) {
final LineString line = this.geometryFactory.lineString(points);
lines.add(line);
}
return lines;
}
use of com.revolsys.geometry.graph.Node in project com.revolsys.open by revolsys.
the class LineStringRelate method getOverlap.
public Lineal getOverlap() {
final List<List<Point>> intersections = new ArrayList<>();
final LineString points1 = this.line1;
final List<Point> currentCoordinates = new ArrayList<>();
Node<LineSegment> previousNode = this.graph1.getNode(this.fromPoint1);
do {
final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
if (outEdges.isEmpty()) {
previousNode = null;
} else if (outEdges.size() > 1) {
System.err.println("Cannot handle overlaps\n" + getLine1() + "\n " + getLine2());
final GeometryFactory factory = this.line1.getGeometryFactory();
return factory.lineString();
} else {
final Edge<LineSegment> edge = outEdges.get(0);
final LineSegment line = edge.getObject();
final Node<LineSegment> nextNode = edge.getToNode();
if (this.graph2.hasEdgeBetween(previousNode, nextNode)) {
if (currentCoordinates.size() == 0) {
currentCoordinates.add(line.getPoint(0));
}
currentCoordinates.add(line.getPoint(1));
} else {
if (currentCoordinates.size() > 0) {
final List<Point> points = new ArrayList<>();
intersections.add(points);
currentCoordinates.clear();
}
}
previousNode = nextNode;
}
} while (previousNode != null && !previousNode.equals(2, this.fromPoint1));
if (currentCoordinates.size() > 0) {
final List<Point> points = new ArrayList<>();
intersections.add(points);
}
final GeometryFactory factory = this.line1.getGeometryFactory();
return factory.lineal(intersections);
}
use of com.revolsys.geometry.graph.Node in project com.revolsys.open by revolsys.
the class LineMatchGraph method add.
private void add(final LineString line, final int index) {
if (line.getLength() > 0) {
final LineString coords = line;
final Point coordinate0 = coords.getPoint(0);
final Node<LineSegmentMatch> node = getNode(coordinate0);
final Set<Node<LineSegmentMatch>> indexStartNodes = getStartNodes(index);
indexStartNodes.add(node);
Point previousCoordinate = coordinate0;
for (int i = 1; i < coords.getVertexCount(); i++) {
final Point coordinate = coords.getPoint(i);
final LineSegment segment = new LineSegmentDoubleGF(this.geometryFactory, previousCoordinate, coordinate);
if (segment.getLength() > 0) {
add(previousCoordinate, coordinate, segment, index);
}
previousCoordinate = coordinate;
}
}
}
use of com.revolsys.geometry.graph.Node in project com.revolsys.open by revolsys.
the class NodeLessThanDistanceOfGeometryVisitor method getNodes.
public static <T> List<Node<T>> getNodes(final Graph<T> graph, final Geometry geometry, final double maxDistance) {
if (geometry == null) {
return Collections.emptyList();
} else {
final CreateListVisitor<Node<T>> results = new CreateListVisitor<>();
BoundingBox env = geometry.getBoundingBox();
env = env.expand(maxDistance);
final IdObjectIndex<Node<T>> index = graph.getNodeIndex();
final NodeLessThanDistanceOfGeometryVisitor<T> visitor = new NodeLessThanDistanceOfGeometryVisitor<>(geometry, maxDistance, results);
index.forEach(env, visitor);
return results.getList();
}
}
use of com.revolsys.geometry.graph.Node in project com.revolsys.open by revolsys.
the class OnLineNodeVisitor method getNodes.
public static <T> List<Node<T>> getNodes(final Graph<T> graph, final LineString line, final double maxDistance) {
if (line == null) {
return Collections.emptyList();
} else {
final CreateListVisitor<Node<T>> results = new CreateListVisitor<>();
BoundingBox env = line.getBoundingBox();
env = env.expand(maxDistance);
final IdObjectIndex<Node<T>> index = graph.getNodeIndex();
final OnLineNodeVisitor<T> visitor = new OnLineNodeVisitor<>(line, results);
index.forEach(env, visitor);
return results.getList();
}
}
Aggregations