| | |
| | | import org.osgeo.proj4j.ProjCoordinate; |
| | | |
| | | public class ProjectionToGeographicUtil { |
| | | |
| | | public static JSONArray getPointAndHight(Double x,Double y) { |
| | | // 创建 CRSFactory 对象 |
| | | JSONArray vertice = new JSONArray(); |
| | | vertice.add(x); |
| | | vertice.add(y); |
| | | vertice.add(0.0); |
| | | return vertice; |
| | | } |
| | | public static JSONArray getPoint(Double x,Double y) { |
| | | // 创建 CRSFactory 对象 |
| | | CRSFactory crsFactory = new CRSFactory(); |
| | |
| | | vertice.add(0.0); |
| | | return vertice; |
| | | } |
| | | |
| | | public static JSONArray get4548Point(Double x,Double y) { |
| | | // 创建 CRSFactory 对象 |
| | | CRSFactory crsFactory = new CRSFactory(); |
| | | // 定义投影坐标系统,这里以 UTM 投影为例,zone 33N |
| | | CoordinateReferenceSystem sourceCRS = crsFactory.createFromName("EPSG:4326"); |
| | | // 定义地理坐标系统,这里使用 WGS84 |
| | | CoordinateReferenceSystem targetCRS = crsFactory.createFromName("EPSG:4548"); |
| | | // 创建坐标转换对象 |
| | | BasicCoordinateTransform transform = new BasicCoordinateTransform(sourceCRS, targetCRS); |
| | | // 输入投影坐标,以 UTM 投影坐标为例,单位是米 |
| | | ProjCoordinate sourceCoord = new ProjCoordinate(x, y); |
| | | ProjCoordinate targetCoord = new ProjCoordinate(); |
| | | // 执行坐标转换 |
| | | transform.transform(sourceCoord, targetCoord); |
| | | JSONArray vertice = new JSONArray(); |
| | | vertice.add(targetCoord.x); |
| | | vertice.add(targetCoord.y); |
| | | return vertice; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(getPoint(469257.26224087493,4416938.9521611305)); |
| | | System.out.println(getPoint(116.64058,39.88605)); |
| | | } |
| | | } |