- 创建坐标转换
/**
* 创建坐标系转换方法
* @param sourceWkt 源坐标系WKT定义
* @param targetWkt 目标坐标系WKT定义
* @return
*/
public static MathTransform createMathTransform(String sourceWkt, String targetWkt){
CoordinateReferenceSystem source = null;
CoordinateReferenceSystem target = null;
try {
source = CRS.parseWKT(sourceWkt);
target = CRS.parseWKT(targetWkt);
} catch (FactoryException e) {
e.printStackTrace();
}
MathTransform transform = null;
try {
transform = CRS.findMathTransform(source, target);
} catch (FactoryException e) {
e.printStackTrace();
}
return transform;
}
- 将wkt转换为geometry
/**
* 将wkt数据转为geometry数据
* @param wkt
* @return
*/
public static Geometry transformWktToGeometry(String wkt){
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Geometry geometry = null;
try {
geometry = (Geometry) reader.read(wkt);
} catch (ParseException e) {
e.printStackTrace();
}
return geometry;
}
- 将坐标转为指定坐标系
/**
* 将输入要素转换为指定坐标系
* @param geometry
* @param mathTransform 坐标转换方法
* @return
*/
public static Geometry transformGeometryProjection(Geometry geometry, MathTransform mathTransform){
Geometry result = null;
try {
result = JTS.transform(geometry, mathTransform);
} catch (TransformException e) {
e.printStackTrace();
}
return result;
}