use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class BoundingBoxDoubleXY method toRectangle.
@Override
public RectangleXY toRectangle() {
final double width = getWidth();
final double height = getHeight();
final GeometryFactory geometryFactory = getGeometryFactory();
return geometryFactory.newRectangle(this.minX, this.minY, width, height);
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class PolygonEditor method newGeometry.
@Override
public Polygon newGeometry() {
final int ringCount = this.editors.size();
final LinearRing[] rings = new LinearRing[ringCount];
int ringIndex = 0;
for (final LinearRingEditor editor : this.editors) {
rings[ringIndex++] = editor.newGeometry();
}
final GeometryFactory geometryFactory = getGeometryFactory();
if (this.polygon == null) {
return geometryFactory.polygon(rings);
} else {
return this.polygon.newPolygon(geometryFactory, rings);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class PolygonEditor method getCurrentGeometry.
@Override
public Geometry getCurrentGeometry() {
final GeometryFactory geometryFactory = getGeometryFactory();
if (isEmpty()) {
return geometryFactory.polygon();
}
final List<LinearRing> rings = new ArrayList<>();
final List<Geometry> geometries = new ArrayList<>();
boolean shell = true;
for (final LinearRingEditor editor : this.editors) {
final Geometry ringGeometry = editor.getCurrentGeometry();
if (ringGeometry instanceof LinearRing) {
final LinearRing ring = (LinearRing) ringGeometry;
if (shell || !rings.isEmpty()) {
rings.add(ring);
} else {
geometries.add(ringGeometry);
}
} else {
geometries.add(ringGeometry);
}
shell = false;
}
if (!rings.isEmpty()) {
final Polygon polygon = geometryFactory.polygon(rings);
if (geometries.isEmpty()) {
return polygon;
} else {
geometries.add(polygon);
}
}
return geometryFactory.geometry(geometries);
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class Buffer method buffer.
private static Geometry buffer(final Noder noder, final GeometryFactory precisionModel, final Geometry geometry, final double distance, final BufferParameters parameters) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
final OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(geometry, distance, precisionModel, parameters);
final List<NodedSegmentString> curves = curveSetBuilder.getCurves();
if (curves.size() == 0) {
return geometryFactory.polygon();
} else {
final EdgeList edgeList = new EdgeList();
computeNodedEdges(noder, edgeList, curves);
final PlanarGraph graph = new PlanarGraph(new OverlayNodeFactory());
final List<Edge> edges = edgeList.getEdges();
graph.addEdges(edges);
final List<BufferSubgraph> subgraphList = newSubgraphs(graph);
final PolygonBuilder polyBuilder = new PolygonBuilder(geometryFactory);
buildSubgraphs(subgraphList, polyBuilder);
final List<Polygon> polygons = polyBuilder.getPolygons();
if (polygons.size() == 0) {
return geometryFactory.polygon();
} else {
final Geometry resultGeom = geometryFactory.buildGeometry(polygons);
return resultGeom;
}
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class Buffer method buffer.
/**
* Comutes the buffer for a geometry for a given buffer distance
* and accuracy of approximation.
*
* @param g the geometry to buffer
* @param distance the buffer distance
* @param parameters the buffer parameters to use
* @return the buffer of the input geometry
*/
@SuppressWarnings("unchecked")
public static <G extends Geometry> G buffer(final Geometry geometry, final double distance, final BufferParameters parameters) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
try {
final MCIndexNoder noder = new MCIndexNoder();
final LineIntersector li = new RobustLineIntersector(geometryFactory.getScaleXY());
noder.setSegmentIntersector(new IntersectionAdder(li));
return (G) buffer(noder, geometryFactory, geometry, distance, parameters);
} catch (final RuntimeException e) {
if (geometryFactory.isFloating()) {
return (G) bufferReducedPrecision(geometry, distance, parameters);
} else {
return (G) bufferFixedPrecision(geometryFactory, geometry, distance, parameters);
}
}
}
Aggregations