1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
/**
* User: san
* Date: 23/06/12
* Time: 6:09 PM
*/
public class ConvertRef {
public static void main(String[] args) throws FactoryException, TransformException {
GeometryFactory gf = new GeometryFactory();
Coordinate c = new Coordinate(175784.99999999997, 5842215.0);
Point p = gf.createPoint(c);
CoordinateReferenceSystem crs2 = CRS.decode("EPSG:3395");
CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:2154");
CoordinateReferenceSystem utmCrs1 = CRS.decode("CRS:83");
MathTransform mathTransform = CRS.findMathTransform(utmCrs,utmCrs1 , true);
Point p1 = (Point) JTS.transform(p, mathTransform);
System.out.println(p1.getCoordinate());
CoordinateReferenceSystem utmCrs2 = CRS.decode("CRS:83");
MathTransform mathTransform2 = CRS.findMathTransform(utmCrs1,utmCrs,true);
Point p2 = (Point) JTS.transform(gf.createPoint(p1.getCoordinate()), mathTransform2);
System.out.println(p2.getCoordinate());
}
} |
Partager