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/13 13:08:46 UTC
svn commit: r1481790 - in /sis/branches/JDK7:
core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/
storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/
Author: desruisseaux
Date: Mon May 13 11:08:45 2013
New Revision: 1481790
URL: http://svn.apache.org/r1481790
Log:
Leverage DefaultTemporalExtent.setBounds(Data, Date) in NetCDF metadata reader,
and remove the last direct dependency to UCAR library (so we can keep it optional).
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Decoder.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/DecoderUCAR.java
sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java?rev=1481790&r1=1481789&r2=1481790&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java [UTF-8] Mon May 13 11:08:45 2013
@@ -40,6 +40,7 @@ import org.apache.sis.internal.metadata.
* <ul>
* <li>{@link #getStartTime()} for fetching the start time from the temporal primitive.</li>
* <li>{@link #getEndTime()} for fetching the end time from the temporal primitive.</li>
+ * <li>{@link #setBounds(Date, Date)} for setting the extent from the given start and end time.</li>
* <li>{@link #setBounds(Envelope)} for setting the extent from the given envelope.</li>
* </ul>
*
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Decoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Decoder.java?rev=1481790&r1=1481789&r2=1481790&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Decoder.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/Decoder.java [UTF-8] Mon May 13 11:08:45 2013
@@ -131,6 +131,15 @@ abstract class Decoder {
}
/**
+ * Converts the given numerical values to date, using the information provided in the given unit symbol.
+ * The unit symbol is typically a string like "<cite>days since 1970-01-01T00:00:00Z</cite>".
+ *
+ * @param values The values to convert. May contains {@code null} elements.
+ * @return The converted values. May contains {@code null} elements.
+ */
+ public abstract Date[] numberToDate(final String symbol, final Number... values);
+
+ /**
* Returns the value of the {@code "_Id"} global attribute. The UCAR library defines a
* {@link ucar.nc2.NetcdfFile#getId()} method for that purpose, which we will use when
* possible in case that {@code getId()} method is defined in an other way.
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/DecoderUCAR.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/DecoderUCAR.java?rev=1481790&r1=1481789&r2=1481790&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/DecoderUCAR.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/DecoderUCAR.java [UTF-8] Mon May 13 11:08:45 2013
@@ -20,6 +20,7 @@ import java.util.Date;
import ucar.nc2.Group;
import ucar.nc2.Attribute;
import ucar.nc2.NetcdfFile;
+import ucar.nc2.units.DateUnit;
import ucar.nc2.time.Calendar;
import ucar.nc2.time.CalendarDate;
import ucar.nc2.time.CalendarDateFormatter;
@@ -210,6 +211,32 @@ final class DecoderUCAR extends Decoder
}
/**
+ * Converts the given numerical values to date, using the information provided in the given unit symbol.
+ * The unit symbol is typically a string like "<cite>days since 1970-01-01T00:00:00Z</cite>".
+ *
+ * @param values The values to convert. May contains {@code null} elements.
+ * @return The converted values. May contains {@code null} elements.
+ */
+ @Override
+ public Date[] numberToDate(final String symbol, final Number... values) {
+ final Date[] dates = new Date[values.length];
+ final DateUnit unit;
+ try {
+ unit = new DateUnit(symbol);
+ } catch (Exception e) { // Declared by the DateUnit constructor.
+ warning("numberToDate", e);
+ return dates;
+ }
+ for (int i=0; i<values.length; i++) {
+ final Number value = values[i];
+ if (value != null) {
+ dates[i] = unit.makeDate(value.doubleValue());
+ }
+ }
+ return dates;
+ }
+
+ /**
* Returns the globally unique dataset identifier as determined by the UCAR library.
*/
@Override
Modified: sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1481790&r1=1481789&r2=1481790&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] Mon May 13 11:08:45 2013
@@ -35,9 +35,6 @@ import javax.measure.unit.NonSI;
import javax.measure.converter.UnitConverter;
import javax.measure.converter.ConversionException;
-import ucar.nc2.constants.CF;
-import ucar.nc2.units.DateUnit;
-
import org.opengis.util.NameFactory;
import org.opengis.util.InternationalString;
import org.opengis.metadata.Metadata;
@@ -69,6 +66,10 @@ import org.apache.sis.metadata.iso.linea
import org.apache.sis.metadata.iso.quality.DefaultDataQuality;
import org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints;
+// The following dependency is used only for static final String constants.
+// Consequently the compiled class files should not have this dependency.
+import ucar.nc2.constants.CF;
+
import static org.apache.sis.storage.netcdf.AttributeNames.*;
@@ -594,18 +595,21 @@ final class MetadataReader {
final Number ymax = decoder.numericValue(LATITUDE .MAXIMUM);
final Number zmin = decoder.numericValue(VERTICAL .MINIMUM);
final Number zmax = decoder.numericValue(VERTICAL .MAXIMUM);
+ /*
+ * If at least one geographic ordinates above is available, add a GeographicBoundingBox.
+ */
if (xmin != null || xmax != null || ymin != null || ymax != null) {
- extent = new DefaultExtent();
final UnitConverter xConv = getConverterTo(decoder.unitValue(LONGITUDE.UNITS), NonSI.DEGREE_ANGLE);
final UnitConverter yConv = getConverterTo(decoder.unitValue(LATITUDE .UNITS), NonSI.DEGREE_ANGLE);
+ extent = new DefaultExtent();
extent.getGeographicElements().add(new DefaultGeographicBoundingBox(
valueOf(xmin, xConv), valueOf(xmax, xConv),
valueOf(ymin, yConv), valueOf(ymax, yConv)));
}
+ /*
+ * If at least one vertical ordinates above is available, add a VerticalExtent.
+ */
if (zmin != null || zmax != null) {
- if (extent == null) {
- extent = new DefaultExtent();
- }
final UnitConverter c = getConverterTo(decoder.unitValue(VERTICAL.UNITS), SI.METRE);
double min = valueOf(zmin, c);
double max = valueOf(zmax, c);
@@ -614,10 +618,14 @@ final class MetadataReader {
min = -max;
max = -tmp;
}
+ if (extent == null) {
+ extent = new DefaultExtent();
+ }
extent.getVerticalElements().add(new DefaultVerticalExtent(min, max, VERTICAL_CRS));
}
/*
- * Temporal extent.
+ * Get the start and end times as Date objects if available, or as numeric values otherwise.
+ * In the later case, the unit symbol tells how to convert to Date objects.
*/
Date startTime = decoder.dateValue(TIME.MINIMUM);
Date endTime = decoder.dateValue(TIME.MAXIMUM);
@@ -626,21 +634,31 @@ final class MetadataReader {
final Number tmax = decoder.numericValue(TIME.MAXIMUM);
if (tmin != null || tmax != null) {
final String symbol = decoder.stringValue(TIME.UNITS);
- if (symbol != null) try {
- final DateUnit unit = new DateUnit(symbol);
- if (tmin != null) startTime = unit.makeDate(tmin.doubleValue());
- if (tmax != null) endTime = unit.makeDate(tmax.doubleValue());
- } catch (Exception e) { // Declared by the DateUnit constructor.
- warning("createExtent", e);
+ if (symbol != null) {
+ final Date[] dates = decoder.numberToDate(symbol, tmin, tmax);
+ startTime = dates[0];
+ endTime = dates[1];
}
}
}
- if (startTime != null || endTime != null) {
+ /*
+ * If at least one time values above is available, add a temporal extent.
+ * This operation requires the the sis-temporal module. If not available,
+ * we will report a warning and leave the temporal extent missing.
+ */
+ if (startTime != null || endTime != null) try {
+ final DefaultTemporalExtent t = new DefaultTemporalExtent();
+ t.setBounds(startTime, endTime);
if (extent == null) {
extent = new DefaultExtent();
}
- extent.getTemporalElements().add(new DefaultTemporalExtent(/*startTime, endTime*/)); // TODO
+ extent.getTemporalElements().add(t);
+ } catch (UnsupportedOperationException e) {
+ warning("createExtent", e);
}
+ /*
+ * Add the geographic identifier, if present.
+ */
final String identifier = decoder.stringValue(GEOGRAPHIC_IDENTIFIER);
if (identifier != null) {
if (extent == null) {