Search in sources :

Example 1 with Range

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);
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) JAIExtRangeValues(com.sldeditor.rendertransformation.types.JAIExtRangeValues) Range(it.geosolutions.jaiext.range.Range) FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) Test(org.junit.jupiter.api.Test)

Example 2 with Range

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);
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) Rectangle(java.awt.Rectangle) Range(it.geosolutions.jaiext.range.Range) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) RangeLookupTable(it.geosolutions.jaiext.rlookup.RangeLookupTable) ROIShape(javax.media.jai.ROIShape) RenderedImage(java.awt.image.RenderedImage) Execute(oms3.annotations.Execute)

Example 3 with Range

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);
}
Also used : Interpolation(javax.media.jai.Interpolation) Warp(javax.media.jai.Warp) InterpolationNearest(it.geosolutions.jaiext.interpolators.InterpolationNearest) RenderedImage(java.awt.image.RenderedImage) Range(it.geosolutions.jaiext.range.Range) ImageLayout(javax.media.jai.ImageLayout) ROI(javax.media.jai.ROI) PlanarImage(javax.media.jai.PlanarImage)

Aggregations

Range (it.geosolutions.jaiext.range.Range)3 RenderedImage (java.awt.image.RenderedImage)2 JAIExtRangeValues (com.sldeditor.rendertransformation.types.JAIExtRangeValues)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 FieldConfigRange (com.sldeditor.ui.detail.config.FieldConfigRange)1 InterpolationNearest (it.geosolutions.jaiext.interpolators.InterpolationNearest)1 RangeLookupTable (it.geosolutions.jaiext.rlookup.RangeLookupTable)1 Rectangle (java.awt.Rectangle)1 ImageLayout (javax.media.jai.ImageLayout)1 Interpolation (javax.media.jai.Interpolation)1 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)1 PlanarImage (javax.media.jai.PlanarImage)1 ROI (javax.media.jai.ROI)1 ROIShape (javax.media.jai.ROIShape)1 Warp (javax.media.jai.Warp)1 Execute (oms3.annotations.Execute)1 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)1 Test (org.junit.jupiter.api.Test)1 Expression (org.opengis.filter.expression.Expression)1