java中JTS对空间数据Geometry进行坐标系投影转换
代码:
/**
* @Description: 用JTS对Geometry空间数据进行坐标系投影转换
*
* @Param: [params]
* @Return: Geometry
* @Author yanghaoxing
* @Date 2024/9/10 14:54
*/
public Geometry getGeometryForlong(Geometry geometry) {
String srcCrsCode = "EPSG:4490";
String tarCrsCode = "EPSG:4522";
CoordinateReferenceSystem sourceCRS = null;
CoordinateReferenceSystem targetCRS = null;
try{
sourceCRS = CRS.decode(srcCrsCode, true);
targetCRS = CRS.decode(tarCrsCode, true);
}catch (FactoryException e){
System.out.println(e);
}
Geometry reprojectGeometry = null;
try {
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
reprojectGeometry = JTS.transform(geometry, transform);
}catch (Exception e){
System.out.println(e);
}
return reprojectGeometry;
}
使用:
Geometry regionGeometry = null;
try {
regionGeometry = getGeometryForlong(reader.read(wkt));
} catch (ParseException e) {
e.printStackTrace();
}
完结!