use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class InteriorPointArea method widestGeometry.
// @return if geometry is a collection, the widest sub-geometry; otherwise,
// the geometry itself
private Geometry widestGeometry(final Geometry geometry) {
if (geometry.isGeometryCollection()) {
if (geometry.isEmpty()) {
return geometry;
} else {
double widestWidth = 0;
Geometry widestGeometry = null;
// scan remaining geom components to see if any are wider
for (final Geometry part : geometry.geometries()) {
final double width = part.getBoundingBox().getWidth();
if (widestGeometry == null || width > widestWidth) {
widestGeometry = part;
widestWidth = width;
}
}
return widestGeometry;
}
} else {
return geometry;
}
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class Graph method getNodes.
public List<Node<T>> getNodes(final Predicate<Node<T>> filter, final Geometry geometry, final double maxDistance) {
final BoundingBox boundingBox = geometry.getBoundingBox().expand(maxDistance);
final Predicate<Node<T>> distanceFilter = (node) -> {
return filter.test(node) && node.distance(geometry) <= maxDistance;
};
return getNodes(boundingBox, distanceFilter, null);
}
use of com.revolsys.geometry.model.Geometry 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.Geometry in project com.revolsys.open by revolsys.
the class LineStringGraph method isSimple.
public boolean isSimple() {
for (final Node<LineSegment> node : getNodes()) {
if (node.getDegree() > 2) {
return false;
}
}
for (final Edge<LineSegment> edge : getEdges()) {
final LineSegment line = edge.getObject();
final EdgeObjectFilter<LineSegment> filter = new EdgeObjectFilter<>(new LineSegmentIntersectingFilter(line));
final List<Edge<LineSegment>> edges = getEdges(line, filter);
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry intersections = line.getIntersection(line2);
if (intersections instanceof LineSegment) {
return false;
} else if (intersections instanceof Point) {
if (edge.getCommonNodes(edge2).isEmpty()) {
return false;
}
}
}
}
return true;
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class LineStringGraph method getSelfIntersections.
public Geometry getSelfIntersections() {
final Set<Point> intersectionPoints = new HashSet<>();
for (int i = 0; i < this.points.getVertexCount(); i++) {
final Point point = this.points.getPoint(i);
final Node<LineSegment> node = getNode(point);
if (node.getDegree() > 2 || hasTouchingEdges(node)) {
intersectionPoints.add(point);
}
}
forEachEdge((edge1) -> {
final LineSegment lineSegment1 = edge1.getObject();
forEachEdge(edge1, (edge2) -> {
if (edge1 != edge2) {
final LineSegment lineSegment2 = edge2.getObject();
final Geometry intersections = ((LineSegment) lineSegment1.convertGeometry(getGeometryFactory())).getIntersection(lineSegment2);
for (final Point intersection : intersections.vertices()) {
if (!lineSegment1.isEndPoint(intersection) && !lineSegment2.isEndPoint(intersection)) {
intersectionPoints.add(intersection);
}
}
}
});
});
return this.geometryFactory.punctual(intersectionPoints);
}
Aggregations