use of javax.media.jai.ROIShape in project hortonmachine by TheHortonMachine.
the class CoverageUtilities method prepareROI.
/**
* Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation.
*
* @param roi a {@link Geometry} in model space.
* @param mt2d an {@link AffineTransform} that maps from raster to model space. This is already referred to the pixel corner.
* @return a {@link ROI} suitable for using with JAI.
* @throws ProcessException in case there are problems with ivnerting the provided {@link AffineTransform}. Very unlikely to happen.
*/
public static ROI prepareROI(Geometry roi, AffineTransform mt2d) throws Exception {
// transform the geometry to raster space so that we can use it as a ROI source
Geometry rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse()));
// simplify the geometry so that it's as precise as the coverage, excess coordinates
// just make it slower to determine the point in polygon relationship
Geometry simplifiedGeometry = DouglasPeuckerSimplifier.simplify(rasterSpaceGeometry, 1);
// build a shape using a fast point in polygon wrapper
return new ROIShape(new FastLiteShape(simplifiedGeometry));
}
use of javax.media.jai.ROIShape in project hortonmachine by TheHortonMachine.
the class OmsRangeLookup method process.
@SuppressWarnings("nls")
@Execute
public void process() throws Exception {
if (!concatOr(outRaster == null, doReset)) {
return;
}
// FIXME remove when the jaitools rangelookup is not pulled fro
JAIExt.initJAIEXT(true);
// raster process anymore
checkNull(inRaster, pRanges, pClasses);
double novalue = HMConstants.getNovalue(inRaster);
RenderedImage inRI = inRaster.getRenderedImage();
RangeLookupTable.Builder<Double, Double> builder = new RangeLookupTable.Builder<Double, Double>();
String[] rangesSplit = pRanges.trim().split(",");
String[] classesSplit = pClasses.trim().split(",");
if (rangesSplit.length != classesSplit.length) {
throw new ModelsIllegalargumentException("Ranges and classes must be in pairs!", this, pm);
}
for (int i = 0; i < rangesSplit.length; i++) {
String classStr = classesSplit[i].trim();
double classNum = Double.parseDouble(classStr);
String range = rangesSplit[i].trim();
boolean minIncluded = false;
boolean maxIncluded = false;
if (range.startsWith("[")) {
minIncluded = true;
}
if (range.endsWith("]")) {
maxIncluded = true;
}
String rangeNoBrac = range.replaceAll("\\[|\\]|\\(|\\)", "");
String[] split = rangeNoBrac.trim().split("\\s+");
Double min = null;
try {
if (split[0].equals("null")) {
min = Double.NEGATIVE_INFINITY;
} else {
min = Double.parseDouble(split[0]);
}
} catch (Exception e) {
// can be null
}
Double max = null;
try {
if (split[1].equals("null")) {
max = Double.POSITIVE_INFINITY;
} else {
max = Double.parseDouble(split[1]);
}
} catch (Exception e) {
// can be null
}
Range r = RangeFactory.create(min, minIncluded, max, maxIncluded);
builder.add(r, classNum);
}
// List<org.jaitools.numeric.Range> ranges;
// new RangeLookupProcess().execute(inRaster, 0, ranges, null);
RangeLookupTable<Double, Double> table = builder.build();
ROIShape roi = new ROIShape(new Rectangle(0, 0, inRI.getWidth(), inRI.getHeight()));
ParameterBlockJAI pb = new ParameterBlockJAI("RLookup");
pb.setSource("source0", inRI);
pb.setParameter("table", table);
pb.setParameter("roi", roi);
pb.setParameter("default", (Double) novalue);
RenderedImage lookupImg = JAI.create("RLookup", pb);
HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
outRaster = CoverageUtilities.buildCoverageWithNovalue("rangelookup", lookupImg, regionMap, inRaster.getCoordinateReferenceSystem(), novalue);
}
Aggregations