使用proj4和EPSG代码变换成不同的坐标系

Using proj4 and EPSG code to transform into different coordinate system

我的坐标在 EPSG:25833,即 UTM,32N 区。 我想将它们转换为 EPSG:3857,WebMercator。 documentation 表示

var firstProjection = 'PROJCS["NAD83 / Massachusetts Mainland",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",42.68333333333333],PARAMETER["standard_parallel_2",41.71666666666667],PARAMETER["latitude_of_origin",41],PARAMETER["central_meridian",-71.5],PARAMETER["false_easting",200000],PARAMETER["false_northing",750000],AUTHORITY["EPSG","26986"],AXIS["X",EAST],AXIS["Y",NORTH]]';
var secondProjection = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";

proj4(firstProjection,secondProjection,[2,5]);

是否可以仅将 EPSG 字符串作为 firstProjectionsecondProjection 传递?通过 EPSG:25833UTM 32N 已经包含所有需要的信息。为什么需要通过才能做到这一点

Proj4js.defs["EPSG:25833"] = "+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs"; 

使用这个定义也限制了我。如果 EPSG:25833 变成另一个 EPSG 怎么办?那我也要更新这个+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs...

Proj4js 分布在以下坐标系中,

export default function(defs) {
  defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
  defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
  defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");

  defs.WGS84 = defs['EPSG:4326'];
  defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
  defs.GOOGLE = defs['EPSG:3857'];
  defs['EPSG:900913'] = defs['EPSG:3857'];
  defs['EPSG:102113'] = defs['EPSG:3857'];
} 

https://github.com/proj4js/proj4js/blob/master/lib/global.js

其他坐标系需要用户自己定义。与随 EPSG 数据库一起分发的 PROJ4 C 库相比,...

这就是您不能仅传递 EPSG 代码的原因,除非它在别处定义。

请注意,

您可以声明,例如,

Proj4js.defs["ETRS89 UTM32"] = "+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs"; 

而不是

Proj4js.defs["EPSG:25833"] = "+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs";

然后是别名

Proj4js.MYEPSG = Proj4js.defs["EPSG:25833"]