Search in sources :

Example 1 with BufferParameters

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) InstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) GeometryFinder(eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder) BufferParameters(org.locationtech.jts.operation.buffer.BufferParameters) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Nullable(javax.annotation.Nullable)

Aggregations

DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)1 GeometryFinder (eu.esdihumboldt.hale.common.instance.geometry.GeometryFinder)1 DepthFirstInstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser)1 InstanceTraverser (eu.esdihumboldt.hale.common.instance.helper.InstanceTraverser)1 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)1 Nullable (javax.annotation.Nullable)1 Geometry (org.locationtech.jts.geom.Geometry)1 BufferParameters (org.locationtech.jts.operation.buffer.BufferParameters)1