X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=gis%2Fruntime%2Forg.argeo.gis.geotools%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fgeotools%2Fjcr%2FGeoJcrUtils.java;h=15fb6353e955871c9280d60f20cff2441395dbea;hb=c3be9f8db8a79e159d6a057758dfc7f3580efc2d;hp=08181759b9bbbb3225bd49f25c5bb19cec5cc95e;hpb=477f38e7085ce32c6f09e062cac90f7ba8769698;p=lgpl%2Fargeo-commons.git diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrUtils.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrUtils.java index 08181759b..15fb6353e 100644 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrUtils.java +++ b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/jcr/GeoJcrUtils.java @@ -8,9 +8,11 @@ import org.argeo.ArgeoException; import org.argeo.jcr.gis.GisNames; import org.argeo.jcr.gis.GisTypes; import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.opengis.geometry.DirectPosition; import org.opengis.referencing.crs.CoordinateReferenceSystem; +import org.opengis.referencing.operation.MathTransform; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; @@ -95,4 +97,15 @@ public class GeoJcrUtils { "Cannot get coordinate reference system for " + node, e); } } + + public static Geometry reproject(CoordinateReferenceSystem crs, + Geometry geometry, CoordinateReferenceSystem targetCrs) { + try { + MathTransform transform = CRS.findMathTransform(crs, targetCrs); + return JTS.transform(geometry, transform); + } catch (Exception e) { + throw new ArgeoException("Cannot reproject " + geometry + " from " + + crs + " to " + targetCrs); + } + } }