use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.
the class PolygonBuilder method buildMinimalEdgeRings.
private List<MaximalEdgeRing> buildMinimalEdgeRings(final List<MaximalEdgeRing> maxEdgeRings, final List<EdgeRing> shellList, final List<EdgeRing> freeHoleList) {
final List<MaximalEdgeRing> edgeRings = new ArrayList<>();
for (final MaximalEdgeRing er : maxEdgeRings) {
if (er.getMaxNodeDegree() > 2) {
er.linkDirectedEdgesForMinimalEdgeRings();
final List<MinimalEdgeRing> minEdgeRings = er.buildMinimalRings();
// at this point we can go ahead and attempt to place holes, if this
// EdgeRing is a polygon
final EdgeRing shell = findShell(minEdgeRings);
if (shell != null) {
placePolygonHoles(shell, minEdgeRings);
shellList.add(shell);
} else {
freeHoleList.addAll(minEdgeRings);
}
} else {
edgeRings.add(er);
}
}
return edgeRings;
}
use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.
the class PolygonBuilder method getPolygons.
public List<Polygon> getPolygons() {
final List<Polygon> polygons = new ArrayList<>();
for (final EdgeRing edgeRing : this.shellList) {
final Polygon polygon = edgeRing.toPolygon(this.geometryFactory);
polygons.add(polygon);
}
return polygons;
}
use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.
the class PolygonBuilder method findEdgeRingContaining.
/**
* Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
* The innermost enclosing ring is the <i>smallest</i> enclosing ring.
* The algorithm used depends on the fact that:
* <br>
* ring A contains ring B iff envelope(ring A) contains envelope(ring B)
* <br>
* This routine is only safe to use if the chosen point of the hole
* is known to be properly contained in a shell
* (which is guaranteed to be the case if the hole does not touch its shell)
*
* @return containing EdgeRing, if there is one
* or null if no containing EdgeRing is found
*/
private EdgeRing findEdgeRingContaining(final EdgeRing testEr, final List<EdgeRing> shellList) {
final LinearRing testRing = testEr.getLinearRing();
final BoundingBox testEnv = testRing.getBoundingBox();
final double testX = testRing.getX(0);
final double testY = testRing.getY(0);
EdgeRing minShell = null;
BoundingBox minEnv = null;
for (final EdgeRing tryShell : shellList) {
final LinearRing tryRing = tryShell.getLinearRing();
final BoundingBox tryEnv = tryRing.getBoundingBox();
if (minShell != null) {
minEnv = minShell.getLinearRing().getBoundingBox();
}
boolean isContained = false;
if (tryEnv.covers(testEnv) && tryRing.isPointInRing(testX, testY)) {
isContained = true;
}
// ring
if (isContained) {
if (minShell == null || minEnv.covers(tryEnv)) {
minShell = tryShell;
}
}
}
return minShell;
}
use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.
the class ConnectedInteriorTester method hasUnvisitedShellEdge.
/**
* Check if any shell ring has an unvisited edge.
* A shell ring is a ring which is not a hole and which has the interior
* of the parent area on the RHS.
* (Note that there may be non-hole rings with the interior on the LHS,
* since the interior of holes will also be polygonized into CW rings
* by the linkAllDirectedEdges() step)
*
* @return true if there is an unvisited edge in a non-hole ring
*/
private boolean hasUnvisitedShellEdge(final List edgeRings) {
for (int i = 0; i < edgeRings.size(); i++) {
final EdgeRing er = (EdgeRing) edgeRings.get(i);
// don't check hole rings
if (er.isHole()) {
continue;
}
final List edges = er.getEdges();
DirectedEdge de = (DirectedEdge) edges.get(0);
// (MD - this check may now be irrelevant)
if (de.getLabel().getLocation(0, Position.RIGHT) != Location.INTERIOR) {
continue;
}
/**
* the edgeRing is CW ring which surrounds the INT of the area, so check all
* edges have been visited. If any are unvisited, this is a disconnected part of the interior
*/
for (int j = 0; j < edges.size(); j++) {
de = (DirectedEdge) edges.get(j);
// Debug.print("visted? "); Debug.println(de);
if (!de.isVisited()) {
// Debug.print("not visited "); Debug.println(de);
this.disconnectedRingcoord = de.getCoordinate();
return true;
}
}
}
return false;
}
use of com.revolsys.geometry.geomgraph.EdgeRing in project com.revolsys.open by revolsys.
the class PolygonBuilder method findShell.
/**
* This method takes a list of MinimalEdgeRings derived from a MaximalEdgeRing,
* and tests whether they form a Polygon. This is the case if there is a single shell
* in the list. In this case the shell is returned.
* The other possibility is that they are a series of connected holes, in which case
* no shell is returned.
*
* @return the shell EdgeRing, if there is one
* or null, if all the rings are holes
*/
private EdgeRing findShell(final List<MinimalEdgeRing> minEdgeRings) {
int shellCount = 0;
EdgeRing shell = null;
for (final MinimalEdgeRing er : minEdgeRings) {
if (!er.isHole()) {
shell = er;
shellCount++;
}
}
Assert.isTrue(shellCount <= 1, "found two shells in MinimalEdgeRing list");
return shell;
}
Aggregations