use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class PdfViewport method drawGeometry.
@Override
public void drawGeometry(final Geometry geometry, final GeometryStyle style) {
try {
this.contentStream.saveGraphicsState();
setGeometryStyle(style);
this.contentStream.setNonStrokingColor(style.getPolygonFill());
this.contentStream.setStrokingColor(style.getLineColor());
for (Geometry part : geometry.geometries()) {
part = part.convertGeometry(getGeometryFactory());
if (part instanceof LineString) {
final LineString line = (LineString) part;
drawLine(line);
this.contentStream.stroke();
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
int i = 0;
for (final LinearRing ring : polygon.rings()) {
if (i == 0) {
if (ring.isClockwise()) {
drawLineReverse(ring);
} else {
drawLine(ring);
}
} else {
if (ring.isCounterClockwise()) {
drawLineReverse(ring);
} else {
drawLine(ring);
}
}
this.contentStream.closeSubPath();
i++;
}
this.contentStream.fill(PathIterator.WIND_NON_ZERO);
for (final LinearRing ring : polygon.rings()) {
drawLine(ring);
this.contentStream.stroke();
}
}
}
} catch (final IOException e) {
} finally {
try {
this.contentStream.restoreGraphicsState();
} catch (final IOException e) {
}
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class PointLocator method locate.
public Location locate(final Geometry geometry, final double x, final double y) {
if (geometry.isEmpty()) {
return Location.EXTERIOR;
} else if (geometry instanceof LineString) {
return geometry.locate(x, y);
} else if (geometry instanceof Polygon) {
return geometry.locate(x, y);
}
this.isIn = false;
final int boundaryCount = computeLocation(geometry, x, y);
if (boundaryCount % 2 == 1) {
return Location.BOUNDARY;
} else if (boundaryCount > 0 || this.isIn) {
return Location.INTERIOR;
} else {
return Location.EXTERIOR;
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class LineSegment method getCrossing.
default Point getCrossing(final Point point1, final Point point2, final BoundingBox boundingBox) {
final GeometryFactory geometryFactory = getGeometryFactory();
Point intersection = null;
final Polygon polygon = boundingBox.toPolygon(1);
final LineString ring = polygon.getShell();
for (int i = 0; i < 4; i++) {
final Point ringC1 = ring.getPoint(i);
final Point ringC2 = ring.getPoint(i);
final LineString currentIntersections = LineSegmentUtil.getIntersection(geometryFactory, point1, point2, ringC1, ringC2);
if (currentIntersections.getVertexCount() == 1) {
final Point currentIntersection = currentIntersections.getPoint(0);
if (intersection == null) {
intersection = currentIntersection;
} else if (point1.distancePoint(currentIntersection) < point1.distancePoint(intersection)) {
intersection = currentIntersection;
}
}
}
return intersection;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class AbstractPreparedPolygonContains method isSingleShell.
/**
* Tests whether a geometry consists of a single originalGeometry with no holes.
*
* @return true if the geometry is a single originalGeometry with no holes
*/
private boolean isSingleShell(final Polygonal polygonal) {
// handles single-element MultiPolygons, as well as Polygons
if (polygonal.getPolygonCount() != 1) {
return false;
}
final Polygon poly = polygonal.getPolygon(0);
final int numHoles = poly.getHoleCount();
if (numHoles == 0) {
return true;
}
return false;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MultiPolygonSegment method hasNext.
@Override
public boolean hasNext() {
final Polygonal polygonal = this.polygonal;
if (polygonal.isEmpty()) {
return false;
} else {
int partIndex = this.partIndex;
int ringIndex = this.ringIndex;
int segmentIndex = this.segmentIndex + 1;
while (partIndex < polygonal.getGeometryCount()) {
final Polygon polygon = getPolygon();
while (ringIndex < polygon.getRingCount()) {
final LinearRing ring = polygon.getRing(ringIndex);
if (segmentIndex < ring.getSegmentCount()) {
return true;
} else {
ringIndex++;
segmentIndex = 0;
}
}
partIndex++;
ringIndex = 0;
segmentIndex = 0;
}
return false;
}
}
Aggregations