燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-07-14 db44f336e46825afc855466512065cc08e5790bd
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
package com.yssh.utils;
 
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Coordinate;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
 
public class GisUtil {
    
    /**
     * @param srcNo
     *            源坐标系EPSG代号
     * @param targetNo
     *            目标坐标系EPSG代号
     * @param x
     *            源坐标x
     * @param y
     *            源坐标y
     * @Description: 坐标系转换
     */
    public static Coordinate coordinateTransform(String sourceCRS, String targetCRS,
            double x, double y) {
        Coordinate tar = new Coordinate();
        try {
            CoordinateReferenceSystem src = CRS.decode(sourceCRS);
            CoordinateReferenceSystem target = CRS.decode(targetCRS);
            MathTransform transform = CRS.findMathTransform(src, target, true);
            Coordinate sour = new Coordinate(x, y);
            return JTS.transform(sour, tar, transform);
        } catch (Exception e) {
        }
        return tar;
 
    }
}