geotools之坐标转换

第一次写文章,先前都是看别人的文章,贡献点自己的东西吧,当然坐标转换有很多种方法,今天看了下geotools,那就写下今晚看的东西吧

最常用的两种坐标4326,3857,具体是什么我不说了,相信你懂,哈哈,4326到3857转换

第一种方法

CoordinateReferenceSystem sourceCRS = CRS.decode(“EPSG:4326”);

CoordinateReferenceSystem targetCRS = CRS.decode(“EPSG:3857”);

MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);

Coordinate coorDst=new Coordinate();

JTS.transform(new Coordinate(40, 116),coorDst, transform);

System.out.println(coorDst);

第二种方法

CoordinateReferenceSystem sourceCrs = CRS.decode(“EPSG:4326”);

CoordinateReferenceSystem targetCrs = CRS.decode(“EPSG:3857”);

boolean lenient = true;

MathTransform mathTransform = CRS.findMathTransform(sourceCrs, targetCrs, lenient);

DirectPosition2D srcDirectPosition2D = new DirectPosition2D(sourceCrs, 40, 116);//bj

DirectPosition2D destDirectPosition2D = new DirectPosition2D();

mathTransform.transform(srcDirectPosition2D, destDirectPosition2D);

double transX = destDirectPosition2D.x;

double transY = destDirectPosition2D.y;

System.out.println(transX);

System.out.println(transY);

补充下

CoordinateReferenceSystem sourceCrs = CRS.decode(“EPSG:4326”);

System.out.println(sourceCrs.toWKT());

System.out.println(DefaultGeographicCRS.WGS84.toWKT());

GEOGCS[“WGS 84”,

  DATUM[“World Geodetic System 1984”,

    SPHEROID[“WGS 84”, 6378137.0, 298.257223563, AUTHORITY[“EPSG”,”7030″]],

    AUTHORITY[“EPSG”,”6326″]],

  PRIMEM[“Greenwich”, 0.0, AUTHORITY[“EPSG”,”8901″]],

  UNIT[“degree”, 0.017453292519943295],

  AXIS[“Geodetic latitude”, NORTH],

  AXIS[“Geodetic longitude”, EAST],

  AUTHORITY[“EPSG”,”4326″]]

==============================================

GEOGCS[“WGS84(DD)”,

  DATUM[“WGS84”,

    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],

  PRIMEM[“Greenwich”, 0.0],

  UNIT[“degree”, 0.017453292519943295],

  AXIS[“Geodetic longitude”, EAST],

  AXIS[“Geodetic latitude”, NORTH]]

转载自:https://blog.csdn.net/weixin_33701617/article/details/86853405

You may also like...