use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class Graph method addEdge.
/**
* Actually add the edge.
*
* @param object
* @param line
* @param from
* @param to
* @return
*/
protected Edge<T> addEdge(final T object, final LineString line, final double fromX, final double fromY, final double toX, final double toY) {
if (this.inMemory && getEdgeCount() >= this.maxEdgesInMemory) {
this.edgePropertiesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgePropertiesById);
// TODO edgIds
// TODO edgeIndex
this.edgeLinesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgeLinesById);
this.edgeObjectsById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgeObjectsById);
this.edgesById = BPlusTreeMap.newIntSeralizableTempDisk(this.edgesById);
// TODO nodeIndex
this.nodePropertiesById = BPlusTreeMap.newIntSeralizableTempDisk(this.nodePropertiesById);
this.nodesById = BPlusTreeMap.newIntSeralizableTempDisk(this.nodesById);
this.nodesIdsByPoint = BPlusTreeMap.newTempDisk(this.nodesIdsByPoint, new SerializablePageValueManager<Point>(), PageValueManager.INT);
this.inMemory = false;
}
final Node<T> fromNode = getNode(fromX, fromY);
final Node<T> toNode = getNode(toX, toY);
final int edgeId = ++this.nextEdgeId;
final Edge<T> edge = new Edge<>(edgeId, this, fromNode, toNode);
if (this.edgeLinesById != null) {
this.edgeLinesById.put(edgeId, line);
}
this.edgeObjectsById.put(edgeId, object);
this.edgesById.put(edgeId, edge);
this.edgeIds.put(edge, edgeId);
if (this.edgeIndex != null) {
this.edgeIndex.add(edge);
}
this.edgeListeners.edgeEvent(edge, null, EdgeEvent.EDGE_ADDED, null);
return edge;
}
use of com.revolsys.geometry.model.Point 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.Point 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.Point in project com.revolsys.open by revolsys.
the class LineStringGraph method splitEdge.
@Override
public <V extends Point> List<Edge<LineSegment>> splitEdge(final Edge<LineSegment> edge, final Collection<V> nodes) {
final List<Edge<LineSegment>> newEdges = new ArrayList<>();
if (!edge.isRemoved()) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
final CoordinatesDistanceComparator comparator = new CoordinatesDistanceComparator(fromNode.getX(), toNode.getY());
final Set<Point> newPoints = new TreeSet<>(comparator);
for (final Point point : nodes) {
newPoints.add(point);
}
newPoints.add(toNode);
final List<Integer> index = edge.getProperty(INDEX);
int i = 0;
Point previousPoint = fromNode;
for (final Point point : newPoints) {
final LineSegment lineSegment = new LineSegmentDoubleGF(previousPoint, point);
final Edge<LineSegment> newEdge = addEdge(lineSegment, previousPoint, point);
final List<Integer> newIndecies = new ArrayList<>(index);
newIndecies.add(i++);
newEdge.setProperty(INDEX, newIndecies);
newEdges.add(newEdge);
previousPoint = point;
}
remove(edge);
}
return newEdges;
}
use of com.revolsys.geometry.model.Point 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