Search in sources :

Example 1 with GridNode

use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.

the class OmsDePitter method floodAndFlow.

private void floodAndFlow(int iteration, List<GridNode> nodesToCheck, double runningFloodValue, List<GridNode> allNodesOfPit, BitMatrix floodedPositions, WritableRandomIter pitIter) {
    iteration++;
    double currentRunningFloodValue = runningFloodValue + delta;
    List<GridNode> nodesForNextRound = new ArrayList<>();
    for (GridNode currentNode : nodesToCheck) {
        // flood and grow the first surrounding
        List<GridNode> currentSurroundingNodes = currentNode.getValidSurroundingNodes();
        for (GridNode gridNode : currentSurroundingNodes) {
            if (!floodedPositions.isMarked(gridNode.col, gridNode.row) && allNodesOfPit.contains(gridNode)) {
                double newValue = 0;
                if (gridNode.elevation <= runningFloodValue) {
                    newValue = currentRunningFloodValue;
                } else {
                    // TODO check if it is enough or
                    newValue = gridNode.elevation + delta;
                // better
                // add delta
                }
                gridNode.setValueInMap(pitIter, newValue);
                floodedPositions.mark(gridNode.col, gridNode.row);
                nodesForNextRound.add(gridNode);
            }
        }
    }
    int size = nodesForNextRound.size();
    if (size > 0) {
        floodAndFlow(iteration, nodesForNextRound, currentRunningFloodValue, allNodesOfPit, floodedPositions, pitIter);
    }
}
Also used : GridNode(org.hortonmachine.gears.libs.modules.GridNode) ArrayList(java.util.ArrayList)

Example 2 with GridNode

use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.

the class OmsDePitter method findConnectedOfSameHeight.

private void findConnectedOfSameHeight(GridNode node, BitMatrix allPitsPositions, List<GridNode> nodesInPit) {
    double elev = node.elevation;
    List<GridNode> checkNodes = new ArrayList<>();
    checkNodes.add(node);
    boolean oneAdded = true;
    int startIndex = 0;
    while (oneAdded) {
        oneAdded = false;
        int currentSize = checkNodes.size();
        for (int i = startIndex; i < currentSize; i++) {
            GridNode checkNode = checkNodes.get(i);
            List<GridNode> tmpNodes = checkNode.getValidSurroundingNodes();
            for (GridNode gridNode : tmpNodes) {
                if (allPitsPositions.isMarked(gridNode.col, gridNode.row)) {
                    continue;
                }
                if (gridNode.elevation == elev) {
                    checkNodes.add(gridNode);
                    nodesInPit.add(gridNode);
                    allPitsPositions.mark(gridNode.col, gridNode.row);
                    oneAdded = true;
                }
            }
        }
        startIndex = currentSize;
    }
}
Also used : GridNode(org.hortonmachine.gears.libs.modules.GridNode) ArrayList(java.util.ArrayList)

Example 3 with GridNode

use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.

the class OmsAspectIM method processCell.

@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
    RandomIter elevIter = inRasterIterators.get(0);
    Double novalue = inRasterNovalues.get(0);
    GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
    double aspect = OmsAspect.calculateAspect(node, radtodeg, doRound);
    WritableRandomIter outDataIter = outRasterIterators.get(0);
    outDataIter.setSample(writeCol, writeRow, 0, aspect);
}
Also used : WritableRandomIter(javax.media.jai.iterator.WritableRandomIter) GridNode(org.hortonmachine.gears.libs.modules.GridNode) RandomIter(javax.media.jai.iterator.RandomIter) WritableRandomIter(javax.media.jai.iterator.WritableRandomIter)

Example 4 with GridNode

use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.

the class OmsCurvaturesIM method processCell.

@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
    RandomIter elevIter = inRasterIterators.get(0);
    Double novalue = inRasterNovalues.get(0);
    GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
    OmsCurvatures.calculateCurvatures2(node, planTangProf);
    if (outPlan != null)
        outRasterIterators.get(0).setSample(writeCol, writeRow, 0, planTangProf[0]);
    if (outTang != null)
        outRasterIterators.get(1).setSample(writeCol, writeRow, 0, planTangProf[1]);
    if (outProf != null)
        outRasterIterators.get(2).setSample(writeCol, writeRow, 0, planTangProf[2]);
}
Also used : GridNode(org.hortonmachine.gears.libs.modules.GridNode) RandomIter(javax.media.jai.iterator.RandomIter)

Example 5 with GridNode

use of org.hortonmachine.gears.libs.modules.GridNode in project hortonmachine by TheHortonMachine.

the class OmsSlope method process.

@Execute
public void process() {
    if (!concatOr(outSlope == null, doReset)) {
        return;
    }
    checkNull(inPit, inFlow);
    HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit);
    int nCols = regionMap.get(CoverageUtilities.COLS).intValue();
    int nRows = regionMap.get(CoverageUtilities.ROWS).intValue();
    double xRes = regionMap.get(CoverageUtilities.XRES);
    double yRes = regionMap.get(CoverageUtilities.YRES);
    double novalue = HMConstants.getNovalue(inPit);
    RenderedImage elevationRI = inPit.getRenderedImage();
    RandomIter elevationIter = RandomIterFactory.create(elevationRI, null);
    RenderedImage flowRI = inFlow.getRenderedImage();
    RandomIter flowIter = RandomIterFactory.create(flowRI, null);
    WritableRaster slopeWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, doubleNovalue);
    pm.beginTask(msg.message("slope.calculating"), nCols);
    for (int r = 0; r < nRows; r++) {
        for (int c = 0; c < nCols; c++) {
            double flowValue = flowIter.getSampleDouble(c, r, 0);
            GridNode node = new GridNode(elevationIter, nCols, nRows, xRes, yRes, c, r, novalue);
            double value = calculateSlope(node, flowValue);
            if (doHandleNegativeSlope && value < 0) {
                value = Double.MIN_VALUE;
            }
            slopeWR.setSample(c, r, 0, value);
        }
        pm.worked(1);
    }
    pm.done();
    outSlope = CoverageUtilities.buildCoverageWithNovalue("slope", slopeWR, regionMap, inPit.getCoordinateReferenceSystem(), doubleNovalue);
}
Also used : GridNode(org.hortonmachine.gears.libs.modules.GridNode) WritableRaster(java.awt.image.WritableRaster) RandomIter(javax.media.jai.iterator.RandomIter) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Aggregations

GridNode (org.hortonmachine.gears.libs.modules.GridNode)35 RandomIter (javax.media.jai.iterator.RandomIter)12 RegionMap (org.hortonmachine.gears.utils.RegionMap)10 WritableRandomIter (javax.media.jai.iterator.WritableRandomIter)8 Execute (oms3.annotations.Execute)8 WritableRaster (java.awt.image.WritableRaster)7 ArrayList (java.util.ArrayList)5 BitMatrix (org.hortonmachine.gears.utils.BitMatrix)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)4 Point (org.locationtech.jts.geom.Point)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 TreeSet (java.util.TreeSet)3 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)3 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)2 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2