use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class CoverageUtilities method doProfile.
/**
* Calculates the profile of a raster map between given {@link Coordinate coordinates}.
*
* @param coverage the coverage from which to extract the profile.
* @param coordinates the coordinates to use to trace the profile.
* @return the list of {@link ProfilePoint}s.
* @throws Exception
*/
public static List<ProfilePoint> doProfile(GridCoverage2D coverage, Coordinate... coordinates) throws Exception {
GridGeometry2D gridGeometry = coverage.getGridGeometry();
RenderedImage renderedImage = coverage.getRenderedImage();
RandomIter iter = RandomIterFactory.create(renderedImage, null);
List<ProfilePoint> profilePointsList = doProfile(iter, gridGeometry, coordinates);
iter.done();
return profilePointsList;
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class CoverageUtilities method renderedImage2DoubleArray.
/**
* Transform a rendered image in its array representation.
*
* @param renderedImage the rendered image to transform.
* @param bandNumber the the number of the band to consider..
* @return the array holding the data.
*/
public static double[] renderedImage2DoubleArray(RenderedImage renderedImage, int bandNumber) {
int width = renderedImage.getWidth();
int height = renderedImage.getHeight();
double[] values = new double[width * height];
RandomIter imageIter = RandomIterFactory.create(renderedImage, null);
int index = 0;
;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
double sample = imageIter.getSampleDouble(x, y, bandNumber);
values[index++] = sample;
}
}
imageIter.done();
return values;
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class CoverageUtilities method sumCoverages.
public static GridCoverage2D sumCoverages(GridCoverage2D gc1, GridCoverage2D gc2) {
RegionMap gc1RegionMap = getRegionParamsFromGridCoverage(gc1);
int c1 = gc1RegionMap.getCols();
int r1 = gc1RegionMap.getRows();
RegionMap gc2RegionMap = getRegionParamsFromGridCoverage(gc2);
int c2 = gc2RegionMap.getCols();
int r2 = gc2RegionMap.getRows();
if (c1 != c2 || r1 != r2) {
throw new IllegalArgumentException("The raster maps have to be of equal size to be mapped.");
}
RandomIter gc1Iter = RandomIterFactory.create(gc1.getRenderedImage(), null);
WritableRaster outWR = renderedImage2WritableRaster(gc2.getRenderedImage(), false);
WritableRandomIter gc2Iter = RandomIterFactory.createWritable(outWR, null);
double nv1 = HMConstants.getNovalue(gc1);
for (int r = 0; r < r1; r++) {
for (int c = 0; c < c1; c++) {
double v1 = gc1Iter.getSampleDouble(c, r, 0);
double v2 = gc2Iter.getSampleDouble(c, r, 0);
if (!HMConstants.isNovalue(v1, nv1)) {
double newV = v1 + v2;
gc2Iter.setSample(c, r, 0, newV);
}
}
}
GridCoverage2D outCoverage = buildCoverage("merged", outWR, gc2RegionMap, gc1.getCoordinateReferenceSystem());
return outCoverage;
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class CoverageUtilities method getRandomIterator.
/**
* Creates a {@link RandomIter} for the given {@link GridCoverage2D}.
*
* <p>It is important to use this method since it supports also
* large GRASS rasters.
*
* @param coverage the coverage on which to wrap a {@link RandomIter}.
* @return the iterator.
*/
public static RandomIter getRandomIterator(GridCoverage2D coverage) {
// if (coverage instanceof GrassLegacyGridCoverage2D) {
// GrassLegacyGridCoverage2D grassGC = (GrassLegacyGridCoverage2D) coverage;
// GrassLegacyRandomIter iter = new GrassLegacyRandomIter(grassGC.getData());
// return iter;
// }
RenderedImage renderedImage = coverage.getRenderedImage();
RandomIter iter = RandomIterFactory.create(renderedImage, null);
return iter;
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsVectorizer method maskRaster.
private GridCoverage2D maskRaster() {
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
int nCols = regionMap.getCols();
int nRows = regionMap.getRows();
RandomIter rasterIter = CoverageUtilities.getRandomIterator(inRaster);
WritableRaster[] holder = new WritableRaster[1];
GridCoverage2D outGC = CoverageUtilities.createCoverageFromTemplate(inRaster, novalue, holder);
WritableRandomIter outIter = RandomIterFactory.createWritable(holder[0], null);
pm.beginTask("Masking map...", nRows);
for (int r = 0; r < nRows; r++) {
for (int c = 0; c < nCols; c++) {
double value = rasterIter.getSampleDouble(c, r, 0);
boolean doNull = false;
if (!isNovalue(value, novalue)) {
if (!Double.isNaN(pMaskThreshold)) {
// check threshold
if (value < pMaskThreshold) {
doNull = true;
} else {
doNull = false;
}
}
} else {
doNull = true;
}
if (!doNull)
outIter.setSample(c, r, 0, 1);
}
pm.worked(1);
}
pm.done();
return outGC;
}
Aggregations