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 08e148e6cb69d2d4eec75bda32b9633818e7a03d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Oct 27 19:45:50 2021 +0200 Use separated nodes in native metadata for each TIFF image. --- .../java/org/apache/sis/util/resources/Vocabulary.java | 5 +++++ .../org/apache/sis/util/resources/Vocabulary.properties | 1 + .../apache/sis/util/resources/Vocabulary_fr.properties | 1 + .../org/apache/sis/storage/geotiff/GeoTiffStore.java | 2 +- .../org/apache/sis/storage/geotiff/NativeMetadata.java | 17 ++++++++++++++--- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java index f5a1c08..a3fa6f8 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java +++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java @@ -620,6 +620,11 @@ public final class Vocabulary extends IndexedResourceBundle { public static final short ImageSize = 234; /** + * Image #{0} + */ + public static final short Image_1 = 261; + + /** * Implementation */ public static final short Implementation = 104; diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties index f498cfc..23535c1 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties +++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties @@ -125,6 +125,7 @@ Identifier = Identifier Identifiers = Identifiers Identity = Identity Image = Image +Image_1 = Image #{0} ImageSize = Image size ImageLayout = Image layout Implementation = Implementation diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties index 383dde7..873cf3d 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties +++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties @@ -132,6 +132,7 @@ Identifier = Identifiant Identifiers = Identifiants Identity = Identit\u00e9 Image = Image +Image_1 = Image {0} ImageSize = Taille de l\u2019image ImageLayout = Agencement de l\u2019image Implementation = Impl\u00e9mentation diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java index 29a7046..9da2e6e 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GeoTiffStore.java @@ -361,7 +361,7 @@ public class GeoTiffStore extends DataStore implements Aggregate { @Override public synchronized Optional<TreeTable> getNativeMetadata() throws DataStoreException { if (nativeMetadata == null) try { - nativeMetadata = new NativeMetadata().read(reader()); + nativeMetadata = new NativeMetadata(getLocale()).read(reader()); } catch (IOException e) { throw errorIO(e); } diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java index 663cd44..fbce05e 100644 --- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java +++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/NativeMetadata.java @@ -20,10 +20,12 @@ import java.util.Set; import java.util.HashSet; import java.util.Map; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.function.IntFunction; import java.io.IOException; import org.apache.sis.math.Vector; import org.apache.sis.util.Numbers; +import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.util.collection.TreeTable; import org.apache.sis.util.collection.TableColumn; import org.apache.sis.util.collection.DefaultTreeTable; @@ -32,7 +34,6 @@ import org.apache.sis.internal.geotiff.Compression; import org.apache.sis.internal.geotiff.Predictor; import static java.lang.Math.addExact; -import org.apache.sis.util.resources.Vocabulary; /** @@ -87,9 +88,15 @@ final class NativeMetadata extends GeoKeysLoader { private TreeTable.Node geoNode; /** + * Resources for vocabulary. + */ + private final Vocabulary vocabulary; + + /** * Creates a reader for a tree table of native metadata. */ - NativeMetadata() { + NativeMetadata(final Locale locale) { + vocabulary = Vocabulary.getResources(locale); } /** @@ -112,11 +119,14 @@ final class NativeMetadata extends GeoKeysLoader { * Following loop is a simplified copy of `Reader.getImageFileDirectory(int)` method, * without the "deferred entries" mechanism. Instead we seek immediately. */ + int imageNumber = 0; while ((nextIFD = readInt(false)) != 0) { if (!doneIFD.add(nextIFD)) { // Safety against infinite recursivity. break; } + final TreeTable.Node image = root.newChild(); + image.setValue(NAME, vocabulary.getString(Vocabulary.Keys.Image_1, imageNumber)); input.seek(Math.addExact(reader.origin, nextIFD)); for (long remaining = readInt(true); --remaining >= 0;) { final short tag = (short) input.readUnsignedShort(); @@ -181,7 +191,7 @@ final class NativeMetadata extends GeoKeysLoader { } } if (visible) { - final TreeTable.Node node = root.newChild(); + final TreeTable.Node node = image.newChild(); node.setValue(CODE, Short.toUnsignedInt(tag)); node.setValue(NAME, Tags.name(tag)); node.setValue(VALUE, value); @@ -192,6 +202,7 @@ final class NativeMetadata extends GeoKeysLoader { } input.seek(next); } + imageNumber++; } } catch (ArithmeticException e) { throw new IOException(e); // Can not seek that far.