use of com.revolsys.geometry.filter.EqualFilter in project com.revolsys.open by revolsys.
the class LinearIntersectionNotEqualLineEdgeCleanupVisitor method accept.
@Override
public void accept(final Edge<Record> edge) {
final String typePath = edge.getTypeName();
final Graph<Record> graph = edge.getGraph();
final LineString line = edge.getLineString();
Predicate<Edge<Record>> attributeAndGeometryFilter = new EdgeTypeNameFilter<>(typePath);
final Predicate<Edge<Record>> filter = getPredicate();
if (filter != null) {
attributeAndGeometryFilter = attributeAndGeometryFilter.and(filter);
}
final Predicate<Record> notEqualLineFilter = new RecordGeometryFilter<>(new EqualFilter<>(line)).negate();
final RecordGeometryFilter<LineString> linearIntersectionFilter = new RecordGeometryFilter<>(new LinearIntersectionFilter(line));
attributeAndGeometryFilter = attributeAndGeometryFilter.and(new EdgeObjectFilter<>(notEqualLineFilter.and(linearIntersectionFilter)));
final List<Edge<Record>> intersectingEdges = graph.getEdges(line, attributeAndGeometryFilter);
if (!intersectingEdges.isEmpty()) {
if (intersectingEdges.size() == 1 && line.getLength() > 10) {
if (line.getVertexCount() > 2) {
final Edge<Record> edge2 = intersectingEdges.get(0);
final LineString line2 = edge2.getLineString();
if (middleCoordinatesEqual(line, line2)) {
final boolean firstEqual = line.equalsVertex(2, 0, line2, 0);
if (!firstEqual) {
final Node<Record> fromNode1 = edge.getFromNode();
final Node<Record> fromNode2 = edge2.getFromNode();
if (fromNode1.distancePoint(fromNode2) < 2) {
graph.moveNodesToMidpoint(typePath, fromNode1, fromNode2);
return;
}
}
final boolean lastEqual = line.equalsVertex(2, line.getVertexCount() - 1, line2, line.getVertexCount() - 1);
if (!lastEqual) {
final Node<Record> toNode1 = edge.getToNode();
final Node<Record> toNode2 = edge2.getToNode();
if (toNode1.distancePoint(toNode2) < 2) {
graph.moveNodesToMidpoint(typePath, toNode1, toNode2);
return;
}
}
}
}
}
Logs.error(this, "Has intersecting edges " + line);
}
}
Aggregations