public static RangeLookupTable getRangeLookupTable( List<Range> classificationRanges, final int[] outputPixelValues, final Number noDataValue, final Class<? extends Number> clazz) { final RangeLookupTable.Builder rltBuilder = new RangeLookupTable.Builder(); final int size = classificationRanges.size(); final boolean useCustomOutputPixelValues = outputPixelValues != null && outputPixelValues.length == size; Class<? extends Number> widestClass = noDataValue.getClass(); for (int i = 0; i < size; i++) { final Range range = classificationRanges.get(i); final Class<? extends Number> rangeClass = range.getMin().getClass(); if (widestClass != rangeClass) { widestClass = ClassChanger.getWidestClass(widestClass, rangeClass); } final int reference = useCustomOutputPixelValues ? outputPixelValues[i] : i + 1; rltBuilder.add(range, convert(reference, noDataValue.getClass())); } // Add the largest range that contains the no data value rltBuilder.add( new Range(getClassMinimum(widestClass), true, getClassMaximum(widestClass), true), noDataValue); return rltBuilder.build(); }
/** * Creates a Range instance that is a point (degenerate) interval. If value * is null, for a point at infinity, the inf argument must be * provided and be one of Range.INF or Range.NEG_INF. * * @param <T> value type * @param value the value to set for both min and max end-points * @param inf either Range.INF or Range.NEG_INF (ignored if value is non-null) * @return the new instance */ public static <T extends Number & Comparable> Range<T> create(T value, int... inf) { return new Range<T>(value, inf); }
/** * {@inheritDoc} */ public void addRange(Range<Double> range) { if (range != null) { if (this.rangesType == Range.Type.UNDEFINED) { this.rangesType = Range.Type.EXCLUDE; } // copy the input Range defensively ranges.add(new Range<Double>(range)); } }
/** * {@inheritDoc} */ public void addNoDataRange(Range<Double> noData) { if (noData != null) { // copy the input Range defensively noDataRanges.add(new Range<Double>(noData)); } }
public static Map<Range,Double> rgb8Ranges() { Map<Range,Double> ranges = new HashMap<>(); ranges.put(new Range( 0, true, 85, false), 42.); ranges.put(new Range( 85, true, 170, false), 127.); ranges.put(new Range(170, true, 255, true), 212.); // test tiff: 699*929 = 649371 pixels // 3 ranges above reduce number of features from 565952 to 50781 compared to not using ranges, but still... // both take several minutes return ranges; }
return new Range<T>(minValue, minIncluded, maxValue, maxIncluded);
/** * {@inheritDoc} */ public void addNoDataValue(Double noData) { if (noData != null && !noData.isNaN()) { noDataRanges.add(new Range<Double>(noData)); } }
public static Map<Range,Double> ndviRanges() { Map<Range,Double> ranges = new HashMap<>(); // ranges use scaled int values (assume 10^3 for NDVI) from coverage, // the TZNs need unscaled values: ranges.put(new Range( 0, true, 50, false), 0.0); ranges.put(new Range( 50, true, 150, false), 0.1); ranges.put(new Range(150, true, 250, false), 0.2); ranges.put(new Range(250, true, 350, false), 0.3); ranges.put(new Range(350, true, 450, false), 0.4); ranges.put(new Range(450, true, 550, false), 0.5); ranges.put(new Range(550, true, 650, false), 0.6); ranges.put(new Range(650, true, 800, false), 0.7); ranges.put(new Range(750, true, 850, false), 0.8); ranges.put(new Range(850, true, 950, false), 0.9); ranges.put(new Range(950, true, 1000, true), 1.0); return ranges; }
/** * {@inheritDoc} */ public void addRange(Range<Double> range, Range.Type rangesType) { if (range != null) { if (this.rangesType == Range.Type.UNDEFINED) { this.rangesType = rangesType; } else { if (this.rangesType != rangesType) { throw new IllegalArgumentException("The provided rangesType is not compatible with the processors rangesType"); } } // copy the input Range defensively ranges.add(new Range<Double>(range)); } }
new Range<Double>(min, true, max, true); novalueRangeList = new ArrayList<Range<Double>>(); novalueRangeList.add(novalueRange);
/** * Adds a single value to be considered as NoData. * * @param noData the value to be treated as NoData * * @see #addNoDataRange(Range) */ public void addNoDataValue(Double noData) { if (noData != null && !noData.isNaN()) { addNoDataRange(new Range<Double>(noData)); } }
/** * Adds a range of values to be considered as NoData and then to be excluded * from the calculation of <b>all</b> statistics. NoData ranges take precedence * over included / excluded data ranges. * * @param noData the range defining NoData values */ public void addNoDataRange(Range<Double> noData) { noDataRanges.add(new Range<Double>(noData)); for (Processor p : processors) { p.addNoDataRange(noData); } }
/** * Adds a range of values to include in or exclude from the calculation * of <b>all</b> statistics. If further statistics are set after calling * this method the range will be applied to them as well. * * @param range the range to include/exclude */ public void addRange(Range<Double> range) { ranges.add(new Range<Double>(range)); for (Processor p : processors) { p.addRange(range); } }
/** * Adds a range of values to include in or exclude from the calculation * of <b>all</b> statistics. If further statistics are set after calling * this method the range will be applied to them as well. * * @param range the range to include/exclude * @param rangesType one of {@link Range.Type#INCLUDE} or {@link Range.Type#EXCLUDE} */ public void addRange(Range<Double> range, Range.Type rangesType) { for (Processor p : processors) { p.addRange(range, rangesType); } ranges.add(new Range<Double>(range)); }
} else { Range<Double> noData = new Range<Double>( catRange.getMinimum(), catRange.isMinIncluded(),
/** * Return the parsed Range. * * @param sRange */ static Range<Double> parseRangeInternal(Matcher m, String sRange) { Double min = null; Double max = null; if (m.groupCount() != 4) { throw new IllegalStateException( "Range returned wrong group count (" + sRange + ") : " + m.groupCount()); } if (m.group(2) != null) { min = new Double(m.group(2)); } if (m.group(3) != null) { max = new Double(m.group(3)); } boolean inclmin; if (m.group(1).equals("(")) inclmin = false; else if (m.group(1).equals("[")) inclmin = true; else throw new IllegalArgumentException("Bad min delimiter (" + sRange + ")"); boolean inclmax; if (m.group(4).equals(")")) inclmax = false; else if (m.group(4).equals("]")) inclmax = true; else throw new IllegalArgumentException("Bad max delimiter (" + sRange + ")"); if (min != null && max != null && min > max) throw new IllegalArgumentException("Bad min/max relation (" + sRange + ")"); return new Range<Double>(min, inclmin, max, inclmax); }
/** * Creates the complement of a {@code Range}. This is equivalent to subtracting the * input from the infinite interval. * <p> * If the input is a finite interval or point, the result will be a list of * two {@code Ranges}. For example: the complement of [-5, 5) is made up of * (-Inf, -5) and [5, Inf). * <p> * If the input is an interval open at one end, the result list will contain * a single {@code Range}. For example: the complement of (-Inf, 5) is [5, Inf). * <p> * If the input is a point at positive or negative infinity its complement is, * by convention, (-Inf, Inf). * <p> * If the input is the infinite interval (-Inf, Inf) the result list will be * empty. * * @param <T> the value type * @param range input range * * @return a list of 0, 1 or 2 {@code Ranges} which form the complement * * @see #createComplement(java.util.Collection) */ public static <T extends Number & Comparable> List<Range<T>> createComplement(Range<T> range) { return subtract(range, new Range<T>(null, false, null, false)); }
throw new IllegalArgumentException("Bad min/max relation ("+sRange+")"); return new Range<Double>(min, inclmin, max, inclmax);
public static RangeLookupTable getRangeLookupTable(List<Range> classificationRanges, final int[] outputPixelValues, final Number noDataValue, final Class<? extends Number> clazz) { final RangeLookupTable.Builder rltBuilder = new RangeLookupTable.Builder(); final int size = classificationRanges.size(); final boolean useCustomOutputPixelValues = outputPixelValues != null && outputPixelValues.length == size; Class<? extends Number> widestClass = noDataValue.getClass(); for (int i = 0; i < size; i++) { final Range range = classificationRanges.get(i); final Class<? extends Number> rangeClass = range.getMin().getClass(); if (widestClass != rangeClass) { widestClass = ClassChanger.getWidestClass(widestClass, rangeClass); } final int reference = useCustomOutputPixelValues ? outputPixelValues [i] : i + 1; rltBuilder.add(range, convert(reference, noDataValue.getClass())); } // Add the largest range that contains the no data value rltBuilder.add(new Range(getClassMinimum(widestClass), true, getClassMaximum(widestClass), true), noDataValue); return rltBuilder.build(); }