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 866e380 Add a `GridGeometry.createTransformTo(GridGeometry target)` method.
866e380 is described below
commit 866e3801420106db8eafb3578e6a56e08f60eb01
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Sep 7 16:17:16 2020 +0200
Add a `GridGeometry.createTransformTo(GridGeometry target)` method.
---
.../org/apache/sis/coverage/grid/GridGeometry.java | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index bd89b61..e3dabed 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -1199,6 +1199,35 @@ public class GridGeometry implements LenientComparable, Serializable
{
}
/**
+ * Creates a transform from cell coordinates in this grid to cell coordinates in the
given grid.
+ * The returned transform handles change of Coordinate Reference System and wraparound
axes
+ * (e.g. longitude axis crossing the ±180° meridian) if applicable.
+ *
+ * <p><b>Note:</b> the transform created by this method may be non-invertible.</p>
+ *
+ * @param target the grid which will be the target of returned transform.
+ * @param anchor {@linkplain PixelInCell#CELL_CENTER Cell center} for OGC conventions
or
+ * {@linkplain PixelInCell#CELL_CORNER cell corner} for Java2D/JAI conventions.
+ * @return transform from cell coordinates in this grid to cell coordinates in the given
grid.
+ * @throws TransformException if the math transform can not be created.
+ *
+ * @since 1.1
+ */
+ public MathTransform createTransformTo(final GridGeometry target, final PixelInCell anchor)
throws TransformException {
+ ArgumentChecks.ensureNonNull("target", target);
+ ArgumentChecks.ensureNonNull("anchor", anchor);
+ final CoordinateOperationFinder finder = new CoordinateOperationFinder(target, this);
+ MathTransform tr;
+ try {
+ tr = finder.gridToCRS(anchor);
+ tr = finder.inverse(tr);
+ } catch (FactoryException e) {
+ throw new TransformException(e);
+ }
+ return tr;
+ }
+
+ /**
* Returns a hash value for this grid geometry. This value needs not to remain
* consistent between different implementations of the same class.
*/
|