Author: desruisseaux
Date: Wed Oct 11 14:12:56 2017
New Revision: 1811827
URL: http://svn.apache.org/viewvc?rev=1811827&view=rev
Log:
Add a CRS.compound(CoordinateReferenceSystem...) convenience method.
This task implied adding other methods for computing domain of validity
intersection.
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/AxisDirections.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombiner.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultExtent.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombinerTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ServicesForMetadataTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/PrimitiveTypeProperties.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/AxisDirections.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/AxisDirections.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/AxisDirections.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/AxisDirections.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -429,22 +429,22 @@ public final class AxisDirections extend
* Returns the angular unit of the specified coordinate system.
* The preference will be given to the longitude axis, if found.
*
- * @param cs the coordinate system from which to get the angular unit,
or {@code null}.
- * @param unit the default unit to return if no angular unit is found.
+ * @param cs the coordinate system from which to get the angular
unit, or {@code null}.
+ * @param fallback the default unit to return if no angular unit is
found.
* @return the angular unit, of {@code unit} if no angular unit was found.
*
* @see
org.apache.sis.internal.referencing.ReferencingUtilities#getUnit(CoordinateSystem)
*
* @since 0.6
*/
- public static Unit<Angle> getAngularUnit(final CoordinateSystem cs,
Unit<Angle> unit) {
+ public static Unit<Angle> getAngularUnit(final CoordinateSystem cs,
Unit<Angle> fallback) {
if (cs != null) {
for (int i = cs.getDimension(); --i>=0;) {
final CoordinateSystemAxis axis = cs.getAxis(i);
if (axis != null) {
// Paranoiac check.
final Unit<?> candidate = axis.getUnit();
if (Units.isAngular(candidate)) {
- unit = candidate.asType(Angle.class);
+ fallback = candidate.asType(Angle.class);
if
(AxisDirection.EAST.equals(absolute(axis.getDirection()))) {
break;
// Found the longitude axis.
}
@@ -452,7 +452,7 @@ public final class AxisDirections extend
}
}
}
- return unit;
+ return fallback;
}
/**
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombiner.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombiner.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombiner.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombiner.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -17,6 +17,8 @@
package org.apache.sis.internal.metadata;
import java.util.Map;
+import java.util.HashMap;
+import org.opengis.metadata.extent.Extent;
import org.opengis.referencing.crs.CRSFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.crs.GeodeticCRS;
@@ -32,6 +34,8 @@ import org.opengis.referencing.datum.Ver
import org.opengis.referencing.operation.Conversion;
import org.opengis.referencing.operation.CoordinateOperationFactory;
import org.opengis.util.FactoryException;
+import org.apache.sis.metadata.iso.extent.Extents;
+import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.ArraysExt;
@@ -204,4 +208,27 @@ public class EllipsoidalHeightCombiner {
}
return null;
}
+
+ /**
+ * Suggests properties for a compound CRS made of the given elements.
+ * This method builds a default CRS name and domain of validity.
+ *
+ * @param components the components for which to get a default set of
properties.
+ * @return suggested properties in a modifiable map. Callers can modify
the returned map.
+ */
+ public static Map<String,Object> properties(final
CoordinateReferenceSystem... components) {
+ final StringBuilder name = new StringBuilder(40);
+ Extent domain = null;
+ for (int i=0; i<components.length; i++) {
+ final CoordinateReferenceSystem crs = components[i];
+ ArgumentChecks.ensureNonNullElement("components", i, crs);
+ if (i != 0) name.append(" + ");
+ name.append(crs.getName().getCode());
+ domain = Extents.intersection(domain, crs.getDomainOfValidity());
+ }
+ final Map<String,Object> properties = new HashMap<>(2);
+ properties.put(CoordinateReferenceSystem.NAME_KEY, name.toString());
+ properties.put(CoordinateReferenceSystem.DOMAIN_OF_VALIDITY_KEY,
domain);
+ return properties;
+ }
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -505,6 +505,8 @@ public class ReferencingServices extends
* If the given properties are empty and the {@code mtFactory} is the
system default, then this method
* returns the system default {@code CoordinateOperationFactory} instead
of creating a new one.
*
+ * <p>It is okay to set all parameters to {@code null} in order to get the
system default factory.</p>
+ *
* @param properties the default properties.
* @param mtFactory the math transform factory to use.
* @param crsFactory the factory to use if the operation factory needs
to create CRS for intermediate steps.
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultExtent.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultExtent.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultExtent.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultExtent.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -16,7 +16,10 @@
*/
package org.apache.sis.metadata.iso.extent;
+import java.util.Set;
+import java.util.LinkedHashSet;
import java.util.Collection;
+import java.util.function.BinaryOperator;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -29,9 +32,14 @@ import org.opengis.metadata.extent.Geogr
import org.opengis.referencing.operation.TransformException;
import org.opengis.util.InternationalString;
import org.apache.sis.util.iso.Types;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.collection.Containers;
+import org.apache.sis.metadata.AbstractMetadata;
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.metadata.TitleProperty;
import org.apache.sis.internal.metadata.ReferencingServices;
+import org.apache.sis.xml.NilObject;
+import org.apache.sis.xml.NilReason;
/**
@@ -74,7 +82,7 @@ import org.apache.sis.internal.metadata.
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
- * @version 0.3
+ * @version 0.8
*
* @see Extents#getGeographicBoundingBox(Extent)
* @see
org.apache.sis.referencing.AbstractReferenceSystem#getDomainOfValidity()
@@ -289,6 +297,85 @@ public class DefaultExtent extends ISOMe
*/
public void addElements(final Envelope envelope) throws TransformException
{
checkWritePermission();
+ ArgumentChecks.ensureNonNull("envelope", envelope);
ReferencingServices.getInstance().addElements(envelope, this);
}
+
+ /**
+ * Sets this extent to the intersection of this extent with the specified
one.
+ * This method computes the intersections of all geographic, vertical and
temporal elements in this extent
+ * with all geographic, vertical and temporal elements in the other
extent, ignoring duplicated results.
+ *
+ * @param other the extent to intersect with this extent.
+ * @throws IllegalArgumentException if two elements to intersect are not
compatible (e.g. mismatched
+ * {@linkplain DefaultGeographicBoundingBox#getInclusion()
bounding box inclusion status} or
+ * mismatched {@linkplain DefaultVerticalExtent#getVerticalCRS()
vertical datum}).
+ * @throws UnsupportedOperationException if a {@code TemporalFactory} is
required but no implementation
+ * has been found on the classpath.
+ *
+ * @see Extents#intersection(Extent, Extent)
+ * @see org.apache.sis.geometry.GeneralEnvelope#intersect(Envelope)
+ *
+ * @since 0.8
+ */
+ public void intersect(final Extent other) {
+ checkWritePermission();
+ ArgumentChecks.ensureNonNull("other", other);
+ final InternationalString od = other.getDescription();
+ if (od != null && !(description instanceof NilObject)) {
+ if (description == null || (od instanceof NilObject)) {
+ description = od;
+ } else if (!description.equals(od)) {
+ description =
NilReason.MISSING.createNilObject(InternationalString.class);
+ }
+ }
+ geographicElements = intersect(GeographicExtent.class,
geographicElements, other.getGeographicElements(), Extents::intersection);
+ verticalElements = intersect(VerticalExtent.class,
verticalElements, other.getVerticalElements(), Extents::intersection);
+ temporalElements = intersect(TemporalExtent.class,
temporalElements, other.getTemporalElements(), Extents::intersection);
+ }
+
+ /**
+ * Computes the intersections of all elements in the given {@code sources}
collection will all elements
+ * in the given {@code targets} collection. If one of those collections is
null or empty, this method
+ * returns all elements of the other collection (may be {@code targets}
itself).
+ *
+ * @param <T> compile-time value of {@code type} argument.
+ * @param type the type of elements in the collections.
+ * @param targets the elements in this {@code DefaultExtent}. Also the
collection where results will be stored.
+ * @param sources the elements from the other {@code Extent} to
intersect with this extent.
+ * @param intersect the function computing intersections.
+ * @return the intersection results. May be the same instance than {@code
targets} with elements replaced.
+ */
+ private <T> Collection<T> intersect(final Class<T> type, Collection<T>
targets, Collection<? extends T> sources, final BinaryOperator<T> intersect) {
+ if (!Containers.isNullOrEmpty(sources)) {
+ if (!Containers.isNullOrEmpty(targets)) {
+ final Set<T> results = new
LinkedHashSet<>(Containers.hashMapCapacity(targets.size()));
+ T empty = null;
+ for (final T target : targets) {
+ for (final T source : sources) {
+ final T e = intersect.apply(target, source);
+ results.add(e);
+ /*
+ * If the two elements do not intersect, remember the
value created by the intersection method
+ * for meaning "no intersection". We remember only
the first value since we always create the
+ * same value for meaning "no intersection".
+ */
+ if (empty == null && e != source && e != target && (e
instanceof AbstractMetadata) && ((AbstractMetadata) e).isEmpty()) {
+ empty = e;
+ }
+ }
+ }
+ /*
+ * Remove the "no intersection" value, unless this is the only
result.
+ */
+ results.remove(null);
+ if (results.size() > 1) {
+ results.remove(empty);
+ }
+ sources = results;
+ }
+ targets = writeCollection(sources, targets, type);
+ }
+ return targets;
+ }
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -536,7 +536,7 @@ public class DefaultGeographicBoundingBo
ArgumentChecks.ensureNonNull("box", box);
setBounds(box.getWestBoundLongitude(), box.getEastBoundLongitude(),
box.getSouthBoundLatitude(), box.getNorthBoundLatitude());
- setInclusion(box.getInclusion()); // Set only on success.
+ setInclusion(box.getInclusion()); // Set
only on success.
}
/*
@@ -650,6 +650,7 @@ public class DefaultGeographicBoundingBo
*/
public void add(final GeographicBoundingBox box) {
checkWritePermission();
+ ArgumentChecks.ensureNonNull("box", box);
double λmin = box.getWestBoundLongitude();
double λmax = box.getEastBoundLongitude();
double φmin = box.getSouthBoundLatitude();
@@ -707,6 +708,7 @@ public class DefaultGeographicBoundingBo
*/
public void intersect(final GeographicBoundingBox box) throws
IllegalArgumentException {
checkWritePermission();
+ ArgumentChecks.ensureNonNull("box", box);
if (getInclusion(getInclusion()) != getInclusion(box.getInclusion())) {
throw new
IllegalArgumentException(Errors.format(Errors.Keys.IncompatiblePropertyValue_1,
"inclusion"));
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -31,6 +31,8 @@ import org.opengis.referencing.operation
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.internal.util.TemporalUtilities;
import org.apache.sis.internal.metadata.ReferencingServices;
+import org.apache.sis.xml.NilObject;
+import org.apache.sis.xml.NilReason;
/**
@@ -60,7 +62,7 @@ import org.apache.sis.internal.metadata.
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
- * @version 0.3
+ * @version 0.8
* @since 0.3
* @module
*/
@@ -242,4 +244,49 @@ public class DefaultTemporalExtent exten
checkWritePermission();
ReferencingServices.getInstance().setBounds(envelope, this);
}
+
+ /**
+ * Sets this temporal extent to the intersection of this extent with the
specified one.
+ * If there is no intersection between the two extents, then this method
sets the temporal primitive to nil.
+ * If either this extent or the specified extent has nil primitive, then
the intersection result will also be nil.
+ *
+ * @param other the temporal extent to intersect with this extent.
+ * @throws UnsupportedOperationException if no implementation of {@code
TemporalFactory} has been found
+ * on the classpath.
+ *
+ * @see Extents#intersection(TemporalExtent, TemporalExtent)
+ * @see org.apache.sis.geometry.GeneralEnvelope#intersect(Envelope)
+ *
+ * @since 0.8
+ */
+ public void intersect(final TemporalExtent other) {
+ checkWritePermission();
+ final TemporalPrimitive ot = other.getExtent();
+ if (ot != null && !(extent instanceof NilObject)) {
+ if (extent == null || (ot instanceof NilObject)) {
+ extent = ot;
+ } else {
+ Date t0 = getTime(extent, true);
+ Date t1 = getTime(extent, false);
+ Date h0 = getTime(ot, true);
+ Date h1 = getTime(ot, false);
+ boolean changed = false;
+ if (h0 != null && (t0 == null || h0.after(t0))) {
+ t0 = h0;
+ changed = true;
+ }
+ if (h1 != null && (t1 == null || h1.before(t1))) {
+ t1 = h1;
+ changed = true;
+ }
+ if (changed) {
+ if (t0 != null && t1 != null && t0.after(t1)) {
+ extent =
NilReason.MISSING.createNilObject(TemporalPrimitive.class);
+ } else {
+ setBounds(t0, t1);
+ }
+ }
+ }
+ }
+ }
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -21,12 +21,20 @@ import javax.xml.bind.annotation.XmlElem
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.opengis.geometry.Envelope;
+import org.opengis.util.FactoryException;
import org.opengis.referencing.crs.VerticalCRS;
+import org.opengis.referencing.operation.MathTransform1D;
import org.opengis.referencing.operation.TransformException;
+import org.opengis.geometry.MismatchedReferenceSystemException;
import org.opengis.metadata.extent.VerticalExtent;
import org.apache.sis.metadata.iso.ISOMetadata;
import org.apache.sis.internal.jaxb.gco.GO_Real;
import org.apache.sis.internal.metadata.ReferencingServices;
+import org.apache.sis.math.MathFunctions;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.Utilities;
+import org.apache.sis.xml.NilReason;
/**
@@ -55,7 +63,7 @@ import org.apache.sis.internal.metadata.
* @author Martin Desruisseaux (IRD, Geomatys)
* @author Touraïvane (IRD)
* @author Cédric Briançon (Geomatys)
- * @version 0.3
+ * @version 0.8
* @since 0.3
* @module
*/
@@ -241,4 +249,118 @@ public class DefaultVerticalExtent exten
checkWritePermission();
ReferencingServices.getInstance().setBounds(envelope, this);
}
+
+ /**
+ * Sets this vertical extent to the intersection of this extent with the
specified one.
+ * The {@linkplain
org.apache.sis.referencing.crs.DefaultVerticalCRS#getDatum() vertical datum}
+ * must be the same (ignoring metadata) for both extents; this method does
not perform datum shift.
+ * However this method can perform unit conversions.
+ *
+ * <p>If there is no intersection between the two extents, then this
method sets both minimum and
+ * maximum values to {@linkplain Double#NaN}. If either this extent or the
specified extent has NaN
+ * bounds, then the corresponding bounds of the intersection result will
also be NaN.</p>
+ *
+ * @param other the vertical extent to intersect with this extent.
+ * @throws MismatchedReferenceSystemException if the two extents do not
use the same datum, ignoring metadata.
+ *
+ * @see Extents#intersection(VerticalExtent, VerticalExtent)
+ * @see org.apache.sis.geometry.GeneralEnvelope#intersect(Envelope)
+ *
+ * @since 0.8
+ */
+ public void intersect(final VerticalExtent other) throws
MismatchedReferenceSystemException {
+ checkWritePermission();
+ ArgumentChecks.ensureNonNull("other", other);
+ Double min = other.getMinimumValue();
+ Double max = other.getMaximumValue();
+ try {
+ final MathTransform1D cv =
getConversionFrom(other.getVerticalCRS());
+ if (isReversing(cv, min, max)) {
+ Double tmp = min;
+ min = max;
+ max = tmp;
+ }
+ /*
+ * If minimumValue is NaN, keep it unchanged (because x >
minimumValue is false)
+ * in order to preserve the NilReason. Conversely if min is NaN,
then we want to
+ * take it without conversion for preserving its NilReason.
+ */
+ if (min != null) {
+ if (minimumValue == null || min.isNaN() || (min = convert(cv,
min)) > minimumValue) {
+ minimumValue = min;
+ }
+ }
+ if (max != null) {
+ if (maximumValue == null || max.isNaN() || (max = convert(cv,
max)) < maximumValue) {
+ maximumValue = max;
+ }
+ }
+ } catch (UnsupportedOperationException | FactoryException |
ClassCastException | TransformException e) {
+ throw new
MismatchedReferenceSystemException(Errors.format(Errors.Keys.IncompatiblePropertyValue_1,
"verticalCRS"), e);
+ }
+ if (minimumValue != null && maximumValue != null && minimumValue >
maximumValue) {
+ minimumValue = maximumValue =
NilReason.MISSING.createNilObject(Double.class);
+ }
+ }
+
+ /**
+ * Returns the conversion from the given CRS to the CRS of this extent, or
{@code null} if none or unknown.
+ * The returned {@code MathTransform1D} may apply unit conversions or axis
direction reversal, but usually
+ * not datum shift.
+ *
+ * @param source the CRS from which to perform the conversions, or
{@code null} if unknown.
+ * @return the conversion from {@code source}, or {@code null} if none or
unknown.
+ * @throws UnsupportedOperationException if the {@code sis-referencing}
module is not on the classpath.
+ * @throws FactoryException if the coordinate operation factory is not
available.
+ * @throws ClassCastException if the conversion is not an instance of
{@link MathTransform1D}.
+ */
+ private MathTransform1D getConversionFrom(final VerticalCRS source) throws
FactoryException {
+ if (!Utilities.equalsIgnoreMetadata(verticalCRS, source) &&
verticalCRS != null && source != null) {
+ final MathTransform1D cv = (MathTransform1D)
ReferencingServices.getInstance()
+ .getCoordinateOperationFactory(null, null, null, null)
+ .createOperation(source, verticalCRS).getMathTransform();
+ if (!cv.isIdentity()) {
+ return cv;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns {@code true} if the given conversion seems to change the axis
direction.
+ * This happen for example with conversions from "Elevation" axis to
"Depth" axis.
+ * In case of doubt, this method returns {@code false}.
+ *
+ * <div class="note"><b>Note about alternatives:</b>
+ * we could compare axis directions instead, but it would not work with
user-defined directions
+ * or user-defined unit conversions with negative scale factor (should
never happen, but we are
+ * paranoiac). We could compare the minimum and maximum values after
conversions, but it would
+ * not work if one or both values are {@code null} or {@code NaN}. Since
we want to preserve
+ * {@link NilReason}, we still need to know if axes are reversed in order
to put the nil reason
+ * in the right location.</div>
+ *
+ * @param cv the conversion computed by {@link
#getConversionFrom(VerticalCRS)} (may be {@code null}).
+ * @param sample the minimum or the maximum value.
+ * @param other the minimum or maximum value at the opposite bound.
+ * @return {@code true} if the axis direction is reversed at the given
value.
+ */
+ private static boolean isReversing(final MathTransform1D cv, Double
sample, final Double other) throws TransformException {
+ if (cv == null) {
+ return false;
+ }
+ if (sample == null || sample.isNaN()) {
+ sample = other;
+ } else if (other != null && !other.isNaN()) {
+ sample = (sample + other) / 2;
+ }
+ return MathFunctions.isNegative(cv.derivative(sample != null ? sample
: Double.NaN));
+ }
+
+ /**
+ * Converts the given value with the given transform if non-null. This
converter can generally
+ * not perform datum shift; the operation is merely unit conversion and
change of axis direction.
+ */
+ private static Double convert(MathTransform1D tr, Double value) throws
TransformException {
+ return (tr != null) ? tr.transform(value) : value;
+ }
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -29,6 +29,8 @@ import org.opengis.metadata.extent.Tempo
import org.opengis.metadata.extent.BoundingPolygon;
import org.opengis.metadata.extent.GeographicExtent;
import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.extent.GeographicDescription;
+import org.opengis.geometry.MismatchedReferenceSystemException;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.crs.VerticalCRS;
@@ -45,6 +47,7 @@ import org.apache.sis.measure.Range;
import org.apache.sis.util.resources.Vocabulary;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.Static;
import static java.lang.Math.*;
@@ -436,33 +439,6 @@ public final class Extents extends Stati
}
/**
- * Returns the intersection of the given geographic bounding boxes. If any
of the arguments is {@code null},
- * then this method returns the other argument (which may be null).
Otherwise this method returns a box which
- * is the intersection of the two given boxes.
- *
- * <p>This method never modify the given boxes, but may return directly
one of the given arguments if it
- * already represents the intersection result.</p>
- *
- * @param b1 the first bounding box, or {@code null}.
- * @param b2 the second bounding box, or {@code null}.
- * @return the intersection (may be any of the {@code b1} or {@code b2}
argument if unchanged),
- * or {@code null} if the two given boxes are null.
- * @throws IllegalArgumentException if the {@linkplain
DefaultGeographicBoundingBox#getInclusion() inclusion status}
- * is not the same for both boxes.
- *
- * @see DefaultGeographicBoundingBox#intersect(GeographicBoundingBox)
- *
- * @since 0.4
- */
- public static GeographicBoundingBox intersection(final
GeographicBoundingBox b1, final GeographicBoundingBox b2) {
- if (b1 == null) return b2;
- if (b2 == null || b2 == b1) return b1;
- final DefaultGeographicBoundingBox box = new
DefaultGeographicBoundingBox(b1);
- box.intersect(b2);
- return box;
- }
-
- /**
* Returns an <em>estimation</em> of the area (in square metres) of the
given bounding box.
* Since {@code GeographicBoundingBox} provides only approximative
information (for example
* it does not specify the datum), the value returned by this method is
also approximative.
@@ -496,4 +472,145 @@ public final class Extents extends Stati
max(0, sin(toRadians(box.getNorthBoundLatitude())) -
sin(toRadians(box.getSouthBoundLatitude())));
}
+
+ /**
+ * Returns the intersection of the given geographic bounding boxes. If any
of the arguments is {@code null},
+ * then this method returns the other argument (which may be null).
Otherwise this method returns a box which
+ * is the intersection of the two given boxes.
+ *
+ * <p>This method never modify the given boxes, but may return directly
one of the given arguments if it
+ * already represents the intersection result.</p>
+ *
+ * @param b1 the first bounding box, or {@code null}.
+ * @param b2 the second bounding box, or {@code null}.
+ * @return the intersection (may be any of the {@code b1} or {@code b2}
argument if unchanged),
+ * or {@code null} if the two given boxes are null.
+ * @throws IllegalArgumentException if the {@linkplain
DefaultGeographicBoundingBox#getInclusion() inclusion status}
+ * is not the same for both boxes.
+ *
+ * @see DefaultGeographicBoundingBox#intersect(GeographicBoundingBox)
+ *
+ * @since 0.4
+ */
+ public static GeographicBoundingBox intersection(final
GeographicBoundingBox b1, final GeographicBoundingBox b2) {
+ if (b1 == null) return b2;
+ if (b2 == null || b2 == b1) return b1;
+ final DefaultGeographicBoundingBox box = new
DefaultGeographicBoundingBox(b1);
+ box.intersect(b2);
+ if (box.equals(b1, ComparisonMode.BY_CONTRACT)) return b1;
+ if (box.equals(b2, ComparisonMode.BY_CONTRACT)) return b2;
+ return box;
+ }
+
+ /**
+ * May compute an intersection between the given geographic extents.
+ * Current implementation supports only {@link GeographicBoundingBox};
+ * all other kinds are handled as if they were {@code null}.
+ *
+ * <p>We may improve this method in future Apache SIS version, but it is
not yet clear how.
+ * For example how to handle {@link GeographicDescription} or {@link
BoundingPolygon}?
+ * This method should not be public before we find a better contract.</p>
+ */
+ static GeographicExtent intersection(final GeographicExtent e1, final
GeographicExtent e2) {
+ return intersection(e1 instanceof GeographicBoundingBox ?
(GeographicBoundingBox) e1 : null,
+ e2 instanceof GeographicBoundingBox ?
(GeographicBoundingBox) e2 : null);
+ }
+
+ /**
+ * Returns the intersection of the given vertical extents. If any of the
arguments is {@code null},
+ * then this method returns the other argument (which may be null).
Otherwise this method returns a
+ * vertical extent which is the intersection of the two given extents.
+ *
+ * <p>This method never modify the given extents, but may return directly
one of the given arguments
+ * if it already represents the intersection result.</p>
+ *
+ * <div class="section">Advantage and inconvenient of this method</div>
+ * This method can not intersect extents defined with different datums
because height transformations
+ * generally require the geodetic positions (latitudes and longitudes) of
the heights to transform.
+ * For more general transformations, it is better to convert all extent
components into a single envelope,
+ * then {@linkplain
org.apache.sis.geometry.Envelopes#transform(CoordinateOperation, Envelope)
transform
+ * the envelope at once}. On the other hand, this {@code intersect(…)}
method preserves better
+ * the {@link org.apache.sis.xml.NilReason} (if any).
+ *
+ * @param e1 the first extent, or {@code null}.
+ * @param e2 the second extent, or {@code null}.
+ * @return the intersection (may be any of the {@code e1} or {@code e2}
argument if unchanged),
+ * or {@code null} if the two given extents are null.
+ * @throws MismatchedReferenceSystemException if the two extents do not
use the same datum, ignoring metadata.
+ *
+ * @see DefaultVerticalExtent#intersect(VerticalExtent)
+ *
+ * @since 0.8
+ */
+ public static VerticalExtent intersection(final VerticalExtent e1, final
VerticalExtent e2) {
+ if (e1 == null) return e2;
+ if (e2 == null || e2 == e1) return e1;
+ final DefaultVerticalExtent extent = new DefaultVerticalExtent(e1);
+ extent.intersect(e2);
+ if (extent.equals(e1, ComparisonMode.BY_CONTRACT)) return e1;
+ if (extent.equals(e2, ComparisonMode.BY_CONTRACT)) return e2;
+ return extent;
+ }
+
+ /**
+ * Returns the intersection of the given temporal extents. If any of the
arguments is {@code null},
+ * then this method returns the other argument (which may be null).
Otherwise this method returns a
+ * temporal extent which is the intersection of the two given extents.
+ *
+ * <p>This method never modify the given extents, but may return directly
one of the given arguments
+ * if it already represents the intersection result.</p>
+ *
+ * @param e1 the first extent, or {@code null}.
+ * @param e2 the second extent, or {@code null}.
+ * @return the intersection (may be any of the {@code e1} or {@code e2}
argument if unchanged),
+ * or {@code null} if the two given extents are null.
+ * @throws UnsupportedOperationException if no implementation of {@code
TemporalFactory} has been found
+ * on the classpath.
+ *
+ * @see DefaultTemporalExtent#intersect(TemporalExtent)
+ *
+ * @since 0.8
+ */
+ public static TemporalExtent intersection(final TemporalExtent e1, final
TemporalExtent e2) {
+ if (e1 == null) return e2;
+ if (e2 == null || e2 == e1) return e1;
+ final DefaultTemporalExtent extent = new DefaultTemporalExtent(e1);
+ extent.intersect(e2);
+ if (extent.equals(e1, ComparisonMode.BY_CONTRACT)) return e1;
+ if (extent.equals(e2, ComparisonMode.BY_CONTRACT)) return e2;
+ return extent;
+ }
+
+ /**
+ * Returns the intersection of the given extents. If any of the arguments
is {@code null},
+ * then this method returns the other argument (which may be null).
Otherwise this method
+ * returns an extent which is the intersection of all geographic, vertical
and temporal
+ * elements in the two given extents.
+ *
+ * <p>This method never modify the given extents, but may return directly
one of the given
+ * arguments if it already represents the intersection result.</p>
+ *
+ * @param e1 the first extent, or {@code null}.
+ * @param e2 the second extent, or {@code null}.
+ * @return the intersection (may be any of the {@code e1} or {@code e2}
argument if unchanged),
+ * or {@code null} if the two given extents are null.
+ * @throws IllegalArgumentException if two elements to intersect are not
compatible (e.g. mismatched
+ * {@linkplain DefaultGeographicBoundingBox#getInclusion()
bounding box inclusion status} or
+ * mismatched {@linkplain DefaultVerticalExtent#getVerticalCRS()
vertical datum}).
+ * @throws UnsupportedOperationException if a {@code TemporalFactory} is
required but no implementation
+ * has been found on the classpath.
+ *
+ * @see DefaultExtent#intersect(Extent)
+ *
+ * @since 0.8
+ */
+ public static Extent intersection(final Extent e1, final Extent e2) {
+ if (e1 == null) return e2;
+ if (e2 == null || e2 == e1) return e1;
+ final DefaultExtent extent = new DefaultExtent(e1);
+ extent.intersect(e2);
+ if (extent.equals(e1, ComparisonMode.BY_CONTRACT)) return e1;
+ if (extent.equals(e2, ComparisonMode.BY_CONTRACT)) return e2;
+ return extent;
+ }
}
Modified:
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/DefaultExtentTest.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -17,12 +17,16 @@
package org.apache.sis.metadata.iso.extent;
import java.net.URL;
+import java.util.Arrays;
import java.io.IOException;
import javax.xml.bind.JAXBException;
+import org.opengis.metadata.extent.Extent;
+import org.apache.sis.util.iso.SimpleInternationalString;
import org.apache.sis.xml.IdentifierSpace;
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.xml.NilObject;
import org.apache.sis.test.XMLTestCase;
import org.apache.sis.test.DependsOn;
-import org.apache.sis.xml.Namespaces;
import org.junit.Test;
import static org.apache.sis.test.Assert.*;
@@ -34,7 +38,7 @@ import static org.apache.sis.test.TestUt
*
* @author Cédric Briançon (Geomatys)
* @author Martin Desruisseaux (Geomatys)
- * @version 0.6
+ * @version 0.8
* @since 0.3
* @module
*/
@@ -58,6 +62,40 @@ public final strictfp class DefaultExten
}
/**
+ * Tests {@link DefaultExtent#intersect(Extent)}.
+ */
+ @Test
+ public void testIntersect() {
+ final DefaultGeographicBoundingBox bounds1 = new
DefaultGeographicBoundingBox(10, 20, 30, 40);
+ final DefaultGeographicBoundingBox bounds2 = new
DefaultGeographicBoundingBox(16, 18, 31, 42);
+ final DefaultGeographicBoundingBox clip = new
DefaultGeographicBoundingBox(15, 25, 26, 32);
+ final DefaultGeographicBoundingBox expected1 = new
DefaultGeographicBoundingBox(15, 20, 30, 32);
+ final DefaultGeographicBoundingBox expected2 = new
DefaultGeographicBoundingBox(16, 18, 31, 32);
+ final DefaultExtent e1 = new DefaultExtent("Somewhere", bounds1, null,
null);
+ final DefaultExtent e2 = new DefaultExtent("Somewhere", clip, null,
null);
+ e1.getGeographicElements().add(bounds2);
+ e1.intersect(e2);
+ assertEquals("description", "Somewhere",
e1.getDescription().toString());
+ assertFalse("isNil(description)", e1.getDescription() instanceof
NilObject);
+ assertArrayEquals("geographicElements", new
DefaultGeographicBoundingBox[] {
+ expected1, expected2
+ }, e1.getGeographicElements().toArray());
+ /*
+ * Change the description and test again. That description should be
considered missing
+ * because we have a mismatch. Also change abounding box in such a way
that there is no
+ * intersection. That bounding box should be omitted.
+ */
+ bounds2.setBounds(8, 12, 33, 35);
+ e1.setGeographicElements(Arrays.asList(bounds1, bounds2));
+ e2.setDescription(new SimpleInternationalString("Somewhere else"));
+ e1.intersect(e2);
+ assertTrue("isNil(description)", e1.getDescription() instanceof
NilObject);
+ assertArrayEquals("geographicElements", new
DefaultGeographicBoundingBox[] {
+ expected1
+ }, e1.getGeographicElements().toArray());
+ }
+
+ /**
* Tests the (un)marshalling of a {@code <gmd:EX_Extent>} object.
* This test opportunistically tests setting {@code "gml:id"} value.
*
Modified:
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -23,7 +23,10 @@ import javax.measure.Unit;
import javax.measure.UnitConverter;
import javax.measure.IncommensurableException;
import org.opengis.geometry.DirectPosition;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.VerticalExtent;
import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.referencing.operation.TransformException;
import org.apache.sis.measure.Units;
import org.apache.sis.measure.MeasurementRange;
import org.apache.sis.test.mock.VerticalCRSMock;
@@ -47,7 +50,7 @@ import static org.junit.Assert.*;
* @since 0.4
* @module
*/
-@DependsOn(DefaultGeographicBoundingBoxTest.class)
+@DependsOn({DefaultGeographicBoundingBoxTest.class, DefaultExtentTest.class})
public final strictfp class ExtentsTest extends TestCase {
/**
* One minute of angle, in degrees.
@@ -97,13 +100,45 @@ public final strictfp class ExtentsTest
* Tests {@link Extents#intersection(GeographicBoundingBox,
GeographicBoundingBox)}.
*/
@Test
- public void testIntersection() {
+ public void testGeographicIntersection() {
final GeographicBoundingBox b1 = new DefaultGeographicBoundingBox(10,
20, 30, 40);
final GeographicBoundingBox b2 = new DefaultGeographicBoundingBox(15,
25, 26, 32);
- assertEquals(new DefaultGeographicBoundingBox(15, 20, 30, 32),
Extents.intersection(b1, b2));
- assertSame(b1, Extents.intersection(b1, null));
+ assertEquals("intersect", new DefaultGeographicBoundingBox(15,
20, 30, 32), Extents.intersection(b1, b2));
+ assertSame(b1, Extents.intersection(b1, null));
assertSame(b2, Extents.intersection(null, b2));
- assertNull( Extents.intersection(null, null));
+ assertNull( Extents.intersection((GeographicBoundingBox) null,
(GeographicBoundingBox) null));
+ }
+
+ /**
+ * Tests {@link Extents#intersection(VerticalExtent, VerticalExtent)}.
+ * This test does not perform any unit conversion, because it would
require the use of different CRS.
+ * For a test with unit conversion, see {@code
ServicesForMetadataTest.testVerticalIntersection()} in
+ * {@code sis-referencing} module.
+ *
+ * @throws TransformException should never happen since we do not test
transformation in this class.
+ */
+ @Test
+ public void testVerticalIntersection() throws TransformException {
+ final VerticalExtent e1 = new DefaultVerticalExtent(10, 20, null);
+ final VerticalExtent e2 = new DefaultVerticalExtent(15, 25, null);
+ assertEquals("intersect", new DefaultVerticalExtent(15, 20, null),
Extents.intersection(e1, e2));
+ assertSame(e1, Extents.intersection(e1, null));
+ assertSame(e2, Extents.intersection(null, e2));
+ assertNull( Extents.intersection((VerticalExtent) null,
(VerticalExtent) null));
+ }
+
+ /**
+ * Tests {@link Extents#intersection(Extent, Extent)}.
+ * This test is subject to the same limitation than {@link
#testVerticalIntersection()}.
+ */
+ @Test
+ public void testExtentIntersection() {
+ final Extent e1 = new DefaultExtent(null, new
DefaultGeographicBoundingBox(10, 20, 30, 40), new DefaultVerticalExtent(10, 20,
null), null);
+ final Extent e2 = new DefaultExtent(null, new
DefaultGeographicBoundingBox(15, 25, 26, 32), new DefaultVerticalExtent(15, 25,
null), null);
+ assertEquals( new DefaultExtent(null, new
DefaultGeographicBoundingBox(15, 20, 30, 32), new DefaultVerticalExtent(15, 20,
null), null), Extents.intersection(e1, e2));
+ assertSame(e1, Extents.intersection(e1, null));
+ assertSame(e2, Extents.intersection(null, e2));
+ assertNull( Extents.intersection((Extent) null, (Extent) null));
}
/**
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -661,6 +661,8 @@ public final class ServicesForMetadata e
* If the given properties are empty and the {@code mtFactory} is the
system default, then this method
* returns the system default {@code CoordinateOperationFactory} instead
of creating a new one.
*
+ * <p>It is okay to set all parameters to {@code null} in order to get the
system default factory.</p>
+ *
* @param properties the default properties.
* @param mtFactory the math transform factory to use.
* @param crsFactory the factory to use if the operation factory needs
to create CRS for intermediate steps.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -29,6 +29,7 @@ import org.opengis.referencing.cs.Ellips
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
+import org.opengis.referencing.cs.CSFactory;
import org.opengis.referencing.crs.CRSFactory;
import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.CompoundCRS;
@@ -41,6 +42,7 @@ import org.opengis.referencing.crs.Proje
import org.opengis.referencing.crs.TemporalCRS;
import org.opengis.referencing.crs.VerticalCRS;
import org.opengis.referencing.crs.EngineeringCRS;
+import org.opengis.referencing.operation.CoordinateOperationFactory;
import org.opengis.referencing.operation.OperationNotFoundException;
import org.opengis.metadata.citation.Citation;
import org.opengis.metadata.extent.Extent;
@@ -53,6 +55,7 @@ import org.apache.sis.measure.Units;
import org.apache.sis.geometry.Envelopes;
import org.apache.sis.geometry.GeneralEnvelope;
import org.apache.sis.internal.metadata.AxisDirections;
+import org.apache.sis.internal.metadata.EllipsoidalHeightCombiner;
import org.apache.sis.internal.referencing.PositionalAccuracyConstant;
import org.apache.sis.internal.referencing.CoordinateOperations;
import org.apache.sis.internal.referencing.ReferencingUtilities;
@@ -68,6 +71,7 @@ import org.apache.sis.referencing.crs.De
import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
import org.apache.sis.referencing.operation.CoordinateOperationContext;
import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
+import org.apache.sis.referencing.factory.GeodeticObjectFactory;
import org.apache.sis.referencing.factory.UnavailableFactoryException;
import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
import org.apache.sis.metadata.iso.extent.Extents;
@@ -805,6 +809,61 @@ public final class CRS extends Static {
}
/**
+ * Creates a compound coordinate reference system from an ordered list of
CRS components.
+ * A CRS is inferred from the given components and the domain of validity
is set to the
+ * {@linkplain org.apache.sis.metadata.iso.extent.DefaultExtent#intersect
intersection}
+ * of the domain of validity of all components.
+ *
+ * <div class="section">Ellipsoidal height</div>
+ * If a two-dimensional geographic or projected CRS if followed or
preceded by a vertical CRS with ellipsoidal
+ * {@linkplain
org.apache.sis.referencing.datum.DefaultVerticalDatum#getVerticalDatumType()
datum type}, then
+ * this method combines them in a single three-dimensional geographic or
projected CRS. Note that standalone
+ * ellipsoidal heights are not allowed according ISO 19111. But if such
situation is nevertheless found, then
+ * the action described here fixes the issue. This is the reverse of
<code>{@linkplain #getVerticalComponent
+ * getVerticalComponent}(crs, true)</code>.
+ *
+ * <div class="section">Components order</div>
+ * Apache SIS is permissive on the order of components that can be used in
a compound CRS.
+ * However for better inter-operability, users are encouraged to follow
the order mandated by ISO 19162:
+ *
+ * <ol>
+ * <li>A mandatory horizontal CRS (only one of two-dimensional {@code
GeographicCRS} or {@code ProjectedCRS} or {@code EngineeringCRS}).</li>
+ * <li>Optionally followed by a {@code VerticalCRS} or a {@code
ParametricCRS} (but not both).</li>
+ * <li>Optionally followed by a {@code TemporalCRS}.</li>
+ * </ol>
+ *
+ * @param components the sequence of coordinate reference systems making
the compound CRS.
+ * @return the compound CRS, or {@code components[0]} if the given array
contains only one component.
+ * @throws IllegalArgumentException if the given array is empty or if the
array contains incompatible components.
+ * @throws FactoryException if the geodetic factory failed to create the
compound CRS.
+ *
+ * @since 0.8
+ *
+ * @see GeodeticObjectFactory#createCompoundCRS(Map,
CoordinateReferenceSystem...)
+ */
+ public static CoordinateReferenceSystem compound(final
CoordinateReferenceSystem... components) throws FactoryException {
+ ArgumentChecks.ensureNonNull("components", components);
+ switch (components.length) {
+ case 0: {
+ throw new
IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1,
"components"));
+ }
+ case 1: {
+ final CoordinateReferenceSystem crs = components[0];
+ if (crs != null) return crs;
+ break;
+ }
+ }
+ final Map<String,?> properties =
EllipsoidalHeightCombiner.properties(components);
+ return new EllipsoidalHeightCombiner() {
+ @Override public void initialize(final int factoryTypes) {
+ if ((factoryTypes & CRS) != 0) crsFactory =
DefaultFactories.forBuildin(CRSFactory.class);
+ if ((factoryTypes & CS) != 0) csFactory =
DefaultFactories.forBuildin(CSFactory.class);
+ if ((factoryTypes & OPERATION) != 0) opFactory =
DefaultFactories.forBuildin(CoordinateOperationFactory.class);
+ }
+ }.createCompoundCRS(properties, components);
+ }
+
+ /**
* Returns {@code true} if the given CRS is horizontal. The current
implementation considers a
* CRS as horizontal if it is two-dimensional and comply with one of the
following conditions:
*
@@ -925,6 +984,8 @@ public final class CRS extends Static {
* The recommended value is {@code false}.
* @return the first vertical CRS, or {@code null} if none.
*
+ * @see #compound(CoordinateReferenceSystem...)
+ *
* @category information
*/
public static VerticalCRS getVerticalComponent(final
CoordinateReferenceSystem crs,
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -1128,8 +1128,8 @@ public class GeodeticObjectFactory exten
}
/**
- * Creates a compound coordinate reference system from an ordered list of
{@code CoordinateReferenceSystem} objects.
- * Apache SIS puts no restriction on the components that can be used in a
compound CRS.
+ * Creates a compound coordinate reference system from an ordered list of
CRS components.
+ * Apache SIS is permissive on the order of components that can be used in
a compound CRS.
* However for better inter-operability, users are encouraged to follow
the order mandated by ISO 19162:
*
* <ol>
@@ -1141,19 +1141,20 @@ public class GeodeticObjectFactory exten
* The default implementation creates a {@link DefaultCompoundCRS}
instance.
*
* @param properties name and other properties to give to the new object.
- * @param elements Ordered array of {@code CoordinateReferenceSystem}
objects.
+ * @param components the sequence of coordinate reference systems making
the compound CRS.
* @throws FactoryException if the object creation failed.
*
* @see DefaultCompoundCRS#DefaultCompoundCRS(Map,
CoordinateReferenceSystem...)
* @see GeodeticAuthorityFactory#createCompoundCRS(String)
+ * @see
org.apache.sis.referencing.CRS#compound(CoordinateReferenceSystem...)
*/
@Override
public CompoundCRS createCompoundCRS(final Map<String,?> properties,
- final CoordinateReferenceSystem... elements) throws
FactoryException
+ final CoordinateReferenceSystem... components) throws
FactoryException
{
final DefaultCompoundCRS crs;
try {
- crs = new DefaultCompoundCRS(complete(properties), elements);
+ crs = new DefaultCompoundCRS(complete(properties), components);
} catch (IllegalArgumentException exception) {
throw new InvalidGeodeticParameterException(exception);
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombinerTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombinerTest.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombinerTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/metadata/EllipsoidalHeightCombinerTest.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -32,6 +32,7 @@ import org.apache.sis.referencing.crs.Ha
import org.apache.sis.referencing.factory.GeodeticObjectFactory;
import org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory;
import org.apache.sis.referencing.operation.HardCodedConversions;
+import org.apache.sis.metadata.iso.extent.Extents;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
@@ -159,4 +160,15 @@ public final strictfp class EllipsoidalH
((CoordinateReferenceSystem)
components[1]).getCoordinateSystem(),
AxisDirection.UP, AxisDirection.EAST, AxisDirection.NORTH);
}
+
+ /**
+ * Tests {@link
EllipsoidalHeightCombiner#properties(CoordinateReferenceSystem...)}.
+ */
+ @Test
+ public void testProperties() {
+ final Map<String,?> properties =
EllipsoidalHeightCombiner.properties(HardCodedCRS.WGS84,
HardCodedCRS.GRAVITY_RELATED_HEIGHT, HardCodedCRS.TIME);
+ assertEquals("WGS 84 + MSL height + Time", properties.remove("name"));
+ assertEquals(Extents.WORLD, properties.remove("domainOfValidity"));
+ assertTrue("No other property expected.", properties.isEmpty());
+ }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ServicesForMetadataTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ServicesForMetadataTest.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ServicesForMetadataTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ServicesForMetadataTest.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -16,6 +16,7 @@
*/
package org.apache.sis.internal.referencing;
+import java.util.Date;
import org.opengis.geometry.Envelope;
import org.opengis.metadata.extent.GeographicBoundingBox;
import org.opengis.metadata.extent.VerticalExtent;
@@ -23,6 +24,7 @@ import org.opengis.referencing.crs.Coord
import org.opengis.referencing.operation.TransformException;
import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
import org.apache.sis.metadata.iso.extent.DefaultVerticalExtent;
+import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
import org.apache.sis.metadata.iso.extent.DefaultSpatialTemporalExtent;
import org.apache.sis.geometry.GeneralEnvelope;
import org.apache.sis.referencing.CommonCRS;
@@ -30,6 +32,8 @@ import org.apache.sis.referencing.crs.Ha
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
+import org.apache.sis.test.TestUtilities;
+import org.junit.Ignore;
import org.junit.Test;
import static org.apache.sis.test.Assert.*;
@@ -162,4 +166,42 @@ public final strictfp class ServicesForM
verifySpatialExtent((GeographicBoundingBox)
getSingleton(extent.getSpatialExtent()));
verifyVerticalExtent(CommonCRS.Vertical.MEAN_SEA_LEVEL,
extent.getVerticalExtent());
}
+
+ /**
+ * Tests {@link DefaultVerticalExtent#intersect(VerticalExtent)}.
+ *
+ * @throws TransformException if the transformation failed.
+ *
+ * @since 0.8
+ */
+ @Test
+ public void testVerticalIntersection() throws TransformException {
+ final DefaultVerticalExtent e1 = new DefaultVerticalExtent(1000, 2000,
HardCodedCRS.ELLIPSOIDAL_HEIGHT_cm);
+ final DefaultVerticalExtent e2 = new DefaultVerticalExtent(15, 25,
HardCodedCRS.ELLIPSOIDAL_HEIGHT);
+ e1.intersect(e2);
+ assertEquals(new DefaultVerticalExtent(1500, 2000,
HardCodedCRS.ELLIPSOIDAL_HEIGHT_cm), e1);
+ }
+
+ /**
+ * Tests {@link DefaultTemporalExtent#intersect(TemporalExtent)}.
+ *
+ * @throws TransformException if the transformation failed.
+ *
+ * @since 0.8
+ */
+ @Test
+ @Ignore("This operation requires the sis-temporal module.")
+ public void testTemporalIntersection() throws TransformException {
+ final DefaultTemporalExtent e1 = new DefaultTemporalExtent();
+ final DefaultTemporalExtent e2 = new DefaultTemporalExtent();
+ final Date t1 = TestUtilities.date("2016-12-05 19:45:20");
+ final Date t2 = TestUtilities.date("2017-02-18 02:12:50");
+ final Date t3 = TestUtilities.date("2017-11-30 23:50:00");
+ final Date t4 = TestUtilities.date("2018-05-20 12:30:45");
+ e1.setBounds(t1, t3);
+ e2.setBounds(t2, t4);
+ e1.intersect(e2);
+ assertEquals("startTime", t2, e1.getStartTime());
+ assertEquals("endTime", t3, e1.getEndTime());
+ }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -310,6 +310,26 @@ public final strictfp class CRSTest exte
}
/**
+ * Tests {@link CRS#compound(CoordinateReferenceSystem...)}.
+ *
+ * @throws FactoryException if an error occurred while creating a compound
CRS.
+ *
+ * @since 0.8
+ */
+ @Test
+ public void testCompound() throws FactoryException {
+ try {
+ CRS.compound();
+ fail("Should not accept empty array.");
+ } catch (IllegalArgumentException e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains("components"));
+ }
+ assertSame(HardCodedCRS.WGS84, CRS.compound(HardCodedCRS.WGS84));
+ assertEqualsIgnoreMetadata(HardCodedCRS.WGS84_3D,
CRS.compound(HardCodedCRS.WGS84, HardCodedCRS.ELLIPSOIDAL_HEIGHT));
+ }
+
+ /**
* Tests {@link CRS#getComponentAt(CoordinateReferenceSystem, int, int)}
on a (x,y,z,t)
* coordinate reference system having 4 dimensions. All arguments given to
this method
* except the last one are the expected components, which may be {@code
null}.
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/PrimitiveTypeProperties.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/PrimitiveTypeProperties.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/PrimitiveTypeProperties.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/PrimitiveTypeProperties.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -89,7 +89,7 @@ public final class PrimitiveTypeProperti
assert isValidKey(primitive) : primitive;
synchronized (SENTINEL_VALUES) {
final Object old = SENTINEL_VALUES.put(primitive, property);
- if (old != null) { // Should never happen - this is rather
debugging check.
+ if (old != null) { // Should never happen
- this is rather debugging check.
SENTINEL_VALUES.put(primitive, old);
throw new AssertionError(primitive);
}
@@ -103,8 +103,10 @@ public final class PrimitiveTypeProperti
* @return the property associated to the given instance, or {@code null}
if none.
*/
public static Object property(final Object primitive) {
- // No 'assert isValidKey(primitive)' because this method is sometime
invoked
- // only after a brief inspection (e.g. 'NilReason.mayBeNil(Object)'
method).
+ /*
+ * No 'assert isValidKey(primitive)' because this method is sometime
invoked
+ * only after a brief inspection (e.g. 'NilReason.mayBeNil(Object)'
method).
+ */
synchronized (SENTINEL_VALUES) {
return SENTINEL_VALUES.get(primitive);
}
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -67,14 +67,15 @@ public final class DefaultFactories exte
/**
* Returns {@code true} if the default factory of the given type is the
given instance.
+ * A {@code null} factory is interpreted as the default one.
*
* @param <T> the interface type.
* @param type the interface type.
- * @param factory the factory implementation to test.
+ * @param factory the factory implementation to test, or {@code null}.
* @return {@code true} if the given factory implementation is the default
instance.
*/
public static synchronized <T> boolean isDefaultInstance(final Class<T>
type, final T factory) {
- return FACTORIES.get(type) == factory;
+ return (factory == null) || FACTORIES.get(type) == factory;
}
/**
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java?rev=1811827&r1=1811826&r2=1811827&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/NilReason.java
[UTF-8] Wed Oct 11 14:12:56 2017
@@ -253,7 +253,7 @@ public final class NilReason implements
}
String result = buffer.toString();
if (result.equals(reason)) {
- result = reason; // Use the existing instance.
+ result = reason; // Use the
existing instance.
}
return POOL.unique(new NilReason(result));
}
@@ -422,7 +422,7 @@ public final class NilReason implements
PrimitiveTypeProperties.associate(object, this);
}
if (nilObjects.put(type, object) != null) {
- throw new AssertionError(type); // Should never happen.
+ throw new AssertionError(type);
// Should never happen.
}
}
return type.cast(object);