use of org.hortonmachine.gears.libs.monitor.DummyProgressMonitor in project hortonmachine by TheHortonMachine.
the class OmsRasterSummary method process.
@Execute
public void process() throws Exception {
if (!concatOr(outMin == null, doReset)) {
return;
}
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
if (printToConsole) {
pm.message("Bounds and resolution");
pm.message("---------------------");
pm.message(regionMap.toStringJGT());
pm.message("");
pm.message("Coordinate Reference System");
pm.message("---------------------------");
pm.message(inRaster.getCoordinateReferenceSystem().toWKT());
pm.message("");
}
// TODO use the geotools bridge instead of jaitools:
// http://svn.osgeo.org/geotools/trunk/modules/library/coverage/src/test/java/org/geotools/coverage/processing/operation/ZonalStasTest.java
RenderedImage inRI = inRaster.getRenderedImage();
Polygon regionPolygon = CoverageUtilities.getRegionPolygon(inRaster);
SimpleFeatureCollection regionFC = FeatureUtilities.featureCollectionFromGeometry(inRaster.getCoordinateReferenceSystem(), regionPolygon);
OmsZonalStats zs = new OmsZonalStats();
zs.pm = new DummyProgressMonitor();
zs.inRaster = inRaster;
zs.inVector = regionFC;
zs.pPercentageThres = 0;
zs.process();
SimpleFeatureCollection outVector = zs.outVector;
List<SimpleFeature> testList = FeatureUtilities.featureCollectionToList(outVector);
SimpleFeature feature = testList.get(0);
if (stats == null) {
stats = new String[] { Variables.MIN, Variables.MAX, Variables.AVG, Variables.SDEV, Variables.VAR, Variables.SUM };
}
for (String statName : stats) {
Object attribute = feature.getAttribute(statName);
if (attribute != null) {
switch(statName) {
case Variables.MIN:
outMin = (Double) attribute;
break;
case Variables.MAX:
outMax = (Double) attribute;
break;
case Variables.AVG:
outMean = (Double) attribute;
break;
case Variables.SDEV:
outSdev = (Double) attribute;
break;
case Variables.SUM:
outSum = (Double) attribute;
break;
default:
break;
}
}
}
if (outMin != null && outMax != null) {
outRange = outMax - outMin;
}
if (!doHistogram)
return;
double[][] cb = new CoupledFieldsMoments().process(inRI, null, pBins, 1, 2, pm, 1);
int width = inRI.getWidth();
int height = inRI.getHeight();
int pixelsNum = width * height;
outCb = new double[cb.length + 1][3];
double sum = 0;
for (int i = 0; i < outCb.length; i++) {
if (i < outCb.length - 1) {
outCb[i][0] = cb[i][0];
outCb[i][1] = cb[i][1];
sum = sum + cb[i][1];
outCb[i][2] = cb[i][1] * 100.0 / pixelsNum;
} else {
outCb[i][0] = HMConstants.doubleNovalue;
double nans = pixelsNum - sum;
outCb[i][1] = nans;
outCb[i][2] = nans * 100.0 / pixelsNum;
}
}
}
use of org.hortonmachine.gears.libs.monitor.DummyProgressMonitor 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.libs.monitor.DummyProgressMonitor in project hortonmachine by TheHortonMachine.
the class GeometryUtilities method sortHorizontal.
public static void sortHorizontal(Coordinate[] coordinates) {
QuickSortAlgorithm sorter = new QuickSortAlgorithm(new DummyProgressMonitor());
double[] x = new double[coordinates.length];
double[] y = new double[coordinates.length];
for (int i = 0; i < x.length; i++) {
x[i] = coordinates[i].x;
y[i] = coordinates[i].y;
}
sorter.sort(x, y);
for (int i = 0; i < x.length; i++) {
coordinates[i].x = x[i];
coordinates[i].y = y[i];
}
}
use of org.hortonmachine.gears.libs.monitor.DummyProgressMonitor in project hortonmachine by TheHortonMachine.
the class HM method makeSldStyleForRaster.
public static void makeSldStyleForRaster(String tableName, String rasterPath, double opacity) throws Exception {
RasterSummary s = new RasterSummary();
s.pm = new DummyProgressMonitor();
s.inRaster = rasterPath;
s.process();
double min = s.outMin;
double max = s.outMax;
String style = RasterStyleUtilities.styleToString(RasterStyleUtilities.createStyleForColortable(tableName, min, max, opacity));
File styleFile = FileUtilities.substituteExtention(new File(rasterPath), "sld");
FileUtilities.writeFile(style, styleFile);
}
use of org.hortonmachine.gears.libs.monitor.DummyProgressMonitor in project hortonmachine by TheHortonMachine.
the class HM method makeQgisStyleForRaster.
public static void makeQgisStyleForRaster(String tableName, String rasterPath, int labelDecimals) throws Exception {
RasterSummary s = new RasterSummary();
s.pm = new DummyProgressMonitor();
s.inRaster = rasterPath;
s.process();
double min = s.outMin;
double max = s.outMax;
String style = RasterStyleUtilities.createQGISRasterStyle(tableName, min, max, null, labelDecimals);
File styleFile = FileUtilities.substituteExtention(new File(rasterPath), "qml");
FileUtilities.writeFile(style, styleFile);
}
Aggregations