You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2019/01/30 19:45:36 UTC
[sis] branch geoapi-4.0 updated (bc48507 -> 63a7898)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.
from bc48507 Control more clearly order of axes read from a netCDF file.
new 5e9b7a9 Rename some getGridGeometry() methods as getGrid() for avoiding confusion with the "real" getGridGeometry() method.
new 63a7898 Take in account the fact that the dimensions returned by UCAR CoordinateSystem.getDomain() are not always in the same order than the dimensions returned by Variable.getDimensions().
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/sis/internal/netcdf/Axis.java | 6 +--
.../org/apache/sis/internal/netcdf/Decoder.java | 2 +-
.../java/org/apache/sis/internal/netcdf/Grid.java | 34 +++++++------
.../org/apache/sis/internal/netcdf/Variable.java | 6 +--
.../sis/internal/netcdf/impl/ChannelDecoder.java | 12 ++---
.../apache/sis/internal/netcdf/impl/GridInfo.java | 14 ++---
.../sis/internal/netcdf/impl/VariableInfo.java | 20 ++++----
.../sis/internal/netcdf/ucar/DecoderWrapper.java | 6 +--
.../sis/internal/netcdf/ucar/GridWrapper.java | 59 ++++++++++++++++------
.../sis/internal/netcdf/ucar/VariableWrapper.java | 15 +++---
.../apache/sis/storage/netcdf/GridResource.java | 6 +--
.../apache/sis/storage/netcdf/MetadataReader.java | 11 ++--
.../org/apache/sis/internal/netcdf/GridTest.java | 12 ++---
.../org/apache/sis/internal/netcdf/TestCase.java | 7 +++
14 files changed, 124 insertions(+), 86 deletions(-)
[sis] 02/02: Take in account the fact that the dimensions returned
by UCAR CoordinateSystem.getDomain() are not always in the same order than
the dimensions returned by Variable.getDimensions().
Posted by de...@apache.org.
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 63a789883e2cb21463df40c5a9ad65d298809f83
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Jan 30 20:44:36 2019 +0100
Take in account the fact that the dimensions returned by UCAR CoordinateSystem.getDomain() are not always in the same order than the dimensions returned by Variable.getDimensions().
---
.../java/org/apache/sis/internal/netcdf/Axis.java | 6 +--
.../java/org/apache/sis/internal/netcdf/Grid.java | 30 ++++++-----
.../org/apache/sis/internal/netcdf/Variable.java | 4 +-
.../apache/sis/internal/netcdf/impl/GridInfo.java | 10 ++--
.../sis/internal/netcdf/impl/VariableInfo.java | 2 +-
.../sis/internal/netcdf/ucar/DecoderWrapper.java | 2 +-
.../sis/internal/netcdf/ucar/GridWrapper.java | 59 ++++++++++++++++------
.../sis/internal/netcdf/ucar/VariableWrapper.java | 7 +--
.../apache/sis/storage/netcdf/MetadataReader.java | 2 +-
.../org/apache/sis/internal/netcdf/GridTest.java | 8 +--
.../org/apache/sis/internal/netcdf/TestCase.java | 7 +++
11 files changed, 88 insertions(+), 49 deletions(-)
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index 12b6378..4701251 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -61,7 +61,7 @@ import ucar.nc2.constants.CF;
* @author Martin Desruisseaux (Geomatys)
* @version 1.0
*
- * @see Grid#getAxes()
+ * @see Grid#getAxes(Decoder)
*
* @since 0.3
* @module
@@ -138,7 +138,7 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
/**
* Constructs a new axis associated to an arbitrary number of grid dimension. The given arrays are stored
- * as-in (not cloned) and their content may be modified after construction by {@link Grid#getAxes()}.
+ * as-in (not cloned) and their content may be modified after construction by {@link Grid#getAxes(Decoder)}.
*
* @param abbreviation axis abbreviation, also identifying its type. This is a controlled vocabulary.
* @param direction direction of positive values ("up" or "down"), or {@code null} if unknown.
@@ -237,7 +237,7 @@ public final class Axis extends NamedElement implements Comparable<Axis> {
/**
* Swaps the two first source dimensions if needed for making the fastest varying dimension first.
- * This is a helper method for {@link Grid#getAxes()} invoked after all axes of a grid have been created.
+ * This is a helper method for {@link Grid#getAxes(Decoder)} invoked after all axes of a grid have been created.
* This method needs to know other axes in order to avoid collision.
*
* @param axes previously created axes.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index 6b8b9e2..0422ffc 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -70,7 +70,7 @@ public abstract class Grid extends NamedElement {
* The ordering of axes is based on the order in which dimensions are declared for variables using this grid.
* This is not necessarily the same order than the order in which variables are listed in the netCDF file.
*
- * @see #getAxes()
+ * @see #getAxes(Decoder)
*/
private Axis[] axes;
@@ -115,7 +115,7 @@ public abstract class Grid extends NamedElement {
/**
* Returns the number of dimensions of target coordinates in the <cite>"grid to CRS"</cite> conversion.
* This is the number of dimensions of the <em>coordinate reference system</em>.
- * It should be equal to the size of the array returned by {@link #getAxes()},
+ * It should be equal to the size of the array returned by {@link #getAxes(Decoder)},
* but caller should be robust to inconsistencies.
*
* @return number of CRS dimensions.
@@ -140,15 +140,16 @@ public abstract class Grid extends NamedElement {
*
* <p>This method returns a direct reference to the cached array; do not modify.</p>
*
+ * @param decoder the decoder, given in case this method needs to create axes.
* @return the CRS axes, in "natural" order (reverse of netCDF order).
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
@SuppressWarnings("ReturnOfCollectionOrArrayField")
- public final Axis[] getAxes() throws IOException, DataStoreException {
+ public final Axis[] getAxes(final Decoder decoder) throws IOException, DataStoreException {
if (axes == null) {
- axes = createAxes();
+ axes = createAxes(decoder);
/*
* The grid dimension which varies fastest should be first. The code below will swap axes if needed in order to
* achieve that goal, except if a previous axis was already using the same order. We avoid collision only in the
@@ -183,15 +184,16 @@ public abstract class Grid extends NamedElement {
}
/**
- * Creates the axes to be returned by {@link #getAxes()}. This method is invoked only once when first needed.
+ * Creates the axes to be returned by {@link #getAxes(Decoder)}. This method is invoked only once when first needed.
* Axes shall be returned in the order they will appear in the Coordinate Reference System.
*
+ * @param decoder the decoder of the netCDF file from which to create axes.
* @return the CRS axes, in "natural" order (reverse of CRS order).
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
- protected abstract Axis[] createAxes() throws IOException, DataStoreException;
+ protected abstract Axis[] createAxes(Decoder decoder) throws IOException, DataStoreException;
/**
* Returns the coordinate reference system, or {@code null} if none.
@@ -206,7 +208,7 @@ public abstract class Grid extends NamedElement {
if (!isCRSDetermined) try {
isCRSDetermined = true; // Set now for avoiding new attempts if creation fail.
final List<CRSBuilder<?,?>> builders = new ArrayList<>();
- for (final Axis axis : getAxes()) {
+ for (final Axis axis : getAxes(decoder)) {
CRSBuilder.dispatch(builders, axis);
}
final SingleCRS[] components = new SingleCRS[builders.size()];
@@ -229,8 +231,7 @@ public abstract class Grid extends NamedElement {
* Builds the grid extent if the shape is available. The shape may not be available
* if a dimension has unlimited length. The dimension names are informative only.
*
- * @param axes value of {@link #getAxes()}. Should be the same as {@link #axes}.
- * Order does not matter for this method.
+ * @param axes value of {@link #getAxes(Decoder)}. Element order does not matter for this method.
*/
@SuppressWarnings("fallthrough")
private GridExtent getExtent(final Axis[] axes) {
@@ -254,9 +255,10 @@ public abstract class Grid extends NamedElement {
} else {
continue;
}
- final int dim = axis.sourceDimensions[0];
- if (dim >= 0 && dim < names.length) {
- names[names.length - 1 - dim] = name;
+ int dim = axis.sourceDimensions[0];
+ if (dim >= 0) {
+ dim = names.length - 1 - dim; // Convert netCDF order to "natural" order.
+ if (dim >= 0) names[dim] = name;
}
}
}
@@ -274,8 +276,8 @@ public abstract class Grid extends NamedElement {
*/
public final GridGeometry getGridGeometry(final Decoder decoder) throws IOException, DataStoreException {
if (!isGeometryDetermined) try {
- isGeometryDetermined = true; // Set now for avoiding new attempts if creation fail.
- final Axis[] axes = getAxes(); // In CRS order (reverse of netCDF order).
+ isGeometryDetermined = true; // Set now for avoiding new attempts if creation fail.
+ final Axis[] axes = getAxes(decoder); // In CRS order (reverse of netCDF order).
/*
* Creates the "grid to CRS" transform. The number of columns is the number of dimensions in the grid
* (the source) +1, and the number of rows is the number of dimensions in the CRS (the target) +1.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 6928e07..4cb153e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -708,8 +708,8 @@ public abstract class Variable extends NamedElement {
/**
* Returns a coordinate for this two-dimensional grid coordinate axis. This is (indirectly) a callback method
- * for {@link Grid#getAxes()}. The (<var>i</var>, <var>j</var>) indices are grid indices <em>before</em>
- * they get reordered by the {@link Grid#getAxes()} method. In the netCDF UCAR API, this method maps directly
+ * for {@link Grid#getAxes(Decoder)}. The (<var>i</var>, <var>j</var>) indices are grid indices <em>before</em>
+ * they get reordered by the {@link Grid#getAxes(Decoder)} method. In the netCDF UCAR API, this method maps directly
* to {@link ucar.nc2.dataset.CoordinateAxis2D#getCoordValue(int, int)}.
*
* @param j the fastest varying (right-most) index.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
index cff7588..617b1ed 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
@@ -25,6 +25,7 @@ import java.util.TreeMap;
import java.util.SortedMap;
import org.apache.sis.internal.netcdf.Axis;
import org.apache.sis.internal.netcdf.Grid;
+import org.apache.sis.internal.netcdf.Decoder;
import org.apache.sis.internal.netcdf.Resources;
import org.apache.sis.storage.DataStoreContentException;
import org.apache.sis.storage.DataStoreException;
@@ -156,7 +157,7 @@ final class GridInfo extends Grid {
/**
* Returns the number of dimensions of target coordinates in the <cite>"grid to CRS"</cite> conversion.
* This is the number of dimensions of the <em>coordinate reference system</em>.
- * It should be equal to the size of the array returned by {@link #getAxes()},
+ * It should be equal to the size of the array returned by {@link #getAxes(Decoder)},
* but caller should be robust to inconsistencies.
*/
@Override
@@ -181,8 +182,8 @@ final class GridInfo extends Grid {
/**
* Returns all axes of the netCDF coordinate system, together with the grid dimension to which the axis
- * is associated. See {@link org.apache.sis.internal.netcdf.ucar.GridWrapper#getAxes()} for a closer look
- * on the relationship between this algorithm and the UCAR library.
+ * is associated. See {@link org.apache.sis.internal.netcdf.ucar.GridWrapper#getAxes(Decoder)} for a
+ * closer look on the relationship between this algorithm and the UCAR library.
*
* <p>In this method, the words "domain" and "range" are used in the netCDF sense: they are the input
* (domain) and output (range) of the function that convert grid indices to geodetic coordinates.</p>
@@ -191,13 +192,14 @@ final class GridInfo extends Grid {
* In particular, the relationship is not straightforward when the coordinate system contains
* "two-dimensional axes" (in {@link ucar.nc2.dataset.CoordinateAxis2D} sense).</p>
*
+ * @param decoder the decoder of the netCDF file from which to create axes.
* @return the CRS axes, in "natural" order (reverse of netCDF order).
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
@Override
- protected Axis[] createAxes() throws IOException, DataStoreException {
+ protected Axis[] createAxes(final Decoder decoder) throws IOException, DataStoreException {
/*
* Process the variables in the order the appear in the sequence of bytes that make the netCDF files.
* This is often the reverse order of range indices, but not necessarily. The intent is to reduce the
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index ef33f2f..7b5fda6 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -816,7 +816,7 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
/**
* Returns a coordinate for this two-dimensional grid coordinate axis.
- * This is (indirectly) a callback method for {@link Grid#getAxes()}.
+ * This is (indirectly) a callback method for {@link Grid#getAxes(Decoder)}.
*
* @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
index 5e2d659..a69bb1e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
@@ -446,7 +446,7 @@ public final class DecoderWrapper extends Decoder implements CancelTask {
}
geometries = new Grid[(systems != null) ? systems.size() : 0];
for (int i=0; i<geometries.length; i++) {
- geometries[i] = new GridWrapper(this, systems.get(i));
+ geometries[i] = new GridWrapper(systems.get(i), null);
}
}
return geometries;
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
index 1f78edd..5eb02fd 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridWrapper.java
@@ -19,12 +19,14 @@ package org.apache.sis.internal.netcdf.ucar;
import java.io.IOException;
import java.util.List;
import ucar.nc2.Dimension;
+import ucar.nc2.VariableIF;
import ucar.nc2.constants.AxisType;
import ucar.nc2.dataset.CoordinateAxis;
import ucar.nc2.dataset.CoordinateAxis2D;
import ucar.nc2.dataset.CoordinateSystem;
import org.apache.sis.internal.netcdf.Axis;
import org.apache.sis.internal.netcdf.Grid;
+import org.apache.sis.internal.netcdf.Decoder;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.util.ArraysExt;
@@ -42,24 +44,49 @@ import org.apache.sis.util.ArraysExt;
*/
final class GridWrapper extends Grid {
/**
- * The decoder which is creating this grid geometry.
- * Used for fetching the variables when first needed.
+ * The netCDF coordinate system to wrap.
*/
- private final DecoderWrapper decoder;
+ private final CoordinateSystem netcdfCS;
/**
- * The netCDF coordinate system to wrap.
+ * Dimensions of the grid in netCDF order (reverse of "natural" order).
+ * This is the same content than {@code netcdfCS.getDomain()} but potentially in a different order.
+ * Reordering is needed when the order of dimensions in a variable does not match the order of dimensions in the grid.
+ * There is no such mismatch with Apache SIS implementation of netCDF reader, but those mismatches sometime happen with
+ * the wrappers around UCAR library where the following methods may return lists with elements in different order:
+ *
+ * <ul>
+ * <li>{@link ucar.nc2.Variable#getDimensions()}</li>
+ * <li>{@link ucar.nc2.dataset.CoordinateSystem#getDomain()}</li>
+ * </ul>
*/
- final CoordinateSystem netcdfCS;
+ private final List<Dimension> domain;
/**
* Creates a new grid geometry for the given netCDF coordinate system.
*
* @param cs the netCDF coordinate system.
*/
- GridWrapper(final DecoderWrapper decoder, final CoordinateSystem cs) {
- this.decoder = decoder;
+ GridWrapper(final CoordinateSystem cs, final List<Dimension> dimensions) {
netcdfCS = cs;
+ domain = (dimensions != null) ? dimensions : cs.getDomain();
+ }
+
+ /**
+ * Returns the grid to use for the given variable. This method is needed because the order of dimensions declared
+ * in the {@link CoordinateSystem} may not be the same order than the dimensions of the given variable.
+ */
+ GridWrapper forVariable(final VariableIF variable, final List<CoordinateSystem> cs) {
+ if (cs.contains(netcdfCS)) {
+ final List<Dimension> source = variable.getDimensions();
+ if (domain.equals(source)) {
+ return this;
+ }
+ if (domain.size() == source.size() && domain.containsAll(source)) {
+ return new GridWrapper(netcdfCS, source);
+ }
+ }
+ return null;
}
/**
@@ -82,7 +109,7 @@ final class GridWrapper extends Grid {
/**
* Returns the number of dimensions of target coordinates in the <cite>"grid to CRS"</cite> conversion.
* This is the number of dimensions of the <em>coordinate reference system</em>.
- * It should be equal to the size of the array returned by {@link #getAxes()},
+ * It should be equal to the size of the array returned by {@link #getAxes(Decoder)},
* but caller should be robust to inconsistencies.
*/
@Override
@@ -98,15 +125,14 @@ final class GridWrapper extends Grid {
*/
@Override
protected long[] getShape() {
- final List<Dimension> domain = netcdfCS.getDomain();
- final int dim = domain.size();
- final long[] size = new long[dim];
- for (int i=0; i<dim; i++) {
+ int dim = domain.size();
+ final long[] size = new long[dim--];
+ for (int i=0; i<=dim; i++) {
final int length = domain.get(i).getLength();
if (length <= 0) {
return null;
}
- size[(dim-1) - i] = length;
+ size[dim - i] = length;
}
return size;
}
@@ -123,14 +149,14 @@ final class GridWrapper extends Grid {
* In particular, the relationship is not straightforward when the coordinate system contains instances
* of {@link CoordinateAxis2D}.</p>
*
+ * @param decoder the decoder of the netCDF file from which to create axes.
* @return the CRS axes, in "natural" order (reverse of netCDF order).
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
@Override
- protected Axis[] createAxes() throws IOException, DataStoreException {
- final List<Dimension> domain = netcdfCS.getDomain();
+ protected Axis[] createAxes(final Decoder decoder) throws IOException, DataStoreException {
final List<CoordinateAxis> range = netcdfCS.getCoordinateAxes();
/*
* In this method, 'sourceDim' and 'targetDim' are relative to "grid to CRS" conversion.
@@ -182,7 +208,8 @@ final class GridWrapper extends Grid {
*/
}
axes[targetDim] = new Axis(abbreviation, axis.getPositive(),
- ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i), decoder.getWrapperFor(axis));
+ ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i),
+ ((DecoderWrapper) decoder).getWrapperFor(axis));
}
/*
* We want axes in "natural" order. But the netCDF UCAR library sometime provides axes already
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
index 8637806..08e2771 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
@@ -229,8 +229,9 @@ final class VariableWrapper extends Variable {
final List<CoordinateSystem> cs = ((Enhancements) variable).getCoordinateSystems();
if (cs != null && !cs.isEmpty()) {
for (final Grid grid : decoder.getGrids()) {
- if (cs.contains(((GridWrapper) grid).netcdfCS)) {
- return grid;
+ final GridWrapper g = ((GridWrapper) grid).forVariable(variable, cs);
+ if (g != null) {
+ return g;
}
}
}
@@ -427,7 +428,7 @@ final class VariableWrapper extends Variable {
/**
* Returns a coordinate for this two-dimensional grid coordinate axis.
- * This is (indirectly) a callback method for {@link Grid#getAxes()}.
+ * This is (indirectly) a callback method for {@link Grid#getAxes(Decoder)}.
*/
@Override
protected double coordinateForAxis(final int j, final int i) {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 2f030d1..b0abc0b 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -713,7 +713,7 @@ split: while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
private void addSpatialRepresentationInfo(final Grid cs) throws IOException, DataStoreException {
- final Axis[] axes = cs.getAxes();
+ final Axis[] axes = cs.getAxes(decoder);
for (int i=0; i<axes.length; i++) {
final Axis axis = axes[i];
/*
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
index b6c42b9..27d7e8a 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
@@ -71,7 +71,7 @@ public strictfp class GridTest extends TestCase {
}
/**
- * Tests {@link Grid#getAxes()} on a two-dimensional dataset.
+ * Tests {@link Grid#getAxes(Decoder)} on a two-dimensional dataset.
*
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
@@ -79,7 +79,7 @@ public strictfp class GridTest extends TestCase {
@Test
@DependsOnMethod("testDimensions")
public void testAxes2D() throws IOException, DataStoreException {
- final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGrids())).getAxes();
+ final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGrids())).getAxes(decoder());
assertEquals(2, axes.length);
final Axis x = axes[0];
final Axis y = axes[1];
@@ -95,7 +95,7 @@ public strictfp class GridTest extends TestCase {
}
/**
- * Tests {@link Grid#getAxes()} on a four-dimensional dataset.
+ * Tests {@link Grid#getAxes(Decoder)} on a four-dimensional dataset.
*
* @throws IOException if an I/O error occurred while opening the file.
* @throws DataStoreException if a logical error occurred.
@@ -103,7 +103,7 @@ public strictfp class GridTest extends TestCase {
@Test
@DependsOnMethod("testDimensions")
public void testAxes4D() throws IOException, DataStoreException {
- final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids())).getAxes();
+ final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids())).getAxes(decoder());
assertEquals(4, axes.length);
final Axis x = axes[0];
final Axis y = axes[1];
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
index 03497f3..c49ef04 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
@@ -147,6 +147,13 @@ public abstract strictfp class TestCase extends org.apache.sis.test.TestCase {
}
/**
+ * Returns the decoder being tested.
+ */
+ final Decoder decoder() {
+ return decoder;
+ }
+
+ /**
* Invoked after all tests in a class have been executed.
* This method closes all netCDF files.
*
[sis] 01/02: Rename some getGridGeometry() methods as getGrid() for
avoiding confusion with the "real" getGridGeometry() method.
Posted by de...@apache.org.
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 5e9b7a9f15676cf6744cad7f5199b8814a15eca7
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Jan 30 15:31:07 2019 +0100
Rename some getGridGeometry() methods as getGrid() for avoiding confusion with the "real" getGridGeometry() method.
---
.../java/org/apache/sis/internal/netcdf/Decoder.java | 2 +-
.../main/java/org/apache/sis/internal/netcdf/Grid.java | 4 ++--
.../java/org/apache/sis/internal/netcdf/Variable.java | 2 +-
.../sis/internal/netcdf/impl/ChannelDecoder.java | 12 ++++++------
.../org/apache/sis/internal/netcdf/impl/GridInfo.java | 4 ++--
.../apache/sis/internal/netcdf/impl/VariableInfo.java | 18 +++++++++---------
.../sis/internal/netcdf/ucar/DecoderWrapper.java | 4 ++--
.../sis/internal/netcdf/ucar/VariableWrapper.java | 8 ++++----
.../org/apache/sis/storage/netcdf/GridResource.java | 6 +++---
.../org/apache/sis/storage/netcdf/MetadataReader.java | 9 ++++-----
.../java/org/apache/sis/internal/netcdf/GridTest.java | 8 ++++----
11 files changed, 38 insertions(+), 39 deletions(-)
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
index aca6d33..23e6f48 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
@@ -282,7 +282,7 @@ public abstract class Decoder extends ReferencingFactoryContainer implements Clo
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
*/
- public abstract Grid[] getGridGeometries() throws IOException, DataStoreException;
+ public abstract Grid[] getGrids() throws IOException, DataStoreException;
/**
* Returns the role of the given variable. In particular, this method shall return
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index 28585d3..6b8b9e2 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -49,7 +49,7 @@ import org.apache.sis.util.NullArgumentException;
* @author Martin Desruisseaux (Geomatys)
* @version 1.0
*
- * @see Decoder#getGridGeometries()
+ * @see Decoder#getGrids()
*
* @since 0.3
* @module
@@ -281,7 +281,7 @@ public abstract class Grid extends NamedElement {
* (the source) +1, and the number of rows is the number of dimensions in the CRS (the target) +1.
* The order of dimensions in the transform is the reverse of the netCDF axis order.
*/
- int lastSrcDim = getSourceDimensions(); // Will be decremented later, then keep final.
+ int lastSrcDim = getSourceDimensions(); // Will be decremented later, then kept final.
int lastTgtDim = getTargetDimensions();
final int[] deferred = new int[axes.length]; // Indices of axes that have been deferred.
final List<MathTransform> nonLinears = new ArrayList<>(axes.length);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 1528a11..6928e07 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -349,7 +349,7 @@ public abstract class Variable extends NamedElement {
* @throws IOException if an error occurred while reading the data.
* @throws DataStoreException if a logical error occurred.
*/
- public abstract Grid getGridGeometry(Decoder decoder) throws IOException, DataStoreException;
+ public abstract Grid getGrid(Decoder decoder) throws IOException, DataStoreException;
/**
* Returns the names of the dimensions of this variable, in the order they are declared in the netCDF file.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index 5e845ed..80c78f7 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -199,7 +199,7 @@ public final class ChannelDecoder extends Decoder {
/**
* The grid geometries, created when first needed.
*
- * @see #getGridGeometries()
+ * @see #getGrids()
*/
private transient Grid[] gridGeometries;
@@ -889,7 +889,7 @@ public final class ChannelDecoder extends Decoder {
*/
@Override
@SuppressWarnings("ReturnOfCollectionOrArrayField")
- public Grid[] getGridGeometries() {
+ public Grid[] getGrids() {
if (gridGeometries == null) {
/*
* First, find all variables which are used as coordinate system axis. The keys in the map are
@@ -960,13 +960,13 @@ nextVar: for (final VariableInfo variable : variables) {
* from the "coordinates" attribute and axes inferred from variable names matching dimension names, we
* are better to sort them.
*/
- GridInfo gridGeometry = new GridInfo(variable.dimensions,
+ GridInfo grid = new GridInfo(variable.dimensions,
axes.toArray(new VariableInfo[axes.size()]), mixedFlag == 3);
- GridInfo existing = shared.putIfAbsent(gridGeometry, gridGeometry);
+ GridInfo existing = shared.putIfAbsent(grid, grid);
if (existing != null) {
- gridGeometry = existing;
+ grid = existing;
}
- variable.gridGeometry = gridGeometry;
+ variable.grid = grid;
}
gridGeometries = shared.values().toArray(new Grid[shared.size()]);
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
index 8553a30..cff7588 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridInfo.java
@@ -23,13 +23,13 @@ import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.SortedMap;
-import org.apache.sis.util.ArraysExt;
import org.apache.sis.internal.netcdf.Axis;
import org.apache.sis.internal.netcdf.Grid;
import org.apache.sis.internal.netcdf.Resources;
import org.apache.sis.storage.DataStoreContentException;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.measure.Units;
+import org.apache.sis.util.ArraysExt;
import ucar.nc2.constants.CF;
@@ -256,7 +256,7 @@ final class GridInfo extends Grid {
/**
* Returns a hash code for this grid. A map of {@code GridInfo} is used by
- * {@link ChannelDecoder#getGridGeometries()} for sharing existing instances.
+ * {@link ChannelDecoder#getGrids()} for sharing existing instances.
*/
@Override
public int hashCode() {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index 664b990..ef33f2f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -147,12 +147,12 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
/**
* The grid geometry associated to this variable,
- * computed by {@link ChannelDecoder#getGridGeometries()} when first needed.
+ * computed by {@link ChannelDecoder#getGrids()} when first needed.
* May stay {@code null} if the variable is not a data cube.
*
- * @see #getGridGeometry(Decoder)
+ * @see #getGrid(Decoder)
*/
- GridInfo gridGeometry;
+ GridInfo grid;
/**
* {@code true} if this variable seems to be a coordinate system axis, as determined by comparing its name
@@ -466,17 +466,17 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
/**
* Returns the grid geometry for this variable, or {@code null} if this variable is not a data cube.
* The grid geometries are opportunistically cached in {@code VariableInfo} instances after they have
- * been computed by {@link ChannelDecoder#getGridGeometries()}.
+ * been computed by {@link ChannelDecoder#getGrids()}.
* The same grid geometry may be shared by many variables.
*
- * @see ChannelDecoder#getGridGeometries()
+ * @see ChannelDecoder#getGrids()
*/
@Override
- public Grid getGridGeometry(final Decoder decoder) throws IOException, DataStoreException {
- if (gridGeometry == null) {
- decoder.getGridGeometries(); // Force calculation of grid geometries if not already done.
+ public Grid getGrid(final Decoder decoder) throws IOException, DataStoreException {
+ if (grid == null) {
+ decoder.getGrids(); // Force calculation of grid geometries if not already done.
}
- return gridGeometry;
+ return grid;
}
/**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
index 5910b5c..5e2d659 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
@@ -92,7 +92,7 @@ public final class DecoderWrapper extends Decoder implements CancelTask {
/**
* The grid geometries, computed when first needed.
*
- * @see #getGridGeometries()
+ * @see #getGrids()
*/
private transient Grid[] geometries;
@@ -433,7 +433,7 @@ public final class DecoderWrapper extends Decoder implements CancelTask {
*/
@Override
@SuppressWarnings({"ReturnOfCollectionOrArrayField", "null"})
- public Grid[] getGridGeometries() throws IOException {
+ public Grid[] getGrids() throws IOException {
if (geometries == null) {
List<CoordinateSystem> systems = null;
if (file instanceof NetcdfDataset) {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
index 0723d78..8637806 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
@@ -218,17 +218,17 @@ final class VariableWrapper extends Variable {
/**
* Returns the grid geometry for this variable, or {@code null} if this variable is not a data cube.
- * This method searches for a grid previously computed by {@link DecoderWrapper#getGridGeometries()}.
+ * This method searches for a grid previously computed by {@link DecoderWrapper#getGrids()}.
* The same grid geometry may be shared by many variables.
*
- * @see DecoderWrapper#getGridGeometries()
+ * @see DecoderWrapper#getGrids()
*/
@Override
- public Grid getGridGeometry(final Decoder decoder) throws IOException, DataStoreException {
+ public Grid getGrid(final Decoder decoder) throws IOException, DataStoreException {
if (variable instanceof Enhancements) {
final List<CoordinateSystem> cs = ((Enhancements) variable).getCoordinateSystems();
if (cs != null && !cs.isEmpty()) {
- for (final Grid grid : decoder.getGridGeometries()) {
+ for (final Grid grid : decoder.getGrids()) {
if (cs.contains(((GridWrapper) grid).netcdfCS)) {
return grid;
}
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
index 28b3bf7..3a84141 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
@@ -128,7 +128,7 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
private final Path location;
/**
- * Creates a new resource.
+ * Creates a new resource. All variables in the {@code data} list shall have the same domain and the same grid geometry.
*
* @param decoder the implementation used for decoding the netCDF file.
* @param name the name for the resource.
@@ -160,7 +160,7 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
if (decoder.roleOf(variable) != VariableRole.COVERAGE) {
continue; // Skip variables that are not grid coverages.
}
- final Grid grid = variable.getGridGeometry(decoder);
+ final Grid grid = variable.getGrid(decoder);
if (grid == null) {
continue; // Skip variables that are not grid coverages.
}
@@ -192,7 +192,7 @@ final class GridResource extends AbstractGridResource implements ResourceOnFileS
final String cn = candidate.getStandardName();
if (cn.regionMatches(cn.length() - suffixLength, name, suffixStart, suffixLength) &&
cn.regionMatches(0, name, 0, prefixLength) && candidate.getDataType() == type &&
- candidate.getGridGeometry(decoder) == grid)
+ candidate.getGrid(decoder) == grid)
{
/*
* Found another variable with the same name except for the keyword. Verify that the
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index 73d31b5..2f030d1 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -659,10 +659,9 @@ split: while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
}
/*
* Add spatial representation type only if it was not explicitly given in the metadata.
- * The call to getGridGeometries() may be relatively costly, so we don't want to invoke
- * it without necessity.
+ * The call to getGrids() may be relatively costly, so we don't want to invoke it without necessity.
*/
- if (!hasDataType && decoder.getGridGeometries().length != 0) {
+ if (!hasDataType && decoder.getGrids().length != 0) {
addSpatialRepresentation(SpatialRepresentationType.GRID);
}
/*
@@ -1027,7 +1026,7 @@ split: while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
* @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
*/
public Metadata read() throws IOException, DataStoreException {
- for (final Grid cs : decoder.getGridGeometries()) {
+ for (final Grid cs : decoder.getGrids()) {
final CoordinateReferenceSystem crs = cs.getCoordinateReferenceSystem(decoder);
addReferenceSystem(crs);
if (verticalCRS == null) {
@@ -1048,7 +1047,7 @@ split: while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
* Add the dimension information, if any. This metadata node
* is built from the netCDF CoordinateSystem objects.
*/
- for (final Grid cs : decoder.getGridGeometries()) {
+ for (final Grid cs : decoder.getGrids()) {
if (cs.getSourceDimensions() >= Grid.MIN_DIMENSION &&
cs.getTargetDimensions() >= Grid.MIN_DIMENSION)
{
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
index e31292e..b6c42b9 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridTest.java
@@ -61,11 +61,11 @@ public strictfp class GridTest extends TestCase {
*/
@Test
public void testDimensions() throws IOException, DataStoreException {
- Grid geometry = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGridGeometries()));
+ Grid geometry = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGrids()));
assertEquals("getSourceDimensions()", 2, geometry.getSourceDimensions());
assertEquals("getTargetDimensions()", 2, geometry.getTargetDimensions());
- geometry = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGridGeometries()));
+ geometry = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids()));
assertEquals("getSourceDimensions()", 4, geometry.getSourceDimensions());
assertEquals("getTargetDimensions()", 4, geometry.getTargetDimensions());
}
@@ -79,7 +79,7 @@ public strictfp class GridTest extends TestCase {
@Test
@DependsOnMethod("testDimensions")
public void testAxes2D() throws IOException, DataStoreException {
- final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGridGeometries())).getAxes();
+ final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_2D_GEOGRAPHIC).getGrids())).getAxes();
assertEquals(2, axes.length);
final Axis x = axes[0];
final Axis y = axes[1];
@@ -103,7 +103,7 @@ public strictfp class GridTest extends TestCase {
@Test
@DependsOnMethod("testDimensions")
public void testAxes4D() throws IOException, DataStoreException {
- final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGridGeometries())).getAxes();
+ final Axis[] axes = getSingleton(filter(selectDataset(TestData.NETCDF_4D_PROJECTED).getGrids())).getAxes();
assertEquals(4, axes.length);
final Axis x = axes[0];
final Axis y = axes[1];