sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1828113 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing: CRS.java operation/CoordinateOperationContext.java operation/DefaultCoordinateOperationFactory.java package-info.java
Date Sat, 31 Mar 2018 15:49:28 GMT
Author: desruisseaux
Date: Sat Mar 31 15:49:27 2018
New Revision: 1828113

URL: http://svn.apache.org/viewvc?rev=1828113&view=rev
Log:
Add public API for CRS.findOperations(sourceCRS, targetCRS) - see SIS-412.

Modified:
    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/operation/CoordinateOperationContext.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/package-info.java

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=1828113&r1=1828112&r2=1828113&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] Sat Mar 31 15:49:27 2018
@@ -136,7 +136,7 @@ import org.opengis.geometry.Geometry;
  * </ul>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
@@ -626,14 +626,7 @@ public final class CRS extends Static {
     {
         ArgumentChecks.ensureNonNull("sourceCRS", sourceCRS);
         ArgumentChecks.ensureNonNull("targetCRS", targetCRS);
-        CoordinateOperationContext context = null;
-        if (areaOfInterest != null) {
-            if (areaOfInterest instanceof DefaultGeographicBoundingBox && ((DefaultGeographicBoundingBox)
areaOfInterest).isEmpty()) {
-                throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1,
"areaOfInterest"));
-            }
-            context = new CoordinateOperationContext();
-            context.setAreaOfInterest(areaOfInterest);
-        }
+        final CoordinateOperationContext context = CoordinateOperationContext.fromBoundingBox(areaOfInterest);
         /*
          * In principle we should just delegate to factory.createOperation(…). However
this operation may fail
          * if a connection to the EPSG database has been found, but the EPSG tables do not
yet exist in that
@@ -645,12 +638,53 @@ public final class CRS extends Static {
         } catch (UnavailableFactoryException e) {
             if (AuthorityFactories.failure(e)) {
                 throw e;
-            } try {
+            } else try {
                 // Above method call replaced the EPSG factory by a fallback. Try again.
                 return factory.createOperation(sourceCRS, targetCRS, context);
             } catch (FactoryException ex) {
                 ex.addSuppressed(e);
                 throw ex;
+            }
+        }
+    }
+
+    /**
+     * Finds mathematical operations that transform or convert coordinates from the given
source to the
+     * given target coordinate reference system. If at least one operation exists, they are
returned in
+     * preference order: the operation having the widest intersection between its
+     * {@linkplain AbstractCoordinateOperation#getDomainOfValidity() domain of validity}
+     * and the given area of interest are returned first.
+     *
+     * @param  sourceCRS       the CRS of source coordinates.
+     * @param  targetCRS       the CRS of target coordinates.
+     * @param  areaOfInterest  the area of interest, or {@code null} if none.
+     * @return mathematical operations from {@code sourceCRS} to {@code targetCRS}.
+     * @throws OperationNotFoundException if no operation was found between the given pair
of CRS.
+     * @throws FactoryException if the operation can not be created for another reason.
+     *
+     * @see DefaultCoordinateOperationFactory#createOperations(CoordinateReferenceSystem,
CoordinateReferenceSystem, CoordinateOperationContext)
+     *
+     * @since 1.0
+     */
+    public static List<CoordinateOperation> findOperations(final CoordinateReferenceSystem
sourceCRS,
+                                                           final CoordinateReferenceSystem
targetCRS,
+                                                           final GeographicBoundingBox areaOfInterest)
+            throws FactoryException
+    {
+        ArgumentChecks.ensureNonNull("sourceCRS", sourceCRS);
+        ArgumentChecks.ensureNonNull("targetCRS", targetCRS);
+        final CoordinateOperationContext context = CoordinateOperationContext.fromBoundingBox(areaOfInterest);
+        final DefaultCoordinateOperationFactory factory = CoordinateOperations.factory();
+        try {
+            return factory.createOperations(sourceCRS, targetCRS, context);
+        } catch (UnavailableFactoryException e) {
+            if (AuthorityFactories.failure(e)) {
+                throw e;
+            } else try {
+                return Collections.singletonList(factory.createOperation(sourceCRS, targetCRS,
context));
+            } catch (FactoryException ex) {
+                ex.addSuppressed(e);
+                throw ex;
             }
         }
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java?rev=1828113&r1=1828112&r2=1828113&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationContext.java
[UTF-8] Sat Mar 31 15:49:27 2018
@@ -21,10 +21,12 @@ import java.util.function.Predicate;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.referencing.operation.CoordinateOperation;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -52,7 +54,7 @@ import org.apache.sis.util.ArgumentCheck
  * late binding implementations.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.0
  * @since   0.7
  * @module
  *
@@ -96,6 +98,27 @@ public class CoordinateOperationContext
     }
 
     /**
+     * Creates an operation context for the given area of interest, which may be null.
+     * This is a convenience method for a frequently-used operation.
+     *
+     * @param  areaOfInterest  the area of interest, or {@code null} if none.
+     * @return the operation context, or {@code null} if the given bounding box was null.
+     *
+     * @since 1.0
+     */
+    public static CoordinateOperationContext fromBoundingBox(final GeographicBoundingBox
areaOfInterest) {
+        if (areaOfInterest != null) {
+            if (areaOfInterest instanceof DefaultGeographicBoundingBox && ((DefaultGeographicBoundingBox)
areaOfInterest).isEmpty()) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1,
"areaOfInterest"));
+            }
+            final CoordinateOperationContext context = new CoordinateOperationContext();
+            context.setAreaOfInterest(areaOfInterest);
+            return context;
+        }
+        return null;
+    }
+
+    /**
      * Returns the spatio-temporal area of interest, or {@code null} if none.
      *
      * @return the spatio-temporal area of interest, or {@code null} if none.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java?rev=1828113&r1=1828112&r2=1828113&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
[UTF-8] Sat Mar 31 15:49:27 2018
@@ -85,7 +85,7 @@ import org.apache.sis.util.Utilities;
  * The second approach is the most frequently used.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.6
  * @module
  */
@@ -822,6 +822,43 @@ next:   for (int i=components.size(); --
     }
 
     /**
+     * Finds or creates operations for conversions or transformations between two coordinate
reference systems.
+     * If at least one operation exists, they are returned in preference order: the operation
having the widest
+     * intersection between its {@linkplain AbstractCoordinateOperation#getDomainOfValidity()
domain of validity}
+     * and the {@linkplain CoordinateOperationContext#getAreaOfInterest() area of interest}
is returned.
+     *
+     * <p>The default implementation performs the following steps:</p>
+     * <ul>
+     *   <li>Invoke {@link #createOperationFinder(CoordinateOperationAuthorityFactory,
CoordinateOperationContext)}.</li>
+     *   <li>Invoke {@link CoordinateOperationFinder#createOperations(CoordinateReferenceSystem,
CoordinateReferenceSystem)}
+     *       on the object returned by the previous step.</li>
+     * </ul>
+     *
+     * Subclasses can override {@link #createOperationFinder createOperationFinder(…)}
if they need more control on
+     * the way coordinate operations are inferred.
+     *
+     * @param  sourceCRS  input coordinate reference system.
+     * @param  targetCRS  output coordinate reference system.
+     * @param  context    area of interest and desired accuracy, or {@code null}.
+     * @return coordinate operations from {@code sourceCRS} to {@code targetCRS}.
+     * @throws OperationNotFoundException if no operation path was found from {@code sourceCRS}
to {@code targetCRS}.
+     * @throws FactoryException if the operation creation failed for some other reason.
+     *
+     * @see CoordinateOperationFinder
+     *
+     * @since 1.0
+     */
+    public List<CoordinateOperation> createOperations(final CoordinateReferenceSystem
sourceCRS,
+                                                      final CoordinateReferenceSystem targetCRS,
+                                                      final CoordinateOperationContext context)
+            throws OperationNotFoundException, FactoryException
+    {
+        final AuthorityFactory registry = USE_EPSG_FACTORY ? CRS.getAuthorityFactory(Constants.EPSG)
: null;
+        return createOperationFinder((registry instanceof CoordinateOperationAuthorityFactory)
?
+                (CoordinateOperationAuthorityFactory) registry : null, context).createOperations(sourceCRS,
targetCRS);
+    }
+
+    /**
      * Creates the object which will perform the actual task of finding a coordinate operation
path between two CRS.
      * This method is invoked by {@link #createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem,
      * CoordinateOperationContext) createOperation(…)} when no operation was found in the
cache.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/package-info.java?rev=1828113&r1=1828112&r2=1828113&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/package-info.java
[UTF-8] Sat Mar 31 15:49:27 2018
@@ -94,7 +94,7 @@
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Guilhem Legal (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.4
  * @module
  */



Mime
View raw message