Search in sources :

Example 1 with BufferBuilder

use of com.vividsolutions.jts.operation.buffer.BufferBuilder 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);
        BufferBuilder bb = new BufferBuilder(new BufferParameters());
        new_geometry = bb.buffer(old_geometry.getGeometry(), bufferWidth);
        result = new DefaultGeometryProperty<Geometry>(old_geometry.getCRSDefinition(), new_geometry);
    }
    return result;
}
Also used : Geometry(com.vividsolutions.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(com.vividsolutions.jts.operation.buffer.BufferParameters) BufferBuilder(com.vividsolutions.jts.operation.buffer.BufferBuilder) DepthFirstInstanceTraverser(eu.esdihumboldt.hale.common.instance.helper.DepthFirstInstanceTraverser) Nullable(javax.annotation.Nullable)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)1 BufferBuilder (com.vividsolutions.jts.operation.buffer.BufferBuilder)1 BufferParameters (com.vividsolutions.jts.operation.buffer.BufferParameters)1 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