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 ab28c7b648 JTS : fix empty geometry transform exception
ab28c7b648 is described below

commit ab28c7b6489e97907efea46cc11bf0a663256b4d
Author: jsorel <[email protected]>
AuthorDate: Tue May 17 15:14:08 2022 +0200

    JTS : fix empty geometry transform exception
---
 .../org/apache/sis/internal/feature/jts/JTS.java   | 23 ++++++++++++----------
 .../apache/sis/internal/feature/jts/JTSTest.java   | 16 +++++++++++++++
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/JTS.java 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/JTS.java
index 9bcc183b88..d4a0fa8f7c 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/JTS.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/JTS.java
@@ -207,16 +207,19 @@ public final class JTS extends Static {
                                                      final Geometry 
areaOfInterest)
             throws FactoryException
     {
-        DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox();
-        try {
-            final Envelope e = areaOfInterest.getEnvelopeInternal();
-            final GeneralEnvelope env = new GeneralEnvelope(sourceCRS);     // 
May be 3- or 4-dimensional.
-            env.setRange(0, e.getMinX(), e.getMaxX());
-            env.setRange(1, e.getMinY(), e.getMaxY());
-            bbox.setBounds(env);
-        } catch (TransformException ex) {
-            bbox = null;
-            Logging.ignorableException(getLogger(Loggers.GEOMETRY), JTS.class, 
"transform", ex);
+        DefaultGeographicBoundingBox bbox = null;
+        if (!areaOfInterest.isEmpty()) {
+            bbox = new DefaultGeographicBoundingBox();
+            try {
+                final Envelope e = areaOfInterest.getEnvelopeInternal();
+                final GeneralEnvelope env = new GeneralEnvelope(sourceCRS);    
 // May be 3- or 4-dimensional.
+                env.setRange(0, e.getMinX(), e.getMaxX());
+                env.setRange(1, e.getMinY(), e.getMaxY());
+                bbox.setBounds(env);
+            } catch (TransformException ex) {
+                bbox = null;
+                Logging.ignorableException(getLogger(Loggers.GEOMETRY), 
JTS.class, "transform", ex);
+            }
         }
         return CRS.findOperation(sourceCRS, targetCRS, bbox);
     }
diff --git 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/jts/JTSTest.java
 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/jts/JTSTest.java
index 60fc318f2d..e46e4018c0 100644
--- 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/jts/JTSTest.java
+++ 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/jts/JTSTest.java
@@ -228,4 +228,20 @@ public final strictfp class JTSTest extends TestCase {
         assertEquals(CommonCRS.WGS84.geographic(), out.getUserData());
         assertEquals(Factory.BIDIMENSIONAL, 
out.getCoordinateSequence().getDimension());
     }
+
+    /**
+     * Test {@code transform} method on an empty geometry.
+     *
+     * @throws FactoryException if an EPSG code can not be resolved.
+     * @throws TransformException if a coordinate can not be transformed.
+     */
+    @Test
+    public void testTransformEmpty() throws FactoryException, 
TransformException {
+        final GeometryFactory factory = Factory.INSTANCE.factory(false);
+        final Point in = factory.createPoint();
+        in.setUserData(CommonCRS.WGS84.geographic());
+        final Geometry out = JTS.transform(in, 
CommonCRS.WGS84.normalizedGeographic());
+        assertEquals(CommonCRS.WGS84.normalizedGeographic(), 
out.getUserData());
+        assertTrue(out.isEmpty());
+    }
 }

Reply via email to