WGS54坐标系中的经纬度坐标 124.793263,46.26888194 转换为54坐标系的Java代码示例
时间: 2024-03-01 13:52:06 浏览: 108
地址到经纬度坐标转化的JAVA代码
可以使用Proj4J库来进行坐标系转换,以下是Java代码示例:
```java
import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.osgeo.proj4j.ProjCoordinate;
import org.osgeo.proj4j.Proj4jException;
import org.osgeo.proj4j.io.Proj4FileReader;
public class WGS54To54Converter {
private static final String WGS84_DEF = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
private static final String WGS54_DEF = "+proj=longlat +ellps=krass +towgs84=-15.8,84.1,-80.9,0,0,0,0 +no_defs";
private static final String WGS54_ZONE_DEF = "+proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=500000 +y_0=0 +ellps=krass +towgs84=-15.8,84.1,-80.9,0,0,0,0 +units=m +no_defs";
private static ProjCoordinate transform(ProjCoordinate src, CoordinateReferenceSystem srcCrs,
CoordinateReferenceSystem destCrs) throws Proj4jException {
ProjCoordinate dest = new ProjCoordinate();
srcCrs.getProjection().transform(srcCrs, destCrs, src, dest);
return dest;
}
public static void main(String[] args) {
ProjCoordinate wgs84Coord = new ProjCoordinate(124.793263, 46.26888194);
Proj4FileReader reader = new Proj4FileReader();
try {
CoordinateReferenceSystem wgs84Crs = reader.createFromParameters("WGS84", WGS84_DEF);
CoordinateReferenceSystem wgs54Crs = reader.createFromParameters("WGS54", WGS54_DEF);
CoordinateReferenceSystem wgs54ZoneCrs = reader.createFromParameters("WGS54 Zone 8", WGS54_ZONE_DEF);
ProjCoordinate wgs54Coord = transform(wgs84Coord, wgs84Crs, wgs54Crs);
ProjCoordinate wgs54ZoneCoord = transform(wgs54Coord, wgs54Crs, wgs54ZoneCrs);
System.out.println(wgs54ZoneCoord.x + ", " + wgs54ZoneCoord.y);
} catch (Proj4jException e) {
e.printStackTrace();
}
}
}
```
其中,`WGS54_DEF` 和 `WGS54_ZONE_DEF` 分别表示 WGS54 和 54 坐标系的参数定义。需要注意的是,54 坐标系是分带的,所以定义时需要指定带号。此处默认为第8带,如果需要转换到其他带,需要修改 `WGS54_ZONE_DEF` 中的参数。
阅读全文