use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class EdgeRing method containsPoint.
/**
* This method will cause the ring to be computed.
* It will also check any holes, if they have been assigned.
*/
public boolean containsPoint(final Point p) {
final LinearRing shell = getLinearRing();
final BoundingBox env = shell.getBoundingBox();
if (!env.covers(p)) {
return false;
}
if (!shell.isPointInRing(p)) {
return false;
}
for (final EdgeRing hole : this.holes) {
if (hole.containsPoint(p)) {
return false;
}
}
return true;
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class GeometryGraph method computeSelfNodes.
/**
* Compute self-nodes, taking advantage of the Geometry type to
* minimize the number of intersection tests. (E.g. rings are
* not tested for self-intersection, since they are assumed to be valid).
* @param li the LineIntersector to use
* @param computeRingSelfNodes if <false>, intersection checks are optimized to not test rings for self-intersection
* @return the SegmentIntersector used, containing information about the intersections found
*/
public SegmentIntersector computeSelfNodes(final LineIntersector li, final boolean computeRingSelfNodes) {
final SegmentIntersector si = new SegmentIntersector(li, true, false);
final EdgeSetIntersector esi = newEdgeSetIntersector();
// optimized test for Polygons and Rings
if (!computeRingSelfNodes && (this.geometry instanceof LinearRing || this.geometry instanceof Polygonal)) {
esi.computeIntersections(this.edges, si, false);
} else {
esi.computeIntersections(this.edges, si, true);
}
// System.out.println("SegmentIntersector # tests = " + si.numTests);
addSelfIntersectionNodes(this.argIndex);
return si;
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class Densifier method densify.
private static Polygon densify(final Polygon polygon, final double distanceTolerance) {
// Attempt to fix invalid geometries
final GeometryFactory geometryFactory = polygon.getGeometryFactory();
final List<LinearRing> rings = new ArrayList<>();
for (final LinearRing ring : polygon.rings()) {
final LinearRing newRing = densify(ring, distanceTolerance);
rings.add(newRing);
}
final Polygon newPolygon = geometryFactory.polygon(rings);
return (Polygon) newPolygon.buffer(0);
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class KmlGeometryReader method parsePolygon.
private Polygon parsePolygon() throws XMLStreamException {
this.in.requireLocalName(POLYGON);
final List<LinearRing> rings = new ArrayList<>();
int axisCount = 2;
final int depth = this.in.getDepth();
while (this.in.skipToStartElements(depth, OUTER_BOUNDARY_IS, INNER_BOUNDARY_IS)) {
final LinearRing ring = parseRing();
if (ring != null) {
axisCount = Math.max(axisCount, ring.getAxisCount());
rings.add(ring);
}
}
final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(axisCount);
final Polygon polygon = geometryFactory.polygon(rings);
return polygon;
}
use of com.revolsys.geometry.model.LinearRing in project com.revolsys.open by revolsys.
the class MeasureOverlay method deleteVertex.
private Geometry deleteVertex() {
final Geometry geometry = getMeasureGeometry();
for (final CloseLocation location : getMouseOverLocations()) {
final int[] vertexId = location.getVertexId();
if (vertexId != null) {
if (geometry instanceof Point) {
return null;
} else if (geometry instanceof LineString) {
final LineString line = (LineString) geometry;
if (line.getVertexCount() == 2) {
if (vertexId.length == 1) {
if (vertexId[0] == 0) {
return line.getPoint(1);
} else {
return line.getPoint(0);
}
}
}
} else if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
final LinearRing ring = polygon.getRing(0);
if (ring.getVertexCount() == 4) {
if (vertexId.length == 2) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
final Vertex point0 = ring.getVertex(0);
final Vertex point1 = ring.getVertex(1);
final Vertex point2 = ring.getVertex(2);
switch(vertexId[1]) {
case 0:
return geometryFactory.lineString(point1, point2);
case 1:
return geometryFactory.lineString(point2, point0);
default:
return geometryFactory.lineString(point0, point1);
}
}
}
}
try {
final GeometryEditor geometryEditor = geometry.newGeometryEditor();
geometryEditor.deleteVertex(vertexId);
if (geometryEditor.isModified()) {
return geometryEditor.newGeometry();
}
} catch (final Exception e) {
Toolkit.getDefaultToolkit().beep();
return geometry;
}
}
}
return geometry;
}
Aggregations