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 8ba529bda9778ceb9a5e68be67739015a2a2734a
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jul 28 14:20:04 2020 +0200
Declare the "Errors_DN" category in GCOM-C files as a legal fill value.
---
.../org/apache/sis/internal/earth/netcdf/GCOM_C.java | 19 ++++++++++++++-----
.../org/apache/sis/internal/earth/netcdf/GCOM_W.java | 2 +-
.../org/apache/sis/internal/netcdf/Convention.java | 20 ++++++++++++++++----
.../apache/sis/internal/netcdf/RasterResource.java | 4 ++--
4 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
index 9796ffe..8afc9c6 100644
--- a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
+++ b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
@@ -156,9 +156,11 @@ public final class GCOM_C extends Convention {
/**
* Names of attributes for sample values having "no-data" meaning.
* All those names have {@value #SUFFIX} suffix.
+ *
+ * @see #nodataValues(Variable)
*/
private static final String[] NO_DATA = {
- "Error_DN",
+ "Error_DN", // Must be first: will be used as "no
data" value.
"Land_DN",
"Cloud_error_DN",
"Retrieval_error_DN"
@@ -459,13 +461,20 @@ public final class GCOM_C extends Convention {
@Override
public Map<Number,Object> nodataValues(final Variable data) {
final Map<Number, Object> pads = super.nodataValues(data);
- for (String name : NO_DATA) {
+ for (int i=0; i<NO_DATA.length; i++) {
+ String name = NO_DATA[i];
final double value = data.getAttributeAsNumber(name);
if (Double.isFinite(value)) {
- if (name.endsWith(SUFFIX)) {
- name = name.substring(0, name.length() - SUFFIX.length());
+ final Object label;
+ if (i != 0) {
+ if (name.endsWith(SUFFIX)) {
+ name = name.substring(0, name.length() - SUFFIX.length());
+ }
+ label = name.replace('_', ' ');
+ } else {
+ label = FILL_VALUE_MASK | MISSING_VALUE_MASK;
}
- pads.put(value, name.replace('_', ' '));
+ pads.put(value, label);
}
}
return pads;
diff --git a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
index 3672708..b249a2e 100644
--- a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
+++ b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
@@ -206,7 +206,7 @@ public final class GCOM_W extends Convention {
public Map<Number,Object> nodataValues(final Variable data) {
final Map<Number, Object> pads = super.nodataValues(data);
if (pads.isEmpty() && roleOf(data) == VariableRole.COVERAGE) {
- pads.put(NO_DATA, 3);
+ pads.put(NO_DATA, FILL_VALUE_MASK | MISSING_VALUE_MASK);
/*
* Value 3 stands for:
* - bit 0 set: NO_DATA is a pad value (can be used as background).
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
index 9208d35..d7c3973 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
@@ -108,11 +108,23 @@ public class Convention {
* map returned by {@link #nodataValues(Variable)}. The main bit is bit #0, which identifies
the background value.
*/
private static final String[] NODATA_ATTRIBUTES = {
- CDM.FILL_VALUE,
- CDM.MISSING_VALUE
+ CDM.FILL_VALUE, // Must be at index i=0 in order to get (1 << i) ==
PAD_VALUE_MASK.
+ CDM.MISSING_VALUE // Must be at index i=1 in order to get (1 << i) ==
MISSING_VALUE_MASK.
};
/**
+ * Mask for pad values in the bits returned by {@link #nodataValues(Variable)}.
+ * The difference with {@link #MISSING_VALUE_MASK} is that pad values may be used as
background
+ * values in regions outside the domain of validity, for example after a image reprojection.
+ */
+ protected static final int FILL_VALUE_MASK = 1;
+
+ /**
+ * Mask for missing values in the bits returned by {@link #nodataValues(Variable)}.
+ */
+ protected static final int MISSING_VALUE_MASK = 2;
+
+ /**
* For subclass constructors.
*/
protected Convention() {
@@ -656,8 +668,8 @@ public class Convention {
* the role of the pad/missing sample value:
*
* <ul>
- * <li>If bit 0 is set, then the value is a pad value. Those values can be used
for background.</li>
- * <li>If bit 1 is set, then the value is a missing value.</li>
+ * <li>If bit 0 is set (mask {@value #FILL_VALUE_MASK}), then the value is a
pad value. Those values can be used for background.</li>
+ * <li>If bit 1 is set (mask {@value #MISSING_VALUE_MASK}), then the value is
a missing value.</li>
* </ul>
*
* Pad values should be first in the map, followed by missing values.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
index 19f0460..75f93b4 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
@@ -534,13 +534,13 @@ public final class RasterResource extends AbstractGridResource implements
Resour
final Object label = entry.getValue();
if (label instanceof Integer) {
final int role = (Integer) label; // Bit 0 set (value 1) =
pad value, bit 1 set = missing value.
- final int i = (role == 1) ? 1 : 0; // i=1 if role is only pad
value, i=0 otherwise.
+ final int i = (role == Convention.FILL_VALUE_MASK) ? 1 : 0; // i=1 if role
is only pad value, i=0 otherwise.
name = names[i];
if (name == null) {
name = Vocabulary.formatInternational(i == 0 ? Vocabulary.Keys.MissingValue
: Vocabulary.Keys.FillValue);
names[i] = name;
}
- if (setBackground & (role & 1) != 0) {
+ if (setBackground & (role & Convention.FILL_VALUE_MASK) != 0) {
setBackground = false; // Declare only one fill
value.
builder.setBackground(name, n);
continue;
|