Java Code Examples for org.geotools.coverage.grid.GridCoverage2D#getEnvelope2D()

The following examples show how to use org.geotools.coverage.grid.GridCoverage2D#getEnvelope2D() . 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: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a bounds polygon of a {@link GridCoverage2D}.
 * 
 * @param gridCoverage the coverage to use.
 * @return the bounding polygon.
 */
public static Polygon getRegionPolygon( GridCoverage2D gridCoverage ) {
    Envelope2D env = gridCoverage.getEnvelope2D();
    Coordinate[] c = new Coordinate[]{new Coordinate(env.getMinX(), env.getMinY()),
            new Coordinate(env.getMinX(), env.getMaxY()), new Coordinate(env.getMaxX(), env.getMaxY()),
            new Coordinate(env.getMaxX(), env.getMinY()), new Coordinate(env.getMinX(), env.getMinY())};
    GeometryFactory gf = GeometryUtilities.gf();
    LinearRing linearRing = gf.createLinearRing(c);
    Polygon polygon = gf.createPolygon(linearRing, null);
    return polygon;
}
 
Example 2
Source File: PrintUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static String toString( GridCoverage2D coverage ) {
    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(coverage);
    StringBuilder sb = new StringBuilder();
    sb.append(regionMap.toStringJGT()).append("\n");
    Envelope2D envelope2d = coverage.getEnvelope2D();
    Envelope jtsEnvelope = envelope2D2Envelope(envelope2d);
    String envelope2wkt = envelope2WKT(jtsEnvelope);
    sb.append("WKT bounds: \n");
    sb.append(envelope2wkt);
    return sb.toString();
}
 
Example 3
Source File: LasOnDtmBuildingsExtractor.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inLas, inDtm, outBuildings);

    SimpleFeatureCollection buildingsFC = null;
    GridCoverage2D inDtmGC = null;
    try (ALasDataManager lasHandler = ALasDataManager.getDataManager(new File(inLas), inDtmGC, 0, null)) {
        lasHandler.open();

        ReferencedEnvelope3D e = lasHandler.getEnvelope3D();

        if (pRasterResolution != null) {
            OmsRasterReader reader = new OmsRasterReader();
            reader.file = inDtm;
            reader.pNorth = e.getMaxY();
            reader.pSouth = e.getMinY();
            reader.pWest = e.getMinX();
            reader.pEast = e.getMaxX();
            reader.pXres = pRasterResolution;
            reader.pYres = pRasterResolution;
            reader.process();
            inDtmGC = reader.outRaster;
        } else {
            inDtmGC = getRaster(inDtm);
            RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inDtmGC);
            pRasterResolution = regionMap.getXres();
        }

        Envelope2D envelope2d = inDtmGC.getEnvelope2D();
        Polygon regionPolygon = FeatureUtilities.envelopeToPolygon(envelope2d);

        WritableRaster[] buildingsHolder = new WritableRaster[1];
        GridCoverage2D newBuildingsRaster = CoverageUtilities.createCoverageFromTemplate(inDtmGC, 1.0, buildingsHolder);
        GridGeometry2D gridGeometry = newBuildingsRaster.getGridGeometry();

        java.awt.Point p = new java.awt.Point();
        IHMProgressMonitor pm = new LogProgressMonitor();
        pm.beginTask("Reading points...", IHMProgressMonitor.UNKNOWN);
        List<LasRecord> pointsInGeometry = lasHandler.getPointsInGeometry(regionPolygon, true);
        pm.done();
        pm.beginTask("Buildings filtering...", (int) pointsInGeometry.size());
        for( LasRecord dot : pointsInGeometry ) {
            Coordinate c = new Coordinate(dot.x, dot.y);
            if (!envelope2d.contains(dot.x, dot.y)) {
                continue;
            }

            double dtmValue = CoverageUtilities.getValue(inDtmGC, c);
            double height = abs(dot.z - dtmValue);
            CoverageUtilities.colRowFromCoordinate(c, gridGeometry, p);
            if (height < pDtmThres) {
                buildingsHolder[0].setSample(p.x, p.y, 0, doubleNovalue);
            }
            pm.worked(1);
        }
        pm.done();

        OmsMorpher morpher = new OmsMorpher();
        morpher.pm = pm;
        morpher.inMap = newBuildingsRaster;
        morpher.pMode = Variables.OPEN;
        morpher.process();
        newBuildingsRaster = morpher.outMap;

        OmsVectorizer buildingsVectorizer = new OmsVectorizer();
        buildingsVectorizer.pm = pm;
        buildingsVectorizer.inRaster = newBuildingsRaster;
        buildingsVectorizer.doRemoveHoles = true;
        double minAreaInCells = pMinArea / pRasterResolution / pRasterResolution;
        buildingsVectorizer.pThres = minAreaInCells;
        buildingsVectorizer.fDefault = "rast";
        buildingsVectorizer.process();

        buildingsFC = buildingsVectorizer.outVector;
        dumpVector(buildingsFC, outBuildings);
        if (doSmoothing && outCleanBuildings != null) {
            // smooth
            SimpleFeatureCollection smoothedFC = smoothBuildings(pDensifyResolution, buildingsFC);

            // remove trees
            DefaultFeatureCollection removedAndSmoothedFC = removeNonBuildings(lasHandler, smoothedFC, inDtmGC,
                    pBuildingsBuffer);

            dumpVector(removedAndSmoothedFC, outCleanBuildings);
        }
    }

}