use of org.locationtech.jts.operation.buffer.BufferParameters in project hale by halestudio.
the class NetworkExpansion method calculateBuffer.
/**
* Calculate a buffer geometry.
*
* @param geometryHolder the geometry or object holding a geometry
* @param bufferWidth the buffer width
* @param log the transformation log, may be <code>null</code>
* @return the buffer geometry or <code>null</code>
*/
@Nullable
public static GeometryProperty<Geometry> calculateBuffer(Object geometryHolder, double bufferWidth, @Nullable TransformationLog log) {
// find contained geometries
InstanceTraverser traverser = new DepthFirstInstanceTraverser(true);
GeometryFinder geoFind = new GeometryFinder(null);
traverser.traverse(geometryHolder, geoFind);
List<GeometryProperty<?>> geometries = geoFind.getGeometries();
GeometryProperty<?> old_geometry = null;
if (!geometries.isEmpty()) {
old_geometry = geometries.get(0);
if (geometries.size() > 1) {
if (log != null) {
log.warn(log.createMessage("Multiple geometries found, but network expansion is only done on the first.", null));
}
}
}
GeometryProperty<Geometry> result = null;
if (old_geometry != null) {
Geometry new_geometry = null;
BufferParameters bufferParameters = new BufferParameters();
bufferParameters.setEndCapStyle(CAP_STYLE);
new_geometry = BufferOp.bufferOp(old_geometry.getGeometry(), bufferWidth, bufferParameters);
result = new DefaultGeometryProperty<Geometry>(old_geometry.getCRSDefinition(), new_geometry);
}
return result;
}
Aggregations