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 3c0fbe89c1 feat(Geometry): add toJava2D method on GeometryWrapper 3c0fbe89c1 is described below commit 3c0fbe89c19c121edbf51717fefab96dc1338e80 Author: jsorel <johann.so...@geomatys.com> AuthorDate: Mon Jan 29 09:44:37 2024 +0100 feat(Geometry): add toJava2D method on GeometryWrapper --- .../org.apache.sis.feature/main/module-info.java | 1 + .../sis/geometry/wrapper/GeometryWrapper.java | 29 ++++++++++++++++++++++ .../apache/sis/geometry/wrapper/j2d/Wrapper.java | 9 +++++++ .../apache/sis/geometry/wrapper/jts/Wrapper.java | 25 +++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/endorsed/src/org.apache.sis.feature/main/module-info.java b/endorsed/src/org.apache.sis.feature/main/module-info.java index 0bffbda6d2..9badc7e6ba 100644 --- a/endorsed/src/org.apache.sis.feature/main/module-info.java +++ b/endorsed/src/org.apache.sis.feature/main/module-info.java @@ -63,6 +63,7 @@ module org.apache.sis.feature { org.apache.sis.storage.sql, org.apache.sis.storage.netcdf, org.apache.sis.storage.shapefile, // In the "incubator" sub-project. + org.apache.sis.portrayal.map, // In the "incubator" sub-project. org.apache.sis.cql; // In the "incubator" sub-project. exports org.apache.sis.geometry.wrapper.j2d to diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java index 3e5ccac478..319ca1672f 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java @@ -16,6 +16,7 @@ */ package org.apache.sis.geometry.wrapper; +import java.awt.Shape; import java.util.Objects; import java.util.Iterator; import java.util.OptionalInt; @@ -46,6 +47,7 @@ import org.opengis.geometry.complex.Complex; import org.opengis.filter.SpatialOperatorName; import org.opengis.filter.DistanceOperatorName; import org.opengis.filter.InvalidFilterValueException; +import org.opengis.referencing.operation.MathTransform; /** @@ -470,6 +472,22 @@ public abstract class GeometryWrapper extends AbstractGeometry implements Geomet throw new UnsupportedOperationException(Geometries.unsupported("transform")); } + /** + * Transforms this geometry using the given transform. + * If the transform is {@code null}, then the geometry is returned unchanged. + * The geometry CRS remains unchanged. + * + * @param transform the math transform to apply, or {@code null}. + * @return the transformed geometry (may be the same geometry instance, but never {@code null}). + * @throws UnsupportedOperationException if this operation is not supported for current implementation. + * @throws TransformException if the geometry cannot be transformed. + */ + public GeometryWrapper transform(MathTransform transform) + throws TransformException + { + throw new UnsupportedOperationException(Geometries.unsupported("transform")); + } + /** * Transforms this geometry to the specified Coordinate Reference System (CRS). * If the given CRS is null, then the geometry is returned unchanged. @@ -522,6 +540,17 @@ public abstract class GeometryWrapper extends AbstractGeometry implements Geomet */ public abstract String formatWKT(double flatness); + /** + * Returns a Java2D shape made from this geometry. + * + * @param geometry the geometry as a shape, not {@code null}. + * @return the Java2D shape. + * @throws UnsupportedOperationException if this operation is not supported for current implementation. + */ + public Shape toJava2D() { + throw new UnsupportedOperationException(Geometries.unsupported("toJava2D")); + } + /** * Methods from the {@link Geometry} interface. The {@link Override} annotation is intentionally omitted * for reducing the risk of compilation failures during the upcoming revision of GeoAPI interfaces since diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java index 43aa2c1819..8ca25c929c 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.function.BiPredicate; import java.awt.Shape; import java.awt.geom.Area; +import java.awt.geom.GeneralPath; import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -197,6 +198,14 @@ add: for (;;) { return ShapeUtilities.toPrimitive(path); } + /** + * @return shape copy. + */ + @Override + public Shape toJava2D() { + return new GeneralPath(geometry); + } + /** * Applies a filter predicate between this geometry and another geometry. * This method assumes that the two geometries are in the same CRS (this is not verified). diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java index bbf5680bfa..882e9106df 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java @@ -16,6 +16,8 @@ */ package org.apache.sis.geometry.wrapper.jts; +import java.awt.Shape; +import java.awt.geom.GeneralPath; import java.util.List; import java.util.Arrays; import java.util.ArrayList; @@ -63,6 +65,7 @@ import org.apache.sis.filter.sqlmm.SQLMM; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.filter.SpatialOperatorName; import org.opengis.filter.DistanceOperatorName; +import org.opengis.referencing.operation.MathTransform; /** @@ -727,6 +730,28 @@ add: for (Geometry next = geometry;;) { } } + /** + * Transforms this geometry using the given transform. + * If the transform is {@code null}, then the geometry is returned unchanged. + * The geometry CRS remains unchanged. + * + * @param transform the math transform to apply, or {@code null}. + * @return the transformed geometry (may be the same geometry instance, but never {@code null}). + * @throws TransformException if the geometry cannot be transformed. + */ + @Override + public GeometryWrapper transform(final MathTransform transform) throws TransformException { + return rewrap(JTS.transform(geometry, transform)); + } + + /** + * @return GeneralPath from current JTS Geometry. + */ + @Override + public Shape toJava2D() { + return new GeneralPath(JTS.asShape(geometry)); + } + /** * Returns {@code true} if the given geometry use the same CRS as this geometry, or conservatively * returns {@code false} in case of doubt. This method should perform only a cheap test; it is used