Search in sources :

Example 41 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsVectorizer method doRegionCheck.

private void doRegionCheck() throws TransformException {
    if (doRegioncheck) {
        int left = Integer.MAX_VALUE;
        int right = -Integer.MAX_VALUE;
        int top = -Integer.MAX_VALUE;
        int bottom = Integer.MAX_VALUE;
        RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
        int cols = regionMap.getCols();
        int rows = regionMap.getRows();
        pm.beginTask("Try to shrink the region over covered area...", rows);
        RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                double value = rasterIter.getSampleDouble(c, r, 0);
                if (!isNovalue(value)) {
                    left = min(left, c);
                    right = max(right, c);
                    top = max(top, r);
                    bottom = min(bottom, r);
                }
            }
            pm.worked(1);
        }
        pm.done();
        rasterIter.done();
        GridGeometry2D gridGeometry = inRaster.getGridGeometry();
        GridEnvelope2D gEnv = new GridEnvelope2D();
        gEnv.setLocation(new Point(left, top));
        gEnv.add(new Point(right, bottom));
        Envelope2D envelope2d = gridGeometry.gridToWorld(gEnv);
        inRaster = (GridCoverage2D) Operations.DEFAULT.crop(inRaster, envelope2d);
    }
}
Also used : GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) Point(java.awt.Point) Envelope2D(org.geotools.geometry.Envelope2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Point(java.awt.Point)

Example 42 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsPointsVectorizer method process.

@Execute
public void process() throws Exception {
    if (!concatOr(outVector == null, doReset)) {
        return;
    }
    checkNull(inRaster);
    GridGeometry2D gridGeometry = inRaster.getGridGeometry();
    RegionMap regionMap = getRegionParamsFromGridCoverage(inRaster);
    int cols = regionMap.getCols();
    int rows = regionMap.getRows();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("pointtype");
    b.setCRS(inRaster.getCoordinateReferenceSystem());
    b.add("the_geom", Point.class);
    b.add(fDefault, Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    GeometryFactory gF = new GeometryFactory();
    outVector = new DefaultFeatureCollection();
    RandomIter rasterIter = RandomIterFactory.create(inRaster.getRenderedImage(), null);
    pm.beginTask("Extracting points...", rows);
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            double value = rasterIter.getSampleDouble(c, r, 0);
            if (isNovalue(value)) {
                continue;
            }
            DirectPosition world = gridGeometry.gridToWorld(new GridCoordinates2D(c, r));
            double[] coordinate = world.getCoordinate();
            Coordinate coord = new Coordinate(coordinate[0], coordinate[1]);
            Point point = gF.createPoint(coord);
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
            Object[] values = new Object[] { point, value };
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            ((DefaultFeatureCollection) outVector).add(feature);
        }
    }
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) GridCoordinates2D(org.geotools.coverage.grid.GridCoordinates2D) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Execute(oms3.annotations.Execute)

Example 43 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class PrintUtilities method printRenderedImageData.

/**
 * Print data from a {@link RenderedImage}.
 *
 * @param renderedImage
 *            the image.
 */
public static void printRenderedImageData(RenderedImage renderedImage) {
    RandomIter iter = RandomIterFactory.create(renderedImage, null);
    int cols = renderedImage.getWidth();
    int rows = renderedImage.getHeight();
    int numBands = renderedImage.getSampleModel().getNumBands();
    for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
            for (int b = 0; b < numBands; b++) {
                if (b > 0) {
                    printer.print("/");
                }
                printer.print(iter.getSampleDouble(c, r, b));
            }
            printer.print(separator);
        }
        printer.println();
    }
    iter.done();
}
Also used : RandomIter(javax.media.jai.iterator.RandomIter)

Example 44 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsDistanceToOutlet method process.

@Execute
public void process() {
    if (!concatOr(outDistance == null, doReset)) {
        return;
    }
    checkInParameters();
    RandomIter pitIter = null;
    if (inPit != null) {
        pitIter = CoverageUtilities.getRandomIterator(inPit);
    }
    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlow);
    int cols = regionMap.get(CoverageUtilities.COLS).intValue();
    int rows = regionMap.get(CoverageUtilities.ROWS).intValue();
    RenderedImage flowRI = inFlow.getRenderedImage();
    WritableRaster flowWR = CoverageUtilities.renderedImage2WritableRaster(flowRI, true);
    WritableRandomIter flowIter = RandomIterFactory.createWritable(flowWR, null);
    WritableRaster distanceWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, 0.0);
    WritableRandomIter distanceIter = CoverageUtilities.getWritableRandomIterator(distanceWR);
    if (pMode == 1) {
        ModelsEngine.outletdistance(flowIter, distanceIter, regionMap, pm);
    } else if (pMode == 0) {
        ModelsEngine.topologicalOutletdistance(flowIter, pitIter, distanceIter, regionMap, pm);
    }
    for (int j = 0; j < rows; j++) {
        for (int i = 0; i < cols; i++) {
            if (isNovalue(flowIter.getSampleDouble(i, j, 0))) {
                distanceIter.setSample(i, j, 0, HMConstants.doubleNovalue);
            }
        }
    }
    outDistance = CoverageUtilities.buildCoverage("distanceToOutlet", distanceWR, regionMap, inFlow.getCoordinateReferenceSystem());
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) RegionMap(org.hortonmachine.gears.utils.RegionMap) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Example 45 with RandomIter

use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.

the class OmsHackLength method process.

@Execute
public void process() {
    if (!concatOr(outHacklength == null, doReset)) {
        return;
    }
    checkNull(inFlow, inTca);
    regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inFlow);
    nCols = regionMap.getCols();
    nRows = regionMap.getRows();
    xRes = regionMap.getXres();
    yRes = regionMap.getYres();
    RandomIter tcaIter = CoverageUtilities.getRandomIterator(inTca);
    RenderedImage flowRI = inFlow.getRenderedImage();
    WritableRaster flowWR = CoverageUtilities.renderedImage2WritableRaster(flowRI, true);
    WritableRandomIter flowIter = RandomIterFactory.createWritable(flowWR, null);
    // if inElevation isn't null then work in 3d.
    RandomIter elevIter = null;
    if (inElevation != null) {
        elevIter = CoverageUtilities.getRandomIterator(inElevation);
    }
    int novalue = HMConstants.getIntNovalue(inFlow);
    hacklength(flowIter, novalue, tcaIter, elevIter);
    tcaIter.done();
    flowIter.done();
    if (elevIter != null) {
        elevIter.done();
    }
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) WritableRaster(java.awt.image.WritableRaster) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Aggregations

RandomIter (javax.media.jai.iterator.RandomIter)126 WritableRandomIter (javax.media.jai.iterator.WritableRandomIter)79 WritableRaster (java.awt.image.WritableRaster)71 RegionMap (org.hortonmachine.gears.utils.RegionMap)62 Execute (oms3.annotations.Execute)57 RenderedImage (java.awt.image.RenderedImage)29 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)29 Coordinate (org.locationtech.jts.geom.Coordinate)26 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)22 Point (java.awt.Point)17 ArrayList (java.util.ArrayList)17 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)16 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)15 Geometry (org.locationtech.jts.geom.Geometry)15 Point (org.locationtech.jts.geom.Point)14 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)12 GridNode (org.hortonmachine.gears.libs.modules.GridNode)12 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)10 FlowNode (org.hortonmachine.gears.libs.modules.FlowNode)9