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 2013/05/23 13:19:57 UTC
svn commit: r1485646 - in /sis/branches/JDK7:
core/sis-utility/src/main/java/org/apache/sis/internal/util/
core/sis-utility/src/test/java/org/apache/sis/internal/util/
storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/
storage/sis-netcdf/...
Author: desruisseaux
Date: Thu May 23 11:19:57 2013
New Revision: 1485646
URL: http://svn.apache.org/r1485646
Log:
Added a GridGeometry implementation for the standalone NetCDF decoder.
Added:
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java (with props)
sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java (with props)
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] Thu May 23 11:19:57 2013
@@ -391,6 +391,33 @@ public final class CollectionsExt extend
}
/**
+ * Adds a value in a pseudo multi-values map. The multi-values map is simulated by a map of lists.
+ * The map can be initially empty - lists will be created as needed.
+ *
+ * @param <K> The type of key elements in the map.
+ * @param <V> The type of value elements in the lists.
+ * @param map The multi-values map where to add an element.
+ * @param key The key of the element to add. Can be null if the given map supports null keys.
+ * @param value The value of the element to add. Can be null.
+ * @return The list where the given value has been added. May be unmodifiable.
+ */
+ public static <K,V> List<V> addToMultiValuesMap(final Map<K,List<V>> map, final K key, final V value) {
+ final List<V> singleton = Collections.singletonList(value);
+ List<V> values = map.put(key, singleton);
+ if (values == null) {
+ return singleton;
+ }
+ if (values.size() <= 1) {
+ values = new ArrayList<>(values);
+ if (map.put(key, values) != singleton) {
+ throw new ConcurrentModificationException();
+ }
+ }
+ values.add(value);
+ return values;
+ }
+
+ /**
* Creates a (<cite>name</cite>, <cite>element</cite>) mapping for the given collection of elements.
* If the name of an element is not all lower cases, then this method also adds an entry for the
* lower cases version of that name in order to allow case-insensitive searches.
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java [UTF-8] Thu May 23 11:19:57 2013
@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
@@ -43,6 +44,30 @@ import org.apache.sis.internal.jdk8.Func
*/
public final strictfp class CollectionsExtTest extends TestCase {
/**
+ * Tests {@link CollectionsExt#addToMultiValuesMap(Map, Object, Object)}.
+ */
+ @Test
+ public void testAddToMultiValuesMap() {
+ final Map<String, List<Integer>> map = new LinkedHashMap<>();
+ final Integer A1 = 2;
+ final Integer A2 = 4;
+ final Integer B1 = 3;
+ final Integer B2 = 6;
+ final Integer B3 = 9;
+ assertArrayEquals(new Integer[] {A1},
+ CollectionsExt.addToMultiValuesMap(map, "A", A1).toArray());
+ assertArrayEquals(new Integer[] {B1},
+ CollectionsExt.addToMultiValuesMap(map, "B", B1).toArray());
+ assertArrayEquals(new Integer[] {B1, B2},
+ CollectionsExt.addToMultiValuesMap(map, "B", B2).toArray());
+ assertArrayEquals(new Integer[] {A1, A2},
+ CollectionsExt.addToMultiValuesMap(map, "A", A2).toArray());
+ assertArrayEquals(new Integer[] {B1, B2, B3},
+ CollectionsExt.addToMultiValuesMap(map, "B", B3).toArray());
+ assertArrayEquals(new String[] {"A", "B"}, map.keySet().toArray());
+ }
+
+ /**
* Tests {@link CollectionsExt#toCaseInsensitiveNameMap(Collection, Function, Locale)}.
*/
@Test
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java [UTF-8] Thu May 23 11:19:57 2013
@@ -25,14 +25,11 @@ package org.apache.sis.internal.netcdf;
* @version 0.3
* @module
*/
-public abstract class GridGeometry extends WarningProducer {
+public abstract class GridGeometry {
/**
- * Constructs a new conversion information.
- *
- * @param parent Where to send the warnings, or {@code null} if none.
+ * Constructs a new grid geometry information.
*/
- protected GridGeometry(final WarningProducer parent) {
- super(parent);
+ protected GridGeometry() {
}
/**
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] Thu May 23 11:19:57 2013
@@ -16,7 +16,12 @@
*/
package org.apache.sis.internal.netcdf.impl;
+import java.util.Set;
import java.util.Map;
+import java.util.LinkedHashSet;
+import java.util.LinkedHashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
@@ -157,15 +162,26 @@ public final class ChannelDecoder extend
/**
* The variables found in the NetCDF file.
+ *
+ * @see #getVariables()
*/
private final VariableInfo[] variables;
/**
* The attributes found in the NetCDF file.
+ *
+ * @see #findAttribute(String)
*/
private final Map<String,Attribute> attributeMap;
/**
+ * The grid geometries, created when first needed.
+ *
+ * @see #getGridGeometries()
+ */
+ private transient GridGeometry[] gridGeometries;
+
+ /**
* Creates a new decoder for the given file.
* This constructor parses immediately the header.
*
@@ -680,9 +696,63 @@ public final class ChannelDecoder extend
return variables;
}
+ /**
+ * Returns all grid geometries found in the NetCDF file.
+ * This method returns a direct reference to an internal array - do not modify.
+ */
@Override
public GridGeometry[] getGridGeometries() throws IOException {
- throw new UnsupportedOperationException();
+ if (gridGeometries == null) {
+ /*
+ * First, find all variables which are used as coordinate system axis. The keys are the
+ * grid dimensions which are the domain of the variable (i.e. the sources of the conversion
+ * from grid coordinates to CRS coordinates).
+ */
+ final Map<Dimension, List<VariableInfo>> dimToAxes = new IdentityHashMap<>();
+ for (final VariableInfo variable : variables) {
+ if (variable.isCoordinateSystemAxis()) {
+ for (final Dimension dimension : variable.dimensions) {
+ CollectionsExt.addToMultiValuesMap(dimToAxes, dimension, variable);
+ }
+ }
+ }
+ /*
+ * For each variables, gets the list of all axes associated to their dimensions. The association
+ * is given by the above 'dimToVars' map. More than one variable may have the same dimensions,
+ * and consequently the same axes, so we will remember the previously created instances in order
+ * to share them.
+ */
+ final Set<VariableInfo> axes = new LinkedHashSet<>(4);
+ final Map<List<Dimension>, GridGeometryInfo> dimsToGG = new LinkedHashMap<>();
+nextVar: for (final VariableInfo variable : variables) {
+ if (variable.isCoordinateSystemAxis()) {
+ continue;
+ }
+ final List<Dimension> dimensions = Arrays.asList(variable.dimensions);
+ GridGeometryInfo gridGeometry = dimsToGG.get(dimensions);
+ if (gridGeometry == null) {
+ /*
+ * Found a new list of dimensions for which no axes have been created yet.
+ * If and only if we can find all axes, then create the GridGeometryInfo.
+ * This is a "all or nothing" operation.
+ */
+ for (final Dimension dimension : variable.dimensions) {
+ final List<VariableInfo> axis = dimToAxes.get(dimension);
+ if (axis == null) {
+ axes.clear();
+ continue nextVar;
+ }
+ axes.addAll(axis);
+ }
+ gridGeometry = new GridGeometryInfo(variable.dimensions, axes.toArray(new VariableInfo[axes.size()]));
+ dimsToGG.put(dimensions, gridGeometry);
+ axes.clear();
+ }
+ variable.gridGeometry = gridGeometry;
+ }
+ gridGeometries = dimsToGG.values().toArray(new GridGeometry[dimsToGG.size()]);
+ }
+ return gridGeometries;
}
/**
Added: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java?rev=1485646&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java (added)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java [UTF-8] Thu May 23 11:19:57 2013
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.netcdf.impl;
+
+import org.apache.sis.util.ArraysExt;
+import org.apache.sis.internal.netcdf.Axis;
+import org.apache.sis.internal.netcdf.GridGeometry;
+import org.apache.sis.storage.netcdf.AttributeNames;
+
+
+/**
+ * Description of a grid geometry found in a NetCDF file.
+ *
+ * <p>In this class, 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>
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+final class GridGeometryInfo extends GridGeometry {
+ /**
+ * Mapping from values of the {@code "_CoordinateAxisType"} attribute to the
+ * {@code AttributeNames.Dimension} constant.
+ */
+ private static final Object[] AXIS_TYPES = {
+ "Lon", AttributeNames.LONGITUDE,
+ "Lat", AttributeNames.LATITUDE,
+ "Pressure", AttributeNames.VERTICAL,
+ "Height", AttributeNames.VERTICAL,
+ "RunTime", AttributeNames.TIME,
+ "Time", AttributeNames.TIME
+ };
+
+ /**
+ * Describes the input values expected by the function converting grid indices to geodetic coordinates.
+ * They are the dimensions of the grid (<strong>not</strong> the dimensions of the CRS).
+ */
+ private final Dimension[] domain;
+
+ /**
+ * Describes the output values calculated by the function converting grid indices to geodetic coordinates.
+ * They are the coordinate values expressed in the CRS.
+ */
+ private final VariableInfo[] range;
+
+ /**
+ * Constructs a new grid geometry information.
+ *
+ * @param domain Describes the input values of the "grid to CRS" conversion.
+ * @param range The output values of the "grid to CRS" conversion.
+ */
+ GridGeometryInfo(final Dimension[] domain, final VariableInfo[] range) {
+ this.domain = domain;
+ this.range = range;
+ }
+
+ /**
+ * Returns the number of dimensions of source coordinates in the "<cite>grid to CRS</cite>" conversion.
+ * This is the number of dimensions of the <em>grid</em>.
+ */
+ @Override
+ public int getSourceDimensions() {
+ return domain.length;
+ }
+
+ /**
+ * 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>.
+ */
+ @Override
+ public int getTargetDimensions() {
+ return range.length;
+ }
+
+ /**
+ * 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.GridGeometryWrapper#getAxes()} for more
+ * information on the algorithm applied here, and relationship with the UCAR library.
+ */
+ @Override
+ public Axis[] getAxes() {
+ int targetDim = range.length;
+ final Axis[] axes = new Axis[targetDim];
+ while (--targetDim >= 0) {
+ final VariableInfo axis = range[targetDim];
+ final Dimension[] axisDomain = axis.dimensions;
+ AttributeNames.Dimension attributeNames = null;
+ final String type = axis.getAxisType();
+ if (type != null) {
+ for (int i=0; i<AXIS_TYPES.length; i+=2) {
+ if (type.equalsIgnoreCase((String) AXIS_TYPES[i])) {
+ attributeNames = (AttributeNames.Dimension) AXIS_TYPES[i+1];
+ break;
+ }
+ }
+ }
+ int i = 0;
+ final int[] indices = new int[axisDomain.length];
+ final int[] sizes = new int[axisDomain.length];
+ for (final Dimension dimension : axisDomain) {
+ for (int sourceDim=domain.length; --sourceDim>=0;) {
+ if (domain[sourceDim] == dimension) {
+ indices[i] = sourceDim;
+ sizes[i++] = dimension.length;
+ break;
+ }
+ }
+ }
+ axes[targetDim] = new Axis(this, attributeNames,
+ ArraysExt.resize(indices, i),
+ ArraysExt.resize(sizes, i));
+ }
+ return axes;
+ }
+
+ @Override
+ protected double coordinateForCurrentAxis(final int j, final int i) {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java [UTF-8] Thu May 23 11:19:57 2013
@@ -19,6 +19,7 @@ package org.apache.sis.internal.netcdf.i
import java.util.Map;
import ucar.nc2.constants.CF;
import ucar.nc2.constants.CDM;
+import ucar.nc2.constants._Coordinate;
import org.apache.sis.internal.netcdf.Variable;
@@ -85,7 +86,7 @@ final class VariableInfo extends Variabl
/**
* The dimensions of that variable.
*/
- private final Dimension[] dimensions;
+ final Dimension[] dimensions;
/**
* All dimensions in the NetCDF files.
@@ -109,6 +110,12 @@ final class VariableInfo extends Variabl
private final long offset;
/**
+ * The grid geometry associated to this variable,
+ * computed by {@link ChannelDecoder#getGridGeometries()} when first needed.
+ */
+ GridGeometryInfo gridGeometry;
+
+ /**
* Creates a new variable.
*/
VariableInfo(final String name, final Dimension[] dimensions, final Dimension[] allDimensions,
@@ -195,6 +202,17 @@ final class VariableInfo extends Variabl
}
/**
+ * Returns the value of the {@code "_CoordinateAxisType"} attribute, or {@code null} if none.
+ */
+ final String getAxisType() {
+ final Attribute attribute = attributes.get(_Coordinate.AxisType);
+ if (attribute != null && attribute.value instanceof String) {
+ return (String) attribute.value;
+ }
+ return null;
+ }
+
+ /**
* Returns the names of the dimensions of this variable.
* The dimensions are those of the grid, not the dimensions of the coordinate system.
*/
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java [UTF-8] Thu May 23 11:19:57 2013
@@ -304,7 +304,7 @@ public final class DecoderWrapper extend
}
geometries = new GridGeometry[(systems != null) ? systems.size() : 0];
for (int i=0; i<geometries.length; i++) {
- geometries[i] = new GridGeometryWrapper(this, systems.get(i));
+ geometries[i] = new GridGeometryWrapper(systems.get(i));
}
}
return geometries;
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java [UTF-8] Thu May 23 11:19:57 2013
@@ -24,7 +24,6 @@ import ucar.nc2.dataset.CoordinateAxis2D
import ucar.nc2.dataset.CoordinateSystem;
import org.apache.sis.internal.netcdf.Axis;
import org.apache.sis.internal.netcdf.GridGeometry;
-import org.apache.sis.internal.netcdf.WarningProducer;
import org.apache.sis.storage.netcdf.AttributeNames;
import org.apache.sis.util.ArraysExt;
@@ -52,13 +51,11 @@ final class GridGeometryWrapper extends
private transient CoordinateAxis2D axis2D;
/**
- * Creates a new CRS builder.
+ * Creates a new grid geometry for the given NetCDF coordinate system.
*
- * @param parent Where to send the warnings, or {@code null} if none.
* @param cs The NetCDF coordinate system, or {@code null} if none.
*/
- GridGeometryWrapper(final WarningProducer parent, final CoordinateSystem cs) {
- super(parent);
+ GridGeometryWrapper(final CoordinateSystem cs) {
netcdfCS = cs;
}
@@ -82,6 +79,9 @@ final class GridGeometryWrapper extends
* Returns all axes of the NetCDF coordinate system, together with the grid dimension to which the axis
* is associated.
*
+ * <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>
+ *
* <p>The domain of all axes (or the {@linkplain CoordinateSystem#getDomain() coordinate system domain})
* is often the same than the {@linkplain #getDomain() domain of the variable}, but not necessarily.
* In particular, the relationship is not straightforward when the coordinate system contains instances
@@ -89,19 +89,19 @@ final class GridGeometryWrapper extends
*/
@Override
public Axis[] getAxes() {
- final List<Dimension> sourceDimensions = netcdfCS.getDomain();
- final List<CoordinateAxis> netcdfAxes = netcdfCS.getCoordinateAxes();
- int targetDim = netcdfAxes.size();
+ final List<Dimension> domain = netcdfCS.getDomain();
+ final List<CoordinateAxis> range = netcdfCS.getCoordinateAxes();
+ int targetDim = range.size();
final Axis[] axes = new Axis[targetDim];
/*
* NetCDF files declare axes in reverse order, so we iterate in the 'netcdfAxes'
* list in reverse order for adding to the 'axes' list in "natural" order.
*/
while (--targetDim >= 0) {
- final CoordinateAxis netcdfAxis = netcdfAxes.get(targetDim);
- final List<Dimension> dimensions = netcdfAxis.getDimensions();
+ final CoordinateAxis axis = range.get(targetDim);
+ final List<Dimension> axisDomain = axis.getDimensions();
AttributeNames.Dimension attributeNames = null;
- final AxisType type = netcdfAxis.getAxisType();
+ final AxisType type = axis.getAxisType();
if (type != null) switch (type) {
case Lon: attributeNames = AttributeNames.LONGITUDE; break;
case Lat: attributeNames = AttributeNames.LATITUDE; break;
@@ -116,10 +116,10 @@ final class GridGeometryWrapper extends
* straightforward NetCDF files. However some more complex files may have 2 dimensions.
*/
int i = 0;
- final int[] indices = new int[dimensions.size()];
+ final int[] indices = new int[axisDomain.size()];
final int[] sizes = new int[indices.length];
- for (final Dimension dimension : dimensions) {
- final int sourceDim = sourceDimensions.indexOf(dimension);
+ for (final Dimension dimension : axisDomain) {
+ final int sourceDim = domain.lastIndexOf(dimension);
if (sourceDim >= 0) {
indices[i] = sourceDim;
sizes[i++] = dimension.getLength();
@@ -130,8 +130,10 @@ final class GridGeometryWrapper extends
* package, we can proceed as if the dimension does not exist.
*/
}
- axis2D = (netcdfAxis instanceof CoordinateAxis2D) ? (CoordinateAxis2D) netcdfAxis : null;
- axes[targetDim] = new Axis(this, attributeNames, ArraysExt.resize(indices, i), ArraysExt.resize(sizes, i));
+ axis2D = (axis instanceof CoordinateAxis2D) ? (CoordinateAxis2D) axis : null;
+ axes[targetDim] = new Axis(this, attributeNames,
+ ArraysExt.resize(indices, i),
+ ArraysExt.resize(sizes, i));
}
axis2D = null;
return axes;
Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java?rev=1485646&r1=1485645&r2=1485646&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/GridGeometryTest.java [UTF-8] Thu May 23 11:19:57 2013
@@ -40,13 +40,26 @@ import static org.apache.sis.test.TestUt
@DependsOn(VariableTest.class)
public strictfp class GridGeometryTest extends TestCase {
/**
+ * Optionally filters out some grid geometries that shall be ignored by the tests.
+ * The default implementation returns the given array unmodified. This method is overridden by
+ * {@code GridGeometryInfoTest} in order to ignore one-dimensional coordinate systems created
+ * by {@code GridGeometry} but not by the UCAR library.
+ *
+ * @param geometries The grid geometries created by {@link Decoder}.
+ * @return The grid geometries to test.
+ */
+ protected GridGeometry[] filter(final GridGeometry[] geometries) {
+ return geometries;
+ }
+
+ /**
* Tests {@link GridGeometry#getSourceDimensions()} and {@link GridGeometry#getTargetDimensions()}.
*
* @throws IOException If an error occurred while reading the NetCDF file.
*/
@Test
public void testDimensions() throws IOException {
- final GridGeometry geometry = getSingleton(selectDataset(NCEP).getGridGeometries());
+ final GridGeometry geometry = getSingleton(filter(selectDataset(NCEP).getGridGeometries()));
assertEquals("getSourceDimensions()", 3, geometry.getSourceDimensions());
assertEquals("getTargetDimensions()", 3, geometry.getTargetDimensions());
}
@@ -59,7 +72,7 @@ public strictfp class GridGeometryTest e
@Test
@DependsOnMethod("testDimensions")
public void testAxes() throws IOException {
- final Axis[] axes = getSingleton(selectDataset(NCEP).getGridGeometries()).getAxes();
+ final Axis[] axes = getSingleton(filter(selectDataset(NCEP).getGridGeometries())).getAxes();
assertEquals(3, axes.length);
final Axis x = axes[2];
final Axis y = axes[1];
Added: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java?rev=1485646&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java (added)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java [UTF-8] Thu May 23 11:19:57 2013
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.netcdf.impl;
+
+import java.io.IOException;
+import org.apache.sis.internal.netcdf.Decoder;
+import org.apache.sis.internal.netcdf.GridGeometry;
+import org.apache.sis.internal.netcdf.GridGeometryTest;
+import org.apache.sis.util.ArraysExt;
+import org.apache.sis.test.DependsOn;
+
+
+/**
+ * Tests the {@link GridGeometry} implementation. This test shall be executed only if the
+ * {@link GridGeometryTest} tests, which use the UCAR library has a reference implementation,
+ * passed.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+@DependsOn({VariableInfoTest.class, GridGeometryTest.class})
+public final strictfp class GridGeometryInfoTest extends GridGeometryTest {
+ /**
+ * Creates a new decoder for dataset of the given name.
+ */
+ @Override
+ protected Decoder createDecoder(final String name) throws IOException {
+ return ChannelDecoderTest.createChannelDecoder(name);
+ }
+
+ /**
+ * Unconditionally returns {@code false} since {@link ChannelDecoder}
+ * supports only the classic and 64 bits NetCDF formats.
+ */
+ @Override
+ protected boolean isSupplementalFormatSupported(final String format) {
+ return false;
+ }
+
+ /**
+ * Filters out the one-dimensional coordinate systems created by {@code GridGeometry}
+ * but not by the UCAR library.
+ */
+ @Override
+ protected GridGeometry[] filter(final GridGeometry[] geometries) {
+ final GridGeometry[] copy = new GridGeometry[geometries.length];
+ int count = 0;
+ for (final GridGeometry geometry : geometries) {
+ if (geometry.getSourceDimensions() != 1 || geometry.getTargetDimensions() != 1) {
+ copy[count++] = geometry;
+ }
+ }
+ return ArraysExt.resize(copy, count);
+ }
+}
Propchange: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfoTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8