Search in sources :

Example 1 with DouglasPeuckerSimplifier

use of org.locationtech.jts.simplify.DouglasPeuckerSimplifier in project OpenTripPlanner by opentripplanner.

the class GraphUtils method makeBuffer.

public static Geometry makeBuffer(Graph graph) {
    Geometry geom = geometryCollectionFromVertices(graph).buffer(.04, 6);
    DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier(geom);
    simplifier.setDistanceTolerance(0.00001);
    return simplifier.getResultGeometry();
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) DouglasPeuckerSimplifier(org.locationtech.jts.simplify.DouglasPeuckerSimplifier)

Example 2 with DouglasPeuckerSimplifier

use of org.locationtech.jts.simplify.DouglasPeuckerSimplifier in project teiid by teiid.

the class GeometryUtils method simplify.

public static GeometryType simplify(GeometryType geom, double tolerance) throws FunctionExecutionException {
    DouglasPeuckerSimplifier douglasPeuckerSimplifier = new DouglasPeuckerSimplifier(getGeometry(geom));
    douglasPeuckerSimplifier.setEnsureValid(false);
    douglasPeuckerSimplifier.setDistanceTolerance(tolerance);
    Geometry resultGeometry = douglasPeuckerSimplifier.getResultGeometry();
    return getGeometryType(resultGeometry, geom.getSrid());
}
Also used : DouglasPeuckerSimplifier(org.locationtech.jts.simplify.DouglasPeuckerSimplifier)

Example 3 with DouglasPeuckerSimplifier

use of org.locationtech.jts.simplify.DouglasPeuckerSimplifier in project hortonmachine by TheHortonMachine.

the class OmsVectorSimplifier method process.

// PARAM DESC END
@Execute
public void process() throws Exception {
    if (!concatOr(outVector == null, doReset)) {
        return;
    }
    FeatureIterator<SimpleFeature> inFeatureIterator = inVector.features();
    outVector = new DefaultFeatureCollection();
    FeatureGeometrySubstitutor fGS = new FeatureGeometrySubstitutor(inVector.getSchema());
    GeometryPrecisionReducer geometryReducer = null;
    int size = inVector.size();
    pm.beginTask("Simplifing features...", size);
    while (inFeatureIterator.hasNext()) {
        SimpleFeature feature = inFeatureIterator.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        List<Geometry> geomList = new ArrayList<Geometry>();
        int numGeometries = geometry.getNumGeometries();
        for (int i = 0; i < numGeometries; i++) {
            Geometry geometryN = geometry.getGeometryN(i);
            switch(pType) {
                case TOPOLOGYPRESERVINGSIMPLIFIER:
                    TopologyPreservingSimplifier tpSimplifier = new TopologyPreservingSimplifier(geometryN);
                    tpSimplifier.setDistanceTolerance(pTolerance);
                    Geometry tpsGeometry = tpSimplifier.getResultGeometry();
                    geomList.add(tpsGeometry);
                    break;
                case DOUGLAS_PEUCKER:
                    DouglasPeuckerSimplifier dpSimplifier = new DouglasPeuckerSimplifier(geometryN);
                    dpSimplifier.setDistanceTolerance(pTolerance);
                    Geometry dpsGeometry = dpSimplifier.getResultGeometry();
                    geomList.add(dpsGeometry);
                    break;
                case PRECISION_REDUCER:
                    if (geometryReducer == null) {
                        if (pScale == null) {
                            throw new ModelsIllegalargumentException("To reduce the precision the scale parameter needs to be set.", this);
                        }
                        geometryReducer = new GeometryPrecisionReducer(new PrecisionModel(pScale));
                    }
                    geomList.add(geometryReducer.reduce(geometryN));
                default:
            }
        }
        Geometry newGeometry = null;
        if (geomList.size() == 1) {
            newGeometry = geomList.get(0);
        } else {
            Geometry[] geomArray = (Geometry[]) geomList.toArray(new Geometry[geomList.size()]);
            newGeometry = new GeometryCollection(geomArray, gf);
        }
        SimpleFeature newFeature = fGS.substituteGeometry(feature, newGeometry);
        ((DefaultFeatureCollection) outVector).add(newFeature);
        pm.worked(1);
    }
    pm.done();
    inFeatureIterator.close();
}
Also used : ArrayList(java.util.ArrayList) DouglasPeuckerSimplifier(org.locationtech.jts.simplify.DouglasPeuckerSimplifier) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(org.locationtech.jts.geom.Geometry) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) GeometryPrecisionReducer(org.locationtech.jts.precision.GeometryPrecisionReducer) TopologyPreservingSimplifier(org.locationtech.jts.simplify.TopologyPreservingSimplifier) FeatureGeometrySubstitutor(org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) Execute(oms3.annotations.Execute)

Example 4 with DouglasPeuckerSimplifier

use of org.locationtech.jts.simplify.DouglasPeuckerSimplifier in project snap-idepix by bcdev.

the class IdepixOlciUtils method computeProductGeometry.

static Geometry computeProductGeometry(Product product) {
    try {
        final GeneralPath[] paths = GeoUtils.createGeoBoundaryPaths(product);
        final Polygon[] polygons = new Polygon[paths.length];
        final GeometryFactory factory = new GeometryFactory();
        for (int i = 0; i < paths.length; i++) {
            polygons[i] = convertAwtPathToJtsPolygon(paths[i], factory);
        }
        final DouglasPeuckerSimplifier peuckerSimplifier = new DouglasPeuckerSimplifier(polygons.length == 1 ? polygons[0] : factory.createMultiPolygon(polygons));
        return peuckerSimplifier.getResultGeometry();
    } catch (Exception e) {
        return null;
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) GeneralPath(java.awt.geom.GeneralPath) DouglasPeuckerSimplifier(org.locationtech.jts.simplify.DouglasPeuckerSimplifier) Polygon(org.locationtech.jts.geom.Polygon) IOException(java.io.IOException)

Aggregations

DouglasPeuckerSimplifier (org.locationtech.jts.simplify.DouglasPeuckerSimplifier)4 Geometry (org.locationtech.jts.geom.Geometry)2 GeneralPath (java.awt.geom.GeneralPath)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Execute (oms3.annotations.Execute)1 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)1 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)1 FeatureGeometrySubstitutor (org.hortonmachine.gears.utils.features.FeatureGeometrySubstitutor)1 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 Polygon (org.locationtech.jts.geom.Polygon)1 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)1 GeometryPrecisionReducer (org.locationtech.jts.precision.GeometryPrecisionReducer)1 TopologyPreservingSimplifier (org.locationtech.jts.simplify.TopologyPreservingSimplifier)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1