use of it.geosolutions.jaiext.range.Range in project sldeditor by robward-scisys.
the class JAIExtRangeValuesTest method testJAIExtRangeValues.
/**
* Test method for {@link
* com.sldeditor.rendertransformation.types.JAIExtRangeValues#JAIExtRangeValues()}.
*/
@Test
void testJAIExtRangeValues() {
JAIExtRangeValues testObj = new JAIExtRangeValues();
testObj.createInstance();
assertEquals(Arrays.asList(Range.class), testObj.getType());
Range range = RangeFactory.create(0.0, true, 50.0, true, false);
testObj.setDefaultValue(range);
assertNull(testObj.getExpression());
// Range value
testObj.setValue(range);
assertNull(testObj.getExpression());
// Literal expression
Expression expectedExpression = ff.literal(range);
testObj.setValue(expectedExpression);
assertEquals(expectedExpression, testObj.getExpression());
// Attribute expression
expectedExpression = ff.property("test");
testObj.setValue(expectedExpression);
assertEquals(expectedExpression, testObj.getExpression());
// Not set
testObj.setValue("");
assertNull(testObj.getExpression());
FieldConfigBase field = testObj.getField(new FieldConfigCommonData(JAIExtRangeValues.class, FieldIdEnum.INITIAL_GAP, "label", true, false, false));
assertEquals(FieldConfigRange.class, field.getClass());
// Increase code coverage
TestJAIExtRangeValues testObj2 = new TestJAIExtRangeValues();
testObj2.populateSymbolType(null);
}
use of it.geosolutions.jaiext.range.Range 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);
}
use of it.geosolutions.jaiext.range.Range in project geowave by locationtech.
the class WarpRIF method create.
/**
* Creates a new instance of warp operator according to the warp object and interpolation method.
*
* @param paramBlock The warp and interpolation objects.
*/
@Override
public RenderedImage create(final ParameterBlock paramBlock, final RenderingHints renderHints) {
final Interpolation interp = (Interpolation) paramBlock.getObjectParameter(1);
if ((interp instanceof InterpolationNearest) || (interp instanceof javax.media.jai.InterpolationNearest)) {
// Get ImageLayout from renderHints if any.
final ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
RenderedImage source = paramBlock.getRenderedSource(0);
final Warp warp = (Warp) paramBlock.getObjectParameter(0);
final double[] backgroundValues = (double[]) paramBlock.getObjectParameter(2);
ROI roi = null;
final Object roi_ = paramBlock.getObjectParameter(3);
if (roi_ instanceof ROI) {
roi = (ROI) roi_;
final PlanarImage temp = PlanarImage.wrapRenderedImage(source);
temp.setProperty("ROI", roi);
source = temp;
}
Range noData = (Range) paramBlock.getObjectParameter(4);
noData = RangeFactory.convert(noData, source.getSampleModel().getDataType());
return new WarpNearestOpImage(source, renderHints, layout, warp, interp, roi, noData, backgroundValues);
}
return super.create(paramBlock, renderHints);
}
Aggregations