From: Mathieu Baudier Date: Sun, 13 Mar 2011 23:21:45 +0000 (+0000) Subject: Improve GIS X-Git-Tag: argeo-commons-2.1.30~1368 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=ae50c6f8bf578334fb3c972cf8d8de29affe2ef3;p=lgpl%2Fargeo-commons.git Improve GIS git-svn-id: https://svn.argeo.org/commons/trunk@4293 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- 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); + } + } }