Java Code Examples for org.locationtech.jts.geom.Geometry#buffer()

The following examples show how to use org.locationtech.jts.geom.Geometry#buffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureElevationComparer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public FeatureElevationComparer( SimpleFeature feature, String field, double buffer, double lengthThreshold ) {
    this.feature = feature;
    this.buffer = buffer;
    this.lengthThreshold = lengthThreshold;

    elevation = ((Number) feature.getAttribute(field)).doubleValue();
    geometry = (Geometry) feature.getDefaultGeometry();

    if (buffer > 0) {
        try{
            bufferPolygon = geometry.buffer(buffer);
        }catch (Exception e) {
            e.printStackTrace();
            try{
            System.out.println("TRYING WITH WIDER BUFFER: *2");
            bufferPolygon = geometry.buffer(buffer*2);
            }catch (Exception e1) {
                e1.printStackTrace();
                System.out.println("TRYING WITH WIDER BUFFER: *4");
                bufferPolygon = geometry.buffer(buffer*4);
            }
        }
    }
}
 
Example 2
Source File: OmsLW01_ChannelPolygonMerger.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inBankfull);

    List<Geometry> geoms = FeatureUtilities.featureCollectionToGeometriesList(inBankfull, true, null);

    // creates a unique feature with multipolygons
    Geometry union = CascadedPolygonUnion.union(geoms);

    // makes a buffer of each geometry in the feature and merges the touching geometries
    Geometry buffer = union.buffer(0.05);

    // splits the remaining geometries (not touching)
    List<Geometry> newGeoms = new ArrayList<Geometry>();
    for( int i = 0; i < buffer.getNumGeometries(); i++ ) {
        Geometry geometryN = buffer.getGeometryN(i);
        if (geometryN instanceof Polygon) {
            newGeoms.add(geometryN);
        }
    }

    outBankfull = FeatureUtilities.featureCollectionFromGeometry(inBankfull.getBounds().getCoordinateReferenceSystem(),
            newGeoms.toArray(GeometryUtilities.TYPE_POLYGON));

}
 
Example 3
Source File: OmsLW08_NetworkBufferWidthCalculator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<Geometry> getPolygonBetweenLines( ArrayList<SimpleFeature> newLinesFeatures ) {
    ArrayList<Geometry> polygons = new ArrayList<Geometry>();
    for( int i = 0; i < newLinesFeatures.size() - 1; i++ ) {
        SimpleFeature f1 = newLinesFeatures.get(i);
        SimpleFeature f2 = newLinesFeatures.get(i + 1);

        LineString l1 = (LineString) f1.getDefaultGeometry();
        LineString l2 = (LineString) f2.getDefaultGeometry();
        MultiLineString multiLine = gf.createMultiLineString(new LineString[]{l1, l2});

        Geometry convexHull = multiLine.convexHull();
        Geometry buffer = convexHull.buffer(0.1);
        polygons.add(buffer);
    }
    return polygons;
}
 
Example 4
Source File: LasOnDtmBuildingsExtractor.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private DefaultFeatureCollection removeNonBuildings( ALasDataManager lasHandler, SimpleFeatureCollection buildingsFC,
        GridCoverage2D dem, double buildingsBuffer ) throws Exception {
    final List<SimpleFeature> buildingsList = FeatureUtilities.featureCollectionToList(buildingsFC);

    final List<SimpleFeature> checkedBuildings = new ArrayList<SimpleFeature>();
    pm.beginTask("Removing buildings...", buildingsList.size());
    for( int i = 0; i < buildingsList.size(); i++ ) {
        SimpleFeature building = buildingsList.get(i);
        Geometry buildingGeom = (Geometry) building.getDefaultGeometry();

        Geometry bufferedGeom = buildingGeom.buffer(buildingsBuffer);
        List<LasRecord> points = lasHandler.getPointsInGeometry(bufferedGeom, false);
        int percOfOnes = checkReturnNum(points, bufferedGeom);
        if (percOfOnes >= 96) {
            checkedBuildings.add(building);
        }
        pm.worked(1);
    }
    pm.done();

    DefaultFeatureCollection fc = new DefaultFeatureCollection();
    fc.addAll(checkedBuildings);
    return fc;
}
 
Example 5
Source File: OmsLineIntersectionCorrector.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private Geometry selfSnap( Geometry g, double snapTolerance ) {
    GeometrySnapper snapper = new GeometrySnapper(g);
    Geometry snapped = snapper.snapTo(g, snapTolerance);
    // need to "clean" snapped geometry - use buffer(0) as a simple way to do this
    Geometry fix = snapped.buffer(0);
    return fix;
}
 
Example 6
Source File: HillSlope.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public Geometry getGeometry( List<PfafstetterNumber> limit, IHMProgressMonitor pm, boolean doMonitor ) {

        if (limit == null && totalGeometryUpstream != null) {
            return totalGeometryUpstream;
        }

        List<Geometry> geometries = new ArrayList<Geometry>();
        geometries.add((Geometry) hillslopeFeature.getDefaultGeometry());
        getAllUpstreamElementsGeometries(geometries, limit, this);
        GeometryFactory gFactory = new GeometryFactory();
        /*
         * join the geoms to a single one
         */
        Geometry runningGeometry = geometries.get(0);
        if (doMonitor)
            pm.beginTask("Estrazione geometrie dei bacini elementari a monte", geometries.size() - 1);
        for( int i = 1; i < geometries.size(); i++ ) {
            if (doMonitor) {
                pm.worked(1);
            } else {
                pm.subTask("Unione geometrie " + i + "/" + (geometries.size() - 1));
            }
            List<Geometry> tmp = new ArrayList<Geometry>(2);
            tmp.add(runningGeometry);
            tmp.add(geometries.get(i));
            Geometry gCollection = gFactory.buildGeometry(tmp);
            runningGeometry = gCollection.buffer(0.0);
        }
        pm.subTask("");
        if (doMonitor)
            pm.done();

        // keep the total geometry, in case it is asked again
        if (limit == null) {
            totalGeometryUpstream = runningGeometry;
        }

        return runningGeometry;
        // return gCollection.buffer(0.0);
    }
 
Example 7
Source File: JTS.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * If the given geometry is a JTS geometry, computes its buffer. Otherwise returns {@code null}.
 */
@Override
Object tryBuffer(final Object geometry, final double distance) {
    if (geometry instanceof Geometry) {
        final Geometry jts = (Geometry) geometry;
        final Geometry buffer = jts.buffer(distance);
        copyMetadata(jts, buffer);
        return buffer;
    }
    return null;
}
 
Example 8
Source File: Shape.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get buffer shape
 * @param distance Distance
 * @return Buffered shape
 */
public Shape buffer(double distance){
    Geometry g1 = this.toGeometry();
    Geometry g3 = g1.buffer(distance);
    return geometry2Shape(g3);
}
 
Example 9
Source File: FeatureMate.java    From hortonmachine with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Apply a buffer to the geometry and use that as new {@link Geometry}.
 * 
 * @param buffer the buffer to apply.
 */
public void useBuffer( double buffer ) {
    Geometry tmpGeometry = getGeometry();
    geometry = tmpGeometry.buffer(buffer);
}