This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 49463335c673b2493669ba89e62fa775b91f8a96 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Thu Oct 14 11:16:20 2021 +0200 If `GDAL_NODATA` value is 0, declare the background value explicitely anyway. --- .../main/java/org/apache/sis/coverage/CategoryList.java | 4 ++-- .../main/java/org/apache/sis/coverage/package-info.java | 2 +- .../org/apache/sis/internal/geotiff/SchemaModifier.java | 13 +++---------- .../apache/sis/storage/geotiff/ImageFileDirectory.java | 16 +++++++++++++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java index 60586ad..0536fb6 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java @@ -69,7 +69,7 @@ import static java.lang.Double.doubleToRawLongBits; * <p>Instances of {@link CategoryList} are immutable and thread-safe.</p> * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.0 * @module */ @@ -346,7 +346,7 @@ final class CategoryList extends AbstractList<Category> implements MathTransform * This check is important for "unit to sample" conversions, because we typically expect all * results to be convertible to integers (ignoring rounding errors). */ - if (converse.categories.length != 0) { + if (background == null && converse.categories.length != 0) { final NumberRange<?> cr = converse.categories[0].range; final double cv = cr.getMinDouble(); if ((cv > 0) || (cv == 0 && !cr.isMinIncluded())) { diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/package-info.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/package-info.java index 2b67959..3f34ae4 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/package-info.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/package-info.java @@ -23,7 +23,7 @@ * {@link org.apache.sis.coverage.grid}. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.0 * @module */ diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/SchemaModifier.java b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/SchemaModifier.java index ed21c4b..781defc 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/SchemaModifier.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/SchemaModifier.java @@ -74,20 +74,13 @@ public interface SchemaModifier { * Implementations can override this method for setting a better name or for declaring the * meaning of sample values (by adding "categories"). * - * <div class="note"><b>API note:</b> - * the zero fill value is excluded because tiles are already initialized to zero by default, - * and because conversions between "real world" values and "packaged values" already use 0 - * as the background value if no category is specified. We avoid specifying categories when - * not necessary because GeoTIFF does not really has this information. - * </div> - * - * The default implementation creates categories only if {@code fillValue} is non-null. - * In such case, the fill value is also defined as the background value. + * <p>The default implementation creates categories only if {@code fillValue} is non-null. + * In such case, the fill value is also defined as the background value.</p> * * @param image index of the image for which to create sample dimension. * @param band index of the band for which to create sample dimension. * @param sampleRange minimum and maximum values declared in the TIFF tags, or {@code null} if unknown. - * @param fillValue the "no data" value, or {@code null} if none or zero. May intersect {@code sampleRange}. + * @param fillValue the "no data" value, or {@code null} if none. May intersect {@code sampleRange}. * @param dimension a sample dimension builder initialized with band number as the dimension name. * This builder can be modified in-place. * @return the sample dimension to use. diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java index 0cc2f23..480dc73 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java @@ -353,7 +353,7 @@ final class ImageFileDirectory extends DataCube { /** * The "no data" or background pixel value, or NaN if undefined. * - * @see #getFillValue() + * @see #getFillValue(boolean) */ private double noData = Double.NaN; @@ -1456,7 +1456,7 @@ final class ImageFileDirectory extends DataCube { maxValues.get(Math.min(band, maxValues.size()-1)), true); } dimensions[band] = reader.store.customizer.customize(index, band, - sampleRange, getFillValue(), builder.setName(++band)); + sampleRange, getFillValue(true), builder.setName(++band)); builder.clear(); } sampleDimensions = UnmodifiableArrayList.wrap(dimensions); @@ -1636,6 +1636,16 @@ final class ImageFileDirectory extends DataCube { */ @Override protected Number getFillValue() { + return getFillValue(false); + } + + /** + * Returns the value to use for filling empty spaces in the raster, or {@code null} if none, + * The exclusion of zero value is optional, controlled by the {@code acceptZero} argument. + * + * @param acceptZero whether to return a number for the zero value. + */ + private Number getFillValue(final boolean acceptZero) { if (Double.isFinite(noData) && noData != 0) { final long min, max; switch (sampleFormat) { @@ -1644,7 +1654,7 @@ final class ImageFileDirectory extends DataCube { default: return noData; } final long value = Math.round(noData); - if (value >= min && value <= max && value != 0) { + if (value >= min && value <= max && (acceptZero || value != 0)) { return Numbers.narrowestNumber(value); } }