This is an automated email from the ASF dual-hosted git repository.

jsorel 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 b705f8c455 Refactor matrix classes between sis referencing Matrix and 
the new geometry module matrix classes
b705f8c455 is described below

commit b705f8c455d3fb1e4fb70410a634e2b0f7856a9d
Author: jsorel <[email protected]>
AuthorDate: Mon Jun 30 15:45:40 2025 +0200

    Refactor matrix classes between sis referencing Matrix and the new geometry 
module matrix classes
---
 .../sis/referencing/operation/matrix/Matrix1.java  | 13 +++++
 .../sis/referencing/operation/matrix/Matrix2.java  | 33 ++++++++++++
 .../sis/referencing/operation/matrix/Matrix3.java  | 19 +++++++
 .../sis/referencing/operation/matrix/Matrix4.java  | 21 ++++++++
 .../org.apache.sis.geometries.processor.Processor  | 28 ++++++++++
 .../org/apache/sis/geometries/math/Matrix.java     |  5 +-
 .../org/apache/sis/geometries/math/Matrix2D.java   | 50 ++++++++---------
 .../org/apache/sis/geometries/math/Matrix3D.java   | 42 +++++++++------
 .../org/apache/sis/geometries/math/Matrix4D.java   | 40 +++++++++-----
 .../org/apache/sis/geometries/math/MatrixND.java   | 44 ---------------
 .../processor/spatialedition/Transform.java        | 63 +++++++++++++++++++++-
 11 files changed, 256 insertions(+), 102 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java
index ec6b8d4bc7..a2fb7e1400 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.operation.matrix;
 
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.util.privy.Numerics;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -237,6 +238,18 @@ public class Matrix1 extends MatrixSIS {
         // Nothing to do for a 1x1 matrix.
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public double[] multiply(double[] v) {
+        if (v.length != 1) {
+            throw new 
MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2,
 1, v.length));
+        }
+        return new double[]{
+            m00 * v[0]
+        };
+    }
     /**
      * Normalizes all columns in-place.
      * For a 1×1 matrix with non-NaN value, this method sets the {@link #m00} 
value
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java
index 193fde99af..edd5d8dac9 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.operation.matrix;
 
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.util.privy.Numerics;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -262,6 +263,38 @@ public class Matrix2 extends MatrixSIS {
         m01 = swap;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public double[] multiply(double[] v) {
+        if (v.length != 2) {
+            throw new 
MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2,
 2, v.length));
+        }
+        final double x = v[0];
+        final double y = v[1];
+        return new double[]{
+            m00 * x + m01 * y,
+            m10 * x + m11 * y
+        };
+    }
+
+    /**
+     * Set matrix to given rotation angle,
+     * Rotation is in counter-clockwise direction.
+     * Resulting matrix will not be affine.
+     *
+     * @param angleRad angle in radians
+     */
+    public void setToRotation(double angleRad) {
+        final double sin = Math.sin(angleRad);
+        final double cos = Math.cos(angleRad);
+        m00 = cos;
+        m01 = -sin;
+        m10 = sin;
+        m11 = cos;
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java
index 244a6e769d..b62d749217 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.referencing.operation.matrix;
 
+import org.apache.sis.util.resources.Errors;
 import org.opengis.referencing.operation.Matrix;
 
 
@@ -288,6 +289,24 @@ public class Matrix3 extends MatrixSIS {
         swap = m12; m12 = m21; m21 = swap;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public double[] multiply(double[] v) {
+        if (v.length != 3) {
+            throw new 
MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2,
 3, v.length));
+        }
+        final double x = v[0];
+        final double y = v[1];
+        final double z = v[2];
+        return new double[]{
+            m00 * x + m01 * y + m02 * z,
+            m10 * x + m11 * y + m12 * z,
+            m20 * x + m21 * y + m22 * z
+        };
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java
index 8011a24a72..86b6e1cafb 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.referencing.operation.matrix;
 
+import org.apache.sis.util.resources.Errors;
 import org.opengis.referencing.operation.Matrix;
 
 
@@ -326,6 +327,26 @@ public class Matrix4 extends MatrixSIS {
         swap = m23; m23 = m32; m32 = swap;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public double[] multiply(double[] v) {
+        if (v.length != 4) {
+            throw new 
MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2,
 4, v.length));
+        }
+        final double x = v[0];
+        final double y = v[1];
+        final double z = v[2];
+        final double w = v[3];
+        return new double[]{
+            m00 * x + m01 * y + m02 * z + m03 * w,
+            m10 * x + m11 * y + m12 * z + m13 * w,
+            m20 * x + m21 * y + m22 * z + m23 * w,
+            m30 * x + m31 * y + m32 * z + m33 * w
+        };
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git 
a/incubator/src/org.apache.sis.geometry/main/META-INF/services/org.apache.sis.geometries.processor.Processor
 
b/incubator/src/org.apache.sis.geometry/main/META-INF/services/org.apache.sis.geometries.processor.Processor
new file mode 100644
index 0000000000..7489f1c667
--- /dev/null
+++ 
b/incubator/src/org.apache.sis.geometry/main/META-INF/services/org.apache.sis.geometries.processor.Processor
@@ -0,0 +1,28 @@
+org.apache.sis.geometries.processor.spatialanalysis2d.Distance$PointPoint
+
+org.apache.sis.geometries.processor.spatialanalysis2d.Intersection$PrimitiveTrianglesPrimitivePoints
+org.apache.sis.geometries.processor.spatialanalysis2d.Intersection$PrimitiveTrianglesPrimitiveLines
+
+org.apache.sis.geometries.processor.spatialedition.To3D$Point
+org.apache.sis.geometries.processor.spatialedition.To3D$LineString
+org.apache.sis.geometries.processor.spatialedition.To3D$Primitive
+
+org.apache.sis.geometries.processor.spatialedition.ComputeAttribute$Primitive
+org.apache.sis.geometries.processor.spatialedition.ComputeAttribute$MultiPrimitive
+
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$Point
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$LineString
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$Polygon
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$MultiLineString
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$MultiPoint
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$MultiPrimitive
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$Primitive
+org.apache.sis.geometries.processor.spatialedition.ToPrimitive$GeometryCollection
+
+org.apache.sis.geometries.processor.spatialedition.Transform$LinearRing
+org.apache.sis.geometries.processor.spatialedition.Transform$Polygon
+org.apache.sis.geometries.processor.spatialedition.Transform$MultiPrimitive
+org.apache.sis.geometries.processor.spatialedition.Transform$Primitive
+org.apache.sis.geometries.processor.spatialedition.Transform$Triangle
+
+org.apache.sis.geometries.processor.spatialrelations2d.Contains$PolygonPoint
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
index 4f56691a11..611d888e7f 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
@@ -16,14 +16,15 @@
  */
 package org.apache.sis.geometries.math;
 
+import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import 
org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 
 /**
- * TODO to mix with SIS matrices
  *
  * @author Johann Sorel (Geomatys)
+ * @todo Remove this class when all elements are merged in MatrixSIS
  */
-public abstract class Matrix {
+public abstract class Matrix extends MatrixSIS {
 
     public abstract void transform(Tuple tuple, Tuple result);
 
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
index f2326cca7f..f2efce9787 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
@@ -17,47 +17,47 @@
 package org.apache.sis.geometries.math;
 
 import org.apache.sis.referencing.operation.matrix.Matrix2;
-import 
org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 
 /**
  *
  * @author Johann Sorel (Geomatys)
  */
-public final class Matrix2D extends Matrix{
-
-    private final Matrix2 matrix;
+public final class Matrix2D extends Matrix2{
 
     public Matrix2D() {
-        this.matrix = new Matrix2();
     }
 
-    public Matrix2D(Matrix2 matrix) {
-        this.matrix = matrix;
+    public Matrix2D(double m00, double m01, double m10, double m11) {
+        super(m00, m01, m10, m11);
     }
 
-    public Matrix2D(double m00, double m01, double m10, double m11) {
-        this.matrix = new Matrix2(m00, m01, m10, m11);
+    public Matrix2D(double[] elements) {
+        super(elements);
     }
 
-    @Override
+
     public void transform(Tuple tuple, Tuple result) {
         //TODO not efficient
-        result.set(matrix.multiply(tuple.toArrayDouble()));
+        result.set(multiply(tuple.toArrayDouble()));
     }
 
-    @Override
-    public Matrix2D inverse() throws NoninvertibleMatrixException {
-        return new Matrix2D(Matrix2.castOrCopy(matrix.inverse()));
+    /**
+     * Casts or copies the given matrix to a {@code Matrix2D} implementation. 
If the given {@code matrix}
+     * is already an instance of {@code Matrix2D}, then it is returned 
unchanged. Otherwise this method
+     * verifies the matrix size, then copies all elements in a new {@code 
Matrix2D} object.
+     *
+     * @param  matrix  the matrix to cast or copy, or {@code null}.
+     * @return the matrix argument if it can be safely casted (including 
{@code null} argument),
+     *         or a copy of the given matrix otherwise.
+     * @throws IllegalArgumentException if the size of the given matrix is not 
{@value #SIZE}×{@value #SIZE}.
+     */
+    public static Matrix2D castOrCopy(final 
org.opengis.referencing.operation.Matrix matrix) throws 
IllegalArgumentException {
+        if (matrix == null || matrix instanceof Matrix2D) {
+            return (Matrix2D) matrix;
+        }
+        if (matrix.getNumCol() != 2 || matrix.getNumRow() != 2) {
+            throw new IllegalArgumentException("Matrix is not of size 2x2");
+        }
+        return new Matrix2D(Matrix2.castOrCopy(matrix).getElements());
     }
-
-    public Matrix2D fromRotation(double angleRad) {
-        final double sin = Math.sin(angleRad);
-        final double cos = Math.cos(angleRad);
-        matrix.m00 = cos;
-        matrix.m01 = sin;
-        matrix.m10 = -sin;
-        matrix.m11 = cos;
-        return this;
-    }
-
 }
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
index 71107eb266..233c9d36f1 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
@@ -17,22 +17,15 @@
 package org.apache.sis.geometries.math;
 
 import org.apache.sis.referencing.operation.matrix.Matrix3;
-import 
org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 
 /**
  *
  * @author Johann Sorel (Geomatys)
+ * @todo Remove this class when all elements are merged in Matrix3
  */
-public class Matrix3D extends Matrix{
-
-    private final Matrix3 matrix;
+public class Matrix3D extends Matrix3{
 
     public Matrix3D() {
-        this.matrix = new Matrix3();
-    }
-
-    public Matrix3D(Matrix3 matrix) {
-        this.matrix = matrix;
     }
 
     public Matrix3D(
@@ -40,20 +33,37 @@ public class Matrix3D extends Matrix{
             double m10, double m11, double m12,
             double m20, double m21, double m22
             ) {
-        this.matrix = new Matrix3(
-                m00, m01, m02,
+        super(  m00, m01, m02,
                 m10, m11, m12,
                 m20, m21, m22);
     }
 
-    @Override
+    public Matrix3D(double[] elements) {
+        super(elements);
+    }
+
     public void transform(Tuple tuple, Tuple result) {
         //TODO not efficient
-        result.set(matrix.multiply(tuple.toArrayDouble()));
+        result.set(multiply(tuple.toArrayDouble()));
     }
 
-    @Override
-    public Matrix3D inverse() throws NoninvertibleMatrixException {
-        return new Matrix3D(Matrix3.castOrCopy(matrix.inverse()));
+    /**
+     * Casts or copies the given matrix to a {@code Matrix3D} implementation. 
If the given {@code matrix}
+     * is already an instance of {@code Matrix3D}, then it is returned 
unchanged. Otherwise this method
+     * verifies the matrix size, then copies all elements in a new {@code 
Matrix3D} object.
+     *
+     * @param  matrix  the matrix to cast or copy, or {@code null}.
+     * @return the matrix argument if it can be safely casted (including 
{@code null} argument),
+     *         or a copy of the given matrix otherwise.
+     * @throws IllegalArgumentException if the size of the given matrix is not 
{@value #SIZE}×{@value #SIZE}.
+     */
+    public static Matrix3D castOrCopy(final 
org.opengis.referencing.operation.Matrix matrix) throws 
IllegalArgumentException {
+        if (matrix == null || matrix instanceof Matrix3D) {
+            return (Matrix3D) matrix;
+        }
+        if (matrix.getNumCol() != 3 || matrix.getNumRow() != 3) {
+            throw new IllegalArgumentException("Matrix is not of size 3x3");
+        }
+        return new Matrix3D(Matrix3.castOrCopy(matrix).getElements());
     }
 }
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
index afd1cf3b3f..16d6f39217 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
@@ -17,22 +17,16 @@
 package org.apache.sis.geometries.math;
 
 import org.apache.sis.referencing.operation.matrix.Matrix4;
-import 
org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
 
 /**
  *
  * @author Johann Sorel (Geomatys)
+ * @todo Remove this class when all elements are merged in Matrix4
  */
-public class Matrix4D extends Matrix{
+public class Matrix4D extends Matrix4 {
 
-    private final Matrix4 matrix;
 
     public Matrix4D() {
-        this.matrix = new Matrix4();
-    }
-
-    public Matrix4D(Matrix4 matrix) {
-        this.matrix = matrix;
     }
 
     public Matrix4D(
@@ -41,7 +35,7 @@ public class Matrix4D extends Matrix{
             double m20, double m21, double m22, double m23,
             double m30, double m31, double m32, double m33
             ) {
-        this.matrix = new Matrix4(
+        super(
                 m00, m01, m02, m03,
                 m10, m11, m12, m13,
                 m20, m21, m22, m23,
@@ -49,14 +43,32 @@ public class Matrix4D extends Matrix{
         );
     }
 
-    @Override
+    public Matrix4D(double[] elements) {
+        super(elements);
+    }
+
     public void transform(Tuple tuple, Tuple result) {
         //TODO not efficient
-        result.set(matrix.multiply(tuple.toArrayDouble()));
+        result.set(multiply(tuple.toArrayDouble()));
     }
 
-    @Override
-    public Matrix4D inverse() throws NoninvertibleMatrixException {
-        return new Matrix4D(Matrix4.castOrCopy(matrix.inverse()));
+    /**
+     * Casts or copies the given matrix to a {@code Matrix4D} implementation. 
If the given {@code matrix}
+     * is already an instance of {@code Matrix4D}, then it is returned 
unchanged. Otherwise this method
+     * verifies the matrix size, then copies all elements in a new {@code 
Matrix4D} object.
+     *
+     * @param  matrix  the matrix to cast or copy, or {@code null}.
+     * @return the matrix argument if it can be safely casted (including 
{@code null} argument),
+     *         or a copy of the given matrix otherwise.
+     * @throws IllegalArgumentException if the size of the given matrix is not 
{@value #SIZE}×{@value #SIZE}.
+     */
+    public static Matrix4D castOrCopy(final 
org.opengis.referencing.operation.Matrix matrix) throws 
IllegalArgumentException {
+        if (matrix == null || matrix instanceof Matrix4D) {
+            return (Matrix4D) matrix;
+        }
+        if (matrix.getNumCol() != 4 || matrix.getNumRow() != 4) {
+            throw new IllegalArgumentException("Matrix is not of size 4x4");
+        }
+        return new Matrix4D(Matrix4.castOrCopy(matrix).getElements());
     }
 }
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
deleted file mode 100644
index 16934cfcec..0000000000
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.geometries.math;
-
-import org.apache.sis.referencing.operation.matrix.MatrixSIS;
-import 
org.apache.sis.referencing.operation.matrix.NoninvertibleMatrixException;
-
-/**
- *
- * @author Johann Sorel (Geomatys)
- */
-public class MatrixND extends Matrix {
-
-    private final MatrixSIS matrix;
-
-    public MatrixND(MatrixSIS matrix) {
-        this.matrix = matrix;
-    }
-
-    @Override
-    public void transform(Tuple tuple, Tuple result) {
-        //TODO not efficient
-        result.set(matrix.multiply(tuple.toArrayDouble()));
-    }
-
-    @Override
-    public MatrixND inverse() throws NoninvertibleMatrixException {
-        return new MatrixND(MatrixSIS.castOrCopy(matrix.inverse()));
-    }
-}
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/processor/spatialedition/Transform.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/processor/spatialedition/Transform.java
index 3bdb9fa213..276f4501a8 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/processor/spatialedition/Transform.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/processor/spatialedition/Transform.java
@@ -33,6 +33,9 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import org.apache.sis.geometries.Curve;
+import org.apache.sis.geometries.DefaultPolygon;
+import org.apache.sis.geometries.LinearRing;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.opengis.referencing.operation.TransformException;
 
@@ -48,6 +51,7 @@ public final class Transform {
 
         final int sourceDimension = reference.getDimension();
         final int targetDimension = 
operation.crs.getCoordinateSystem().getDimension();
+        final SampleSystem ss = SampleSystem.of(operation.crs);
 
         if (sourceDimension == targetDimension) {
             //use in place transform
@@ -57,6 +61,7 @@ public final class Transform {
             } catch (TransformException ex) {
                 throw new OperationException(ex.getMessage(), ex);
             }
+            positions.setSampleSystem(ss);
             return positions;
         } else {
             final int nb = reference.getLength();
@@ -67,7 +72,63 @@ public final class Transform {
             } catch (TransformException ex) {
                 throw new OperationException(ex.getMessage(), ex);
             }
-            return TupleArrays.of(SampleSystem.of(operation.crs), result);
+            return TupleArrays.of(ss, result);
+        }
+    }
+
+    public static class LinearRing implements 
Processor<org.apache.sis.geometries.operation.spatialedition.Transform, 
org.apache.sis.geometries.LinearRing> {
+
+        @Override
+        public 
Class<org.apache.sis.geometries.operation.spatialedition.Transform> 
getOperationClass() {
+            return 
org.apache.sis.geometries.operation.spatialedition.Transform.class;
+        }
+
+        @Override
+        public Class<org.apache.sis.geometries.LinearRing> getGeometryClass() {
+            return org.apache.sis.geometries.LinearRing.class;
+        }
+
+        @Override
+        public void 
process(org.apache.sis.geometries.operation.spatialedition.Transform operation) 
throws OperationException {
+            final org.apache.sis.geometries.LinearRing r = 
(org.apache.sis.geometries.LinearRing) operation.geometry;
+
+            PointSequence ps = r.getPoints();
+            final TupleArray reference = 
ps.getAttributeArray(AttributesType.ATT_POSITION);
+            final TupleArray positions = transform(reference, operation);
+            final ArraySequence cp = new ArraySequence(positions);
+            for (String name : ps.getAttributesType().getAttributeNames()) {
+                if (!AttributesType.ATT_POSITION.equals(name)) {
+                    cp.setAttribute(name, ps.getAttributeArray(name).copy());
+                }
+            }
+            operation.result = new DefaultLinearRing(cp);
+        }
+    }
+
+    public static class Polygon implements 
Processor<org.apache.sis.geometries.operation.spatialedition.Transform, 
org.apache.sis.geometries.Polygon> {
+
+        @Override
+        public 
Class<org.apache.sis.geometries.operation.spatialedition.Transform> 
getOperationClass() {
+            return 
org.apache.sis.geometries.operation.spatialedition.Transform.class;
+        }
+
+        @Override
+        public Class<org.apache.sis.geometries.Polygon> getGeometryClass() {
+            return org.apache.sis.geometries.Polygon.class;
+        }
+
+        @Override
+        public void 
process(org.apache.sis.geometries.operation.spatialedition.Transform operation) 
throws OperationException {
+            final org.apache.sis.geometries.Polygon p = 
(org.apache.sis.geometries.Polygon) operation.geometry;
+
+            Curve exterior = (Curve) 
GeometryOperations.SpatialEdition.transform(p.getExteriorRing(), operation.crs, 
operation.transform);
+
+            final List<Curve> interiors = new 
ArrayList<>(p.getInteriorRings());
+            for (int i = 0, n = interiors.size(); i < n; i++) {
+                interiors.set(i, (Curve) 
GeometryOperations.SpatialEdition.transform(interiors.get(i), operation.crs, 
operation.transform));
+            }
+
+            operation.result = new 
DefaultPolygon((org.apache.sis.geometries.LinearRing) exterior, (List) 
interiors);
         }
     }
 

Reply via email to