use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class GeometryCollectionSegment method hasNext.
@Override
public boolean hasNext() {
if (this.partIndex == -2) {
return false;
} else {
final Geometry geometryCollection = this.geometryCollection;
int partIndex = this.partIndex;
Segment segment = this.segment;
if (segment != null && !segment.hasNext()) {
partIndex++;
segment = null;
}
while (segment == null && partIndex < geometryCollection.getGeometryCount()) {
if (partIndex >= 0) {
final Geometry part = geometryCollection.getGeometry(partIndex);
if (part != null) {
final Iterator<Segment> segmentIterator = part.segments().iterator();
if (segmentIterator.hasNext()) {
return true;
} else {
segment = null;
}
}
}
if (partIndex > -2) {
partIndex++;
}
}
if (segment == null) {
return false;
} else {
return segment.hasNext();
}
}
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class GeometryCollectionSegment method setSegmentId.
@Override
public void setSegmentId(final int... segmentId) {
this.segment = null;
if (segmentId.length > 0) {
this.partIndex = segmentId[0];
final Geometry geometryCollection = this.geometryCollection;
if (this.partIndex >= 0 && this.partIndex < geometryCollection.getGeometryCount()) {
final Geometry part = geometryCollection.getGeometry(this.partIndex);
if (part != null) {
final int[] partSegmentId = new int[segmentId.length - 1];
System.arraycopy(segmentId, 1, partSegmentId, 0, partSegmentId.length);
this.segment = part.getSegment(partSegmentId);
}
}
} else {
this.partIndex = -2;
}
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class GeometryCollectionImpl method forEachPolygon.
@Override
public void forEachPolygon(final Consumer<Polygon> action) {
if (this.geometries != null) {
for (final Geometry geometry : this.geometries) {
if (geometry instanceof Polygon) {
final Polygon polygon = (Polygon) geometry;
action.accept(polygon);
} else if (geometry instanceof GeometryCollection) {
geometry.forEachPolygon(action);
}
}
}
}
use of com.revolsys.geometry.model.Geometry 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.Geometry 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;
}
}
}
Aggregations