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);
}
}
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);
}
}
}
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();
}
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());
}
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();
}
}
Aggregations