@Test public void testDetermineTargetCellType() { assertDetermineTargetCellType(TYPE_1BIT, TYPE_1BIT, 0); assertDetermineTargetCellType(TYPE_1BIT, TYPE_8BIT_U, 2); assertDetermineTargetCellType(TYPE_1BIT, TYPE_8BIT_U, 0, 1, 2); assertDetermineTargetCellType(TYPE_4BIT, TYPE_4BIT, 0); assertDetermineTargetCellType(TYPE_4BIT, TYPE_4BIT, 15); assertDetermineTargetCellType(TYPE_4BIT, TYPE_8BIT_U, 16); assertDetermineTargetCellType(TYPE_8BIT_U, TYPE_8BIT_U, 0); assertDetermineTargetCellType(TYPE_8BIT_U, TYPE_8BIT_U, 255); assertDetermineTargetCellType(TYPE_8BIT_U, TYPE_16BIT_U, 256); assertDetermineTargetCellType(TYPE_8BIT_U, TYPE_16BIT_U, 0, 255, 256); assertDetermineTargetCellType(TYPE_8BIT_S, TYPE_8BIT_S, Byte.MIN_VALUE); assertDetermineTargetCellType(TYPE_8BIT_S, TYPE_8BIT_S, Byte.MAX_VALUE); assertDetermineTargetCellType(TYPE_8BIT_S, TYPE_16BIT_S, Byte.MAX_VALUE + 1); assertDetermineTargetCellType(TYPE_8BIT_S, TYPE_16BIT_S, 0, Byte.MIN_VALUE - 1, Byte.MAX_VALUE); assertDetermineTargetCellType(TYPE_16BIT_S, TYPE_16BIT_S, Short.MIN_VALUE); assertDetermineTargetCellType(TYPE_16BIT_S, TYPE_16BIT_S, Short.MAX_VALUE); assertDetermineTargetCellType(TYPE_16BIT_S, TYPE_32BIT_S, Short.MAX_VALUE + 1); assertDetermineTargetCellType(TYPE_16BIT_S, TYPE_32BIT_S, 0, Short.MIN_VALUE - 1, Short.MAX_VALUE); assertDetermineTargetCellType(TYPE_16BIT_U, TYPE_16BIT_U, 0); assertDetermineTargetCellType(TYPE_16BIT_U, TYPE_16BIT_U, 65535); assertDetermineTargetCellType(TYPE_16BIT_U, TYPE_32BIT_U, 65536); assertDetermineTargetCellType(TYPE_16BIT_U, TYPE_32BIT_U, 0, 65535, 65536); assertDetermineTargetCellType(TYPE_32BIT_U, TYPE_32BIT_U, 0); long max32bitU = TYPE_32BIT_U.getSampleValueRange().castTo(Long.class).getMaxValue(); assertDetermineTargetCellType(TYPE_32BIT_U, TYPE_32BIT_U, max32bitU); assertDetermineTargetCellType(TYPE_32BIT_U, TYPE_64BIT_REAL, max32bitU + 1); assertDetermineTargetCellType(TYPE_32BIT_U, TYPE_64BIT_REAL, 0, max32bitU, max32bitU + 1); assertDetermineTargetCellType(TYPE_32BIT_S, TYPE_32BIT_S, Integer.MIN_VALUE); assertDetermineTargetCellType(TYPE_32BIT_S, TYPE_32BIT_S, Integer.MAX_VALUE); assertDetermineTargetCellType(TYPE_32BIT_S, TYPE_64BIT_REAL, (long) Integer.MIN_VALUE - 1L); assertDetermineTargetCellType(TYPE_32BIT_S, TYPE_64BIT_REAL, Integer.MIN_VALUE, (long) Integer.MAX_VALUE + 1L, (long) Integer.MIN_VALUE - 1L); { try { assertDetermineTargetCellType(TYPE_32BIT_REAL, TYPE_32BIT_REAL, Float.MIN_VALUE); fail("Expected IAE for 332BIT_REAL with no-data other than Float.NaN"); } catch (IllegalArgumentException e) { assertTrue(true); } try { assertDetermineTargetCellType(TYPE_32BIT_REAL, TYPE_32BIT_REAL, Float.MAX_VALUE); fail("Expected IAE for 332BIT_REAL with no-data other than Float.NaN"); } catch (IllegalArgumentException e) { assertTrue(true); } assertDetermineTargetCellType(TYPE_32BIT_REAL, TYPE_32BIT_REAL, Float.NaN); } { try { assertDetermineTargetCellType(TYPE_64BIT_REAL, TYPE_64BIT_REAL, Double.MIN_VALUE); fail("Expected IAE for TYPE_64BIT_REAL with no-data other than Float.NaN"); } catch (IllegalArgumentException e) { assertTrue(true); } try { assertDetermineTargetCellType(TYPE_64BIT_REAL, TYPE_64BIT_REAL, Double.MAX_VALUE); fail("Expected IAE for TYPE_64BIT_REAL with no-data other than Float.NaN"); } catch (IllegalArgumentException e) { assertTrue(true); } assertDetermineTargetCellType(TYPE_64BIT_REAL, TYPE_64BIT_REAL, Double.NaN); } }
public static RasterCellType determineTargetCellType(final RasterCellType nativeCellType, final List<Number> noDataValues) { if (TYPE_32BIT_REAL == nativeCellType || TYPE_64BIT_REAL == nativeCellType) { for (Number nodata : noDataValues) { if (!Double.isNaN(nodata.doubleValue())) { throw new IllegalArgumentException("no data values for float and " + "double cell types shall be NaN: " + nodata); } } return nativeCellType; } double noDataMin = Double.POSITIVE_INFINITY, noDataMax = Double.NEGATIVE_INFINITY; { for (Number noData : noDataValues) { noDataMin = Math.min(noDataMin, noData.doubleValue()); noDataMax = Math.max(noDataMax, noData.doubleValue()); } } final NumberRange<Double> sampleValueRange; sampleValueRange = nativeCellType.getSampleValueRange().castTo(Double.class); final RasterCellType targetCellType; if (sampleValueRange.contains((Number) Double.valueOf(noDataMin)) && sampleValueRange.contains((Number) Double.valueOf(noDataMax))) { targetCellType = nativeCellType; } else { targetCellType = promote(nativeCellType); } return targetCellType; }
RasterUtils { public static RasterCellType determineTargetCellType(final RasterCellType nativeCellType, final List<Number> noDataValues) { if (TYPE_32BIT_REAL == nativeCellType || TYPE_64BIT_REAL == nativeCellType) { for (Number nodata : noDataValues) { if (!Double.isNaN(nodata.doubleValue())) { throw new IllegalArgumentException("no data values for float and " + "double cell types shall be NaN: " + nodata); } } return nativeCellType; } double noDataMin = Double.POSITIVE_INFINITY, noDataMax = Double.NEGATIVE_INFINITY; { for (Number noData : noDataValues) { noDataMin = Math.min(noDataMin, noData.doubleValue()); noDataMax = Math.max(noDataMax, noData.doubleValue()); } } final NumberRange<Double> sampleValueRange; sampleValueRange = nativeCellType.getSampleValueRange().castTo(Double.class); final RasterCellType targetCellType; if (sampleValueRange.contains((Number) Double.valueOf(noDataMin)) && sampleValueRange.contains((Number) Double.valueOf(noDataMax))) { targetCellType = nativeCellType; } else { targetCellType = promote(nativeCellType); } return targetCellType; } }
RasterUtils { public static RasterCellType determineTargetCellType(final RasterCellType nativeCellType, final List<Number> noDataValues) { if (TYPE_32BIT_REAL == nativeCellType || TYPE_64BIT_REAL == nativeCellType) { for (Number nodata : noDataValues) { if (!Double.isNaN(nodata.doubleValue())) { throw new IllegalArgumentException("no data values for float and " + "double cell types shall be NaN: " + nodata); } } return nativeCellType; } double noDataMin = Double.POSITIVE_INFINITY, noDataMax = Double.NEGATIVE_INFINITY; { for (Number noData : noDataValues) { noDataMin = Math.min(noDataMin, noData.doubleValue()); noDataMax = Math.max(noDataMax, noData.doubleValue()); } } final NumberRange<Double> sampleValueRange; sampleValueRange = nativeCellType.getSampleValueRange().castTo(Double.class); final RasterCellType targetCellType; if (sampleValueRange.contains((Number) Double.valueOf(noDataMin)) && sampleValueRange.contains((Number) Double.valueOf(noDataMax))) { targetCellType = nativeCellType; } else { targetCellType = promote(nativeCellType); } return targetCellType; } private  RasterUtils(); }
RasterUtils { public static RasterCellType determineTargetCellType(final RasterCellType nativeCellType, final List<Number> noDataValues) { if (TYPE_32BIT_REAL == nativeCellType || TYPE_64BIT_REAL == nativeCellType) { for (Number nodata : noDataValues) { if (!Double.isNaN(nodata.doubleValue())) { throw new IllegalArgumentException("no data values for float and " + "double cell types shall be NaN: " + nodata); } } return nativeCellType; } double noDataMin = Double.POSITIVE_INFINITY, noDataMax = Double.NEGATIVE_INFINITY; { for (Number noData : noDataValues) { noDataMin = Math.min(noDataMin, noData.doubleValue()); noDataMax = Math.max(noDataMax, noData.doubleValue()); } } final NumberRange<Double> sampleValueRange; sampleValueRange = nativeCellType.getSampleValueRange().castTo(Double.class); final RasterCellType targetCellType; if (sampleValueRange.contains((Number) Double.valueOf(noDataMin)) && sampleValueRange.contains((Number) Double.valueOf(noDataMax))) { targetCellType = nativeCellType; } else { targetCellType = promote(nativeCellType); } return targetCellType; } private  RasterUtils(); static IndexColorModel sdeColorMapToJavaColorModel(final DataBuffer colorMapData,
            final int bitsPerSample); static ImageTypeSpecifier createFullImageTypeSpecifier(
            final RasterDatasetInfo rasterInfo, final int rasterIndex); static GridEnvelope setMosaicLocations(final RasterDatasetInfo rasterInfo,
            final List<RasterQueryInfo> results); static RasterQueryInfo findLowestResolution(List<RasterQueryInfo> results); static List<RasterQueryInfo> findMatchingRasters(final RasterDatasetInfo rasterInfo,
            final GeneralEnvelope requestedEnvelope, final GridEnvelope requestedDim,
            final OverviewPolicy overviewPolicy); static void fitRequestToRaster(final GeneralEnvelope requestedEnvelope,
            final RasterDatasetInfo rasterInfo, final RasterQueryInfo query); static IndexColorModel ensureNoDataPixelIsAvailable(final IndexColorModel colorMap); static Number determineNoDataValue(IndexColorModel colorMap); static Number determineNoDataValue(final int numBands, final double statsMin,
            final double statsMax, final RasterCellType nativeCellType); static boolean isGeoPhysics(final int numBands, final RasterCellType nativeCellType); static RasterCellType determineTargetCellType(final RasterCellType nativeCellType,
            final List<Number> noDataValues); }
RasterUtils { public static RasterCellType determineTargetCellType(final RasterCellType nativeCellType, final List<Number> noDataValues) { if (TYPE_32BIT_REAL == nativeCellType || TYPE_64BIT_REAL == nativeCellType) { for (Number nodata : noDataValues) { if (!Double.isNaN(nodata.doubleValue())) { throw new IllegalArgumentException("no data values for float and " + "double cell types shall be NaN: " + nodata); } } return nativeCellType; } double noDataMin = Double.POSITIVE_INFINITY, noDataMax = Double.NEGATIVE_INFINITY; { for (Number noData : noDataValues) { noDataMin = Math.min(noDataMin, noData.doubleValue()); noDataMax = Math.max(noDataMax, noData.doubleValue()); } } final NumberRange<Double> sampleValueRange; sampleValueRange = nativeCellType.getSampleValueRange().castTo(Double.class); final RasterCellType targetCellType; if (sampleValueRange.contains((Number) Double.valueOf(noDataMin)) && sampleValueRange.contains((Number) Double.valueOf(noDataMax))) { targetCellType = nativeCellType; } else { targetCellType = promote(nativeCellType); } return targetCellType; } private  RasterUtils(); static IndexColorModel sdeColorMapToJavaColorModel(final DataBuffer colorMapData,
            final int bitsPerSample); static ImageTypeSpecifier createFullImageTypeSpecifier(
            final RasterDatasetInfo rasterInfo, final int rasterIndex); static GridEnvelope setMosaicLocations(final RasterDatasetInfo rasterInfo,
            final List<RasterQueryInfo> results); static RasterQueryInfo findLowestResolution(List<RasterQueryInfo> results); static List<RasterQueryInfo> findMatchingRasters(final RasterDatasetInfo rasterInfo,
            final GeneralEnvelope requestedEnvelope, final GridEnvelope requestedDim,
            final OverviewPolicy overviewPolicy); static void fitRequestToRaster(final GeneralEnvelope requestedEnvelope,
            final RasterDatasetInfo rasterInfo, final RasterQueryInfo query); static IndexColorModel ensureNoDataPixelIsAvailable(final IndexColorModel colorMap); static Number determineNoDataValue(IndexColorModel colorMap); static Number determineNoDataValue(final int numBands, final double statsMin,
            final double statsMax, final RasterCellType nativeCellType); static boolean isGeoPhysics(final int numBands, final RasterCellType nativeCellType); static RasterCellType determineTargetCellType(final RasterCellType nativeCellType,
            final List<Number> noDataValues);  }