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;
public static CoordinateReferenceSystem getCoordinateReferenceSystem(
Node node) {
try {
- if (!node.isNodeType(GisTypes.GIS_GEOMETRY))
+ if (!node.isNodeType(GisTypes.GIS_LOCATED))
throw new ArgeoException(node + " is not of type "
- + GisTypes.GIS_GEOMETRY);
+ + GisTypes.GIS_LOCATED);
// Coordinate reference system
String srs = node.getProperty(GisNames.GIS_SRS).getString();
CoordinateReferenceSystem crs;
"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);
+ }
+ }
}