use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class Graph method mergeEdges.
/**
* Merge the two edges into a single edge, removing the old edges and node if
* required from the graph and adding a new edge to the graph.
*
* @param reversedEdges The list of edges that need to be reversed.
* @param node The node to remove.
* @param edge1 The first edge to merge.
* @param edge2 The second edge to merge.
* @return The new edge.
*/
public Edge<T> mergeEdges(final Edge<T> edge1, final Edge<T> edge2) {
final LineString line1 = edge1.getLineString();
final LineString line2 = edge2.getLineString();
final LineString newLine = line1.merge(line2);
final Edge<T> newEdge = replaceEdge(edge1, newLine);
remove(edge2);
return newEdge;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class RecordGraph method hasEdge.
public boolean hasEdge(final Record record) {
final LineString line = record.getGeometry();
final Point fromPoint = line.getPoint(0);
final Point toPoint = line.getToPoint();
final Node<Record> fromNode = findNode(fromPoint);
final Node<Record> toNode = findNode(toPoint);
if (fromNode != null && toNode != null) {
final Collection<Edge<Record>> edges = Node.getEdgesBetween(fromNode, toNode);
for (final Edge<Record> edge : edges) {
final LineString updateLine = edge.getLineString();
if (updateLine.equals(line)) {
return true;
}
}
}
return false;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class RecordGraph method splitEdges.
public List<Edge<Record>> splitEdges(final Point point, final double distance) {
final List<Edge<Record>> edges = new ArrayList<>();
for (final Edge<Record> edge : getEdges(point, distance)) {
final LineString line = edge.getLineString();
final List<Edge<Record>> splitEdges = edge.splitEdge(point);
DirectionalFields.edgeSplitFieldValues(line, point, splitEdges);
edges.addAll(splitEdges);
}
return edges;
}
use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.
the class GeometryGraph method addGeometry.
public void addGeometry(Geometry geometry) {
geometry = getGeometryFactory().geometry(geometry);
final Map<String, Object> properties = new LinkedHashMap<>();
final int geometryIndex = this.geometries.size();
properties.put("geometryIndex", geometryIndex);
this.geometries.add(geometry);
for (int partIndex = 0; partIndex < geometry.getGeometryCount(); partIndex++) {
properties.put("partIndex", partIndex);
final Geometry part = geometry.getGeometry(partIndex);
if (part instanceof Point) {
final Point point = (Point) part;
this.points.add(point);
} else if (part instanceof LineString) {
final LineString line = (LineString) part;
final LineString points = line;
properties.put("type", "LineString");
addEdges(points, properties);
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
int ringIndex = 0;
for (final LinearRing ring : polygon.rings()) {
properties.put("ringIndex", ringIndex++);
if (ringIndex == 0) {
properties.put("type", "PolygonShell");
} else {
properties.put("type", "PolygonHole");
}
addEdges(ring, properties);
}
properties.remove("ringIndex");
}
}
this.boundingBox = this.boundingBox.expandToInclude(geometry);
}
use of com.revolsys.geometry.model.LineString 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;
}
Aggregations