use of org.hortonmachine.gears.modules.r.rasterdiff.OmsRasterDiff in project hortonmachine by TheHortonMachine.
the class OmsGeomorphonMaximaFinder method process.
@Execute
public void process() throws Exception {
checkNull(inDTM, inDSM);
GridGeometry2D gridGeometry = inDSM.getGridGeometry();
DummyProgressMonitor pm = new DummyProgressMonitor();
OmsGeomorphon g = new OmsGeomorphon();
g.pm = pm;
g.inElev = inDSM;
g.pRadius = pRadius;
g.pThreshold = pThreshold;
g.process();
GridCoverage2D geomorphonGC = g.outRaster;
OmsRasterDiff rasterDiff = new OmsRasterDiff();
rasterDiff.inRaster1 = inDSM;
rasterDiff.inRaster2 = inDTM;
rasterDiff.pm = pm;
rasterDiff.process();
GridCoverage2D dsmDtmThresDiff = rasterDiff.outRaster;
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inDSM);
int rows = regionMap.getRows();
int cols = regionMap.getCols();
TreeSet<GridNode> topNodes = new TreeSet<GridNode>(new GridNodePositionComparator());
peakCode = GeomorphonClassification.PEAK.getCode();
hollowCode = GeomorphonClassification.HOLLOW.getCode();
valleyCode = GeomorphonClassification.VALLEY.getCode();
pitCode = GeomorphonClassification.PIT.getCode();
spurCode = GeomorphonClassification.SPUR.getCode();
double geomorphNv = HMConstants.getNovalue(geomorphonGC);
double elevNv = HMConstants.getNovalue(dsmDtmThresDiff);
RandomIter geomorphIter = CoverageUtilities.getRandomIterator(geomorphonGC);
RandomIter elevIter = CoverageUtilities.getRandomIterator(dsmDtmThresDiff);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
GridNode geomorphNode = new GridNode(geomorphIter, cols, rows, 1, -1, c, r, geomorphNv);
GridNode elevNode = new GridNode(elevIter, cols, rows, 1, -1, c, r, elevNv);
if (geomorphNode.elevation == peakCode && !elevNode.touchesBound()) {
// found peak
boolean isLocalMaxima = true;
TreeSet<GridNode> peakNodes = new TreeSet<GridNode>(new GridNodePositionComparator());
peakNodes.add(geomorphNode);
gatherNodes(peakNodes, geomorphNode);
if (peakNodes.size() == 1) {
GridNode topNode = peakNodes.first();
GridNode topElevNode = new GridNode(elevIter, cols, rows, 1, -1, topNode.col, topNode.row, elevNv);
List<GridNode> validSurroundingNodes = topElevNode.getValidSurroundingNodes();
if (validSurroundingNodes.size() < 6) {
// no more than 2 invalid permitted
isLocalMaxima = false;
} else {
if (!analyzeNeighbors(topNode)) {
isLocalMaxima = false;
}
}
}
GridNode topNode = null;
if (isLocalMaxima) {
double maxElev = Double.NEGATIVE_INFINITY;
for (GridNode peakNode : peakNodes) {
double elev = peakNode.getValueFromMap(elevIter);
if (elev > maxElev) {
maxElev = elev;
topNode = peakNode;
}
}
if (topNode != null) {
// check
GridNode topElevNode = new GridNode(elevIter, cols, rows, 1, -1, topNode.col, topNode.row, elevNv);
double[][] windowValues = topElevNode.getWindow(3, false);
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (double[] windowRow : windowValues) {
for (double windowValue : windowRow) {
if (HMConstants.isNovalue(windowValue)) {
isLocalMaxima = false;
break;
} else {
min = Math.min(min, windowValue);
max = Math.max(max, windowValue);
}
}
if (!isLocalMaxima) {
break;
}
}
if (max - min > pElevDiffThres) {
isLocalMaxima = false;
}
}
}
if (isLocalMaxima && topNode != null) {
topNodes.add(topNode);
}
}
}
}
outMaxima = new DefaultFeatureCollection();
SimpleFeatureBuilder builder = getOutBuilder();
int id = 0;
for (GridNode topNode : topNodes) {
Coordinate coordinate = CoverageUtilities.coordinateFromColRow(topNode.col, topNode.row, gridGeometry);
Point point = gf.createPoint(coordinate);
double elev = topNode.getValueFromMap(elevIter);
Object[] values = new Object[] { point, id++, elev };
try {
builder.addAll(values);
} catch (Exception e) {
e.printStackTrace();
}
SimpleFeature newFeature = builder.buildFeature(null);
((DefaultFeatureCollection) outMaxima).add(newFeature);
}
geomorphIter.done();
elevIter.done();
int size = outMaxima.size();
if (size == 0) {
pm.message("No tops extracted...");
} else {
pm.message("Extracted tops = " + outMaxima.size());
}
}
use of org.hortonmachine.gears.modules.r.rasterdiff.OmsRasterDiff in project hortonmachine by TheHortonMachine.
the class TestRasterDiff method testDiff.
public void testDiff() throws Exception {
OmsRasterDiff cutout = new OmsRasterDiff();
cutout.pm = pm;
cutout.inRaster1 = inRaster1;
cutout.inRaster2 = inRaster2;
cutout.process();
GridCoverage2D out = cutout.outRaster;
int[][] expected = new int[][] { //
{ intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN }, //
{ intNaN, intNaN, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, { intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN } };
checkMatrixEqual(out.getRenderedImage(), expected, 0);
}
use of org.hortonmachine.gears.modules.r.rasterdiff.OmsRasterDiff in project hortonmachine by TheHortonMachine.
the class TestRasterDiff method testDiffWithThres.
public void testDiffWithThres() throws Exception {
OmsRasterDiff cutout = new OmsRasterDiff();
cutout.pm = pm;
cutout.inRaster1 = inRaster1;
cutout.inRaster2 = inRaster2;
cutout.pThreshold = 0.0;
cutout.process();
GridCoverage2D out = cutout.outRaster;
int[][] expected = new int[][] { //
{ intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN }, //
{ intNaN, intNaN, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, //
{ intNaN, 0, 0, 0, 0, 0, 0, 0, 0, intNaN }, { intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN, intNaN } };
checkMatrixEqual(out.getRenderedImage(), expected, 0);
}
use of org.hortonmachine.gears.modules.r.rasterdiff.OmsRasterDiff in project hortonmachine by TheHortonMachine.
the class OmsLW10_CHM_AreaToNetpointAssociator method getChm.
/*
* extract the Canopy Height Model from DTM and DSM
*/
private GridCoverage2D getChm(GridCoverage2D inDsm, GridCoverage2D inDtm) throws Exception {
OmsRasterDiff rasterDiff = new OmsRasterDiff();
rasterDiff.pm = pm;
rasterDiff.inRaster1 = inDsm;
rasterDiff.inRaster2 = inDtm;
rasterDiff.pThreshold = 0.0;
rasterDiff.doNegatives = false;
rasterDiff.process();
GridCoverage2D out = rasterDiff.outRaster;
return out;
}
use of org.hortonmachine.gears.modules.r.rasterdiff.OmsRasterDiff in project hortonmachine by TheHortonMachine.
the class RasterDiff method process.
@Execute
public void process() throws Exception {
OmsRasterDiff rasterdiff = new OmsRasterDiff();
rasterdiff.inRaster1 = getRaster(inRaster1);
rasterdiff.inRaster2 = getRaster(inRaster2);
rasterdiff.pThreshold = pThreshold;
rasterdiff.doNegatives = doNegatives;
rasterdiff.pm = pm;
rasterdiff.doProcess = doProcess;
rasterdiff.doReset = doReset;
rasterdiff.process();
dumpRaster(rasterdiff.outRaster, outRaster);
}
Aggregations