use of com.revolsys.geometry.graph.Edge 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.Edge in project com.revolsys.open by revolsys.
the class LineMatchGraph method getMatchLength.
public double getMatchLength(final Node<LineSegmentMatch> node, final boolean direction, final int index1, final int index2) {
List<Edge<LineSegmentMatch>> edges;
if (direction) {
edges = node.getOutEdges();
} else {
edges = node.getInEdges();
}
for (final Edge<LineSegmentMatch> edge : edges) {
final LineSegmentMatch lineSegmentMatch = edge.getObject();
if (lineSegmentMatch.hasMatches(index1, index2)) {
final LineSegment segment = lineSegmentMatch.getSegment(index2);
final double length = segment.getLength();
final Node<LineSegmentMatch> nextNode = edge.getOppositeNode(node);
return length + getMatchLength(nextNode, direction, index1, index2);
}
}
return 0;
}
use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.
the class LineMatchGraph method getNonMatchedLines.
public Lineal getNonMatchedLines(final int index1, final int index2) {
final List<LineString> lines = new ArrayList<>();
final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
for (Node<LineSegmentMatch> currentNode : getStartNodes(index1)) {
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(index1) && !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 this.geometryFactory.lineal(lines);
}
use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.
the class LineMatchGraph method getOverlappingMatches.
public Lineal getOverlappingMatches() {
final List<LineString> overlappingLines = new ArrayList<>();
final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
for (Node<LineSegmentMatch> currentNode : getStartNodes(0)) {
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(0) && !processedEdges.contains(edge)) {
if (lineSegmentMatch.getMatchCount(0) > 2) {
for (int i = 1; i < lineSegmentMatch.getSegmentCount() && lineSegmentMatch.getMatchCount(0) > 2; i++) {
if (lineSegmentMatch.hasSegment(i)) {
if (!hasMatch(currentNode, false, 0, i)) {
final Node<LineSegmentMatch> toNode = edge.getToNode();
if (!hasMatch(toNode, true, 0, i)) {
lineSegmentMatch.removeSegment(i);
} else {
final double matchLength = getMatchLength(currentNode, false, 0, i);
final double duplicateMatchLength = getDuplicateMatchLength(currentNode, true, 0, i);
if (matchLength + duplicateMatchLength <= 2) {
lineSegmentMatch.removeSegment(i);
}
}
}
}
}
if (lineSegmentMatch.getMatchCount(0) > 2) {
overlappingLines.add(lineSegmentMatch.getLine());
}
}
processedEdges.add(edge);
nextNode = edge.getToNode();
}
}
currentNode = nextNode;
}
}
final Lineal lines = this.geometryFactory.lineal(overlappingLines);
return lines;
}
use of com.revolsys.geometry.graph.Edge 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;
}
Aggregations