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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 34034e0 Miscellaneous fixes: typos, missing cause in chained
exception, use of scientific number notation, reduce the amount of searches of
vertical datum in EPSG database.
34034e0 is described below
commit 34034e03edd34cf120a905d8ef401ac7962641f1
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Jan 9 20:28:39 2019 +0100
Miscellaneous fixes: typos, missing cause in chained exception, use of
scientific number notation, reduce the amount of searches of vertical datum in
EPSG database.
---
.../feature/jts/GeometryCoordinateTransform.java | 2 +-
.../main/java/org/apache/sis/io/wkt/Symbols.java | 2 +-
.../org/apache/sis/coverage/SampleRangeFormat.java | 17 +++---------
.../grid/IllegalGridGeometryException.java | 2 +-
.../referencing/factory/sql/EPSGDataAccess.java | 16 +++++++++--
.../org/apache/sis/internal/util/Numerics.java | 31 ++++++++++++++++++++++
.../java/org/apache/sis/measure/RangeFormat.java | 14 ++++++----
.../org/apache/sis/internal/netcdf/Variable.java | 3 ++-
8 files changed, 62 insertions(+), 25 deletions(-)
diff --git
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/GeometryCoordinateTransform.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/GeometryCoordinateTransform.java
index 43269e0..bc73bcb 100644
---
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/GeometryCoordinateTransform.java
+++
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/GeometryCoordinateTransform.java
@@ -32,7 +32,7 @@ import org.opengis.referencing.operation.TransformException;
* @since 1.0
* @module
*/
-public class GeometryCoordinateTransform extends GeometryTransform {
+final class GeometryCoordinateTransform extends GeometryTransform {
/**
* The transform to apply on coordinate values.
*/
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java
b/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java
index 2ef44bf..7270658 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Symbols.java
@@ -82,7 +82,7 @@ public class Symbols implements Localized, Cloneable,
Serializable {
private static final long serialVersionUID = -1730166945430878916L;
/**
- * Set to {@code true} if parsing and formatting of number in scientific
notation is allowed.
+ * Set to {@code true} if parsing and formatting of numbers in scientific
notation is allowed.
* The way to achieve that is currently a hack, because {@link
NumberFormat} has no API for
* managing that as of JDK 1.8.
*
diff --git
a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
index 57c46c2..4a1e1df 100644
---
a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
+++
b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
@@ -20,7 +20,7 @@ import java.util.Locale;
import java.text.NumberFormat;
import java.io.IOException;
import java.io.UncheckedIOException;
-import java.text.DecimalFormat;
+import java.text.Format;
import org.opengis.util.GenericName;
import org.apache.sis.io.TableAppender;
import org.apache.sis.measure.Range;
@@ -134,20 +134,9 @@ final class SampleRangeFormat extends RangeFormat {
* We do that because the range may be repeated in the "Measure"
column with units.</li>
* </ul>
*/
- private String formatSample(Object value) {
+ private String formatSample(final Object value) {
if (value instanceof Number) {
- final double m = Math.abs(((Number) value).doubleValue());
- final String text;
- if (m > 0 && (m >= 1E+9 || m < 1E-4) && elementFormat instanceof
DecimalFormat) {
- final DecimalFormat df = (DecimalFormat) elementFormat;
- final String pattern = df.toPattern();
- df.applyPattern("0.######E00");
- text = df.format(value);
- df.applyPattern(pattern);
- } else {
- text = elementFormat.format(value);
- }
- return text.concat(" ");
+ return Numerics.useScientificNotationIfNeeded(elementFormat,
value, Format::format).concat(" ");
} else if (value instanceof Range<?>) {
if (value instanceof MeasurementRange<?>) {
/*
diff --git
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
index 1f2d0ee..7f7255f 100644
---
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
+++
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
@@ -69,6 +69,6 @@ public class IllegalGridGeometryException extends
IllegalArgumentException {
* @param component name of the parameter that caused the failure.
*/
IllegalGridGeometryException(final Throwable cause, final String
component) {
- super(Resources.format(Resources.Keys.IllegalGridGeometryComponent_1,
component));
+ super(Resources.format(Resources.Keys.IllegalGridGeometryComponent_1,
component), cause);
}
}
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
index e2cd4fb..986dcd3 100644
---
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
+++
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
@@ -160,7 +160,7 @@ import org.apache.sis.internal.util.StandardDateFormat;
* @author Matthias Basler
* @author Andrea Aime (TOPP)
* @author Johann Sorel (Geomatys)
- * @version 0.8
+ * @version 1.0
*
* @see <a
href="http://sis.apache.org/tables/CoordinateReferenceSystems.html">List of
authority codes</a>
*
@@ -171,6 +171,12 @@ public class EPSGDataAccess extends
GeodeticAuthorityFactory implements CRSAutho
CSAuthorityFactory, DatumAuthorityFactory,
CoordinateOperationAuthorityFactory, Localized, AutoCloseable
{
/**
+ * The vertical datum type, which is fixed to a hard-coded value for all
vertical datum for now.
+ * Note that vertical datum type is no longer part of ISO 19111:2007.
+ */
+ private static final VerticalDatumType VERTICAL_DATUM_TYPE =
VerticalDatumType.GEOIDAL;
+
+ /**
* The deprecated ellipsoidal coordinate systems and their replacements.
Those coordinate systems are deprecated
* because they use a unit of measurement which is no longer supported by
OGC (for example degree-minute-second).
* Those replacements can be used only if the ellipsoidal CS is used for
the base geographic CRS of a derived or
@@ -1671,7 +1677,7 @@ addURIs: for (int i=0; ; i++) {
* ISO 19111:2007, it is probably not worth to handle such
cases.
*/
case "vertical": {
- datum = datumFactory.createVerticalDatum(properties,
VerticalDatumType.GEOIDAL);
+ datum = datumFactory.createVerticalDatum(properties,
VERTICAL_DATUM_TYPE);
break;
}
/*
@@ -3131,6 +3137,12 @@ next: while (r.next()) {
where = "ELLIPSOID_CODE";
table = TableInfo.DATUM;
} else {
+ if (object instanceof VerticalDatum) {
+ final VerticalDatumType type = ((VerticalDatum)
object).getVerticalDatumType();
+ if (type != null && !type.equals(VERTICAL_DATUM_TYPE))
{
+ return Collections.emptySet();
+ }
+ }
// Not a supported type. Returns all codes.
return super.getCodeCandidates(object);
}
diff --git
a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
index 3e4e0bd..be52a51 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
@@ -18,8 +18,12 @@ package org.apache.sis.internal.util;
import java.util.Map;
import java.util.HashMap;
+import java.text.Format;
+import java.text.DecimalFormat;
+import java.util.function.BiFunction;
import org.apache.sis.util.Debug;
import org.apache.sis.util.Static;
+import org.apache.sis.util.Workaround;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.math.DecimalFunctions;
import org.opengis.referencing.operation.Matrix; // For javadoc
@@ -521,4 +525,31 @@ public final class Numerics extends Static {
}
return fractionDigits;
}
+
+ /**
+ * Formats the given value with the given format, using scientific
notation if needed.
+ * This is a workaround for {@link DecimalFormat} not switching
automatically to scientific notation for large numbers.
+ *
+ * @param format the format to use for formatting the given value.
+ * @param value the value to format.
+ * @param action the method to invoke. Typically {@code Format::format}.
+ * @return the result of {@code action}.
+ */
+ @Workaround(library="JDK", version="10")
+ public static String useScientificNotationIfNeeded(final Format format,
final Object value, final BiFunction<Format,Object,String> action) {
+ if (value instanceof Number) {
+ final double m = Math.abs(((Number) value).doubleValue());
+ if (m > 0 && (m >= 1E+9 || m < 1E-4) && format instanceof
DecimalFormat) {
+ final DecimalFormat df = (DecimalFormat) format;
+ final String pattern = df.toPattern();
+ df.applyPattern("0.######E00");
+ try {
+ return action.apply(format, value);
+ } finally {
+ df.applyPattern(pattern);
+ }
+ }
+ }
+ return action.apply(format, value);
+ }
}
diff --git
a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
index 0fa5b89..e468fc6 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
@@ -40,6 +40,7 @@ import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.UnconvertibleObjectException;
import org.apache.sis.internal.util.LocalizedParseException;
import org.apache.sis.internal.util.FinalFieldSetter;
+import org.apache.sis.internal.util.Numerics;
/**
@@ -630,11 +631,14 @@ public class RangeFormat extends Format implements
Localized {
} else {
format = elementFormat;
}
- if (characterIterator != null) {
-
characterIterator.append(format.formatToCharacterIterator(value), toAppendTo);
- } else {
- format.format(value, toAppendTo, new FieldPosition(-1));
- }
+ Numerics.useScientificNotationIfNeeded(format, value, (f,v) ->
{
+ if (characterIterator != null) {
+
characterIterator.append(f.formatToCharacterIterator(v), toAppendTo);
+ } else {
+ f.format(v, toAppendTo, new FieldPosition(-1));
+ }
+ return null;
+ });
}
/*
* At this point, the field has been formatted. Now store the
field index,
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 4d825cf..62e857a 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
@@ -213,12 +213,13 @@ public abstract class Variable extends NamedElement {
if (overwrite != null) {
unit = overwrite;
}
+ unitParsed = true;
return epoch;
}
/**
* Returns the unit of measurement for this variable, or {@code null} if
unknown.
- * This method parse the units from {@link #getUnitsString()} when first
needed
+ * This method parses the units from {@link #getUnitsString()} when first
needed
* and sets {@link #epoch} as a side-effect if the unit is temporal.
*
* @return the unit of measurement, or {@code null}.