Search in sources :

Example 1 with LogProgressMonitor

use of org.hortonmachine.gears.libs.monitor.LogProgressMonitor in project hortonmachine by TheHortonMachine.

the class OpenstreetmapImageCreator method main.

public static void main(String[] args) throws Exception {
    String outFile = "/home/hydrologis/Dropbox/hydrologis/lavori/2015_05_bim_sarcamincio/shape_3857/image_output/osm15.png";
    String bounds = "/home/hydrologis/Dropbox/hydrologis/lavori/2015_05_bim_sarcamincio/shape_3857/area.shp";
    String inServiceUrl = "http://a.tile.opencyclemap.org/cycle/ZZZ/XXX/YYY.png";
    // String inServiceUrl = "http://a.tile.openstreetmap.org/ZZZ/XXX/YYY.png";
    ReferencedEnvelope env = OmsVectorReader.readVector(bounds).getBounds();
    OpenstreetmapImageCreator c = new OpenstreetmapImageCreator(inServiceUrl, 15, env, new File(outFile), new LogProgressMonitor());
    c.generate();
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) File(java.io.File) LogProgressMonitor(org.hortonmachine.gears.libs.monitor.LogProgressMonitor)

Example 2 with LogProgressMonitor

use of org.hortonmachine.gears.libs.monitor.LogProgressMonitor in project hortonmachine by TheHortonMachine.

the class LasOnDtmBuildingsExtractor method process.

@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);
        }
    }
}
Also used : GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) IHMProgressMonitor(org.hortonmachine.gears.libs.monitor.IHMProgressMonitor) RegionMap(org.hortonmachine.gears.utils.RegionMap) LogProgressMonitor(org.hortonmachine.gears.libs.monitor.LogProgressMonitor) LasRecord(org.hortonmachine.gears.io.las.core.LasRecord) WritableRaster(java.awt.image.WritableRaster) OmsMorpher(org.hortonmachine.gears.modules.r.morpher.OmsMorpher) Polygon(org.locationtech.jts.geom.Polygon) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) OmsRasterReader(org.hortonmachine.gears.io.rasterreader.OmsRasterReader) Envelope2D(org.geotools.geometry.Envelope2D) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) ALasDataManager(org.hortonmachine.gears.io.las.ALasDataManager) Coordinate(org.locationtech.jts.geom.Coordinate) OmsVectorizer(org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer) ReferencedEnvelope3D(org.geotools.geometry.jts.ReferencedEnvelope3D) File(java.io.File) Execute(oms3.annotations.Execute)

Aggregations

File (java.io.File)2 LogProgressMonitor (org.hortonmachine.gears.libs.monitor.LogProgressMonitor)2 WritableRaster (java.awt.image.WritableRaster)1 Execute (oms3.annotations.Execute)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)1 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)1 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)1 Envelope2D (org.geotools.geometry.Envelope2D)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 ReferencedEnvelope3D (org.geotools.geometry.jts.ReferencedEnvelope3D)1 ALasDataManager (org.hortonmachine.gears.io.las.ALasDataManager)1 LasRecord (org.hortonmachine.gears.io.las.core.LasRecord)1 OmsRasterReader (org.hortonmachine.gears.io.rasterreader.OmsRasterReader)1 IHMProgressMonitor (org.hortonmachine.gears.libs.monitor.IHMProgressMonitor)1 OmsMorpher (org.hortonmachine.gears.modules.r.morpher.OmsMorpher)1 OmsVectorizer (org.hortonmachine.gears.modules.v.vectorize.OmsVectorizer)1 RegionMap (org.hortonmachine.gears.utils.RegionMap)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Polygon (org.locationtech.jts.geom.Polygon)1