在 OpenLayers 3 中解析投影 WKT

Parsing Projection WKT in OpenLayers 3

我正在寻找可以将投影 WKT 解析为其 proj4 文本并创建投影的方法 (javascript)(ol3 的外部或内部部分)。

 <SRS>PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]</SRS>

上面显示了包含 SRS 的 XML 元素的示例。

我发现如果我可以将其转换为 proj4 文本。然后我可以这样将其添加为投影:

proj4.defs("EPSG:28353", "+proj=utm +zone=53 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");

var def = proj4.defs(grid.srs);
var units = def.units;
        var proj = new ol.proj.Projection({
            code: grid.srs,
            units: units,
            axisOrientation: def.axis
        });
        proj.setExtent(/*...*/);
        ol.proj.addProjection(proj);
        var proj4Transform1 = proj4('EPSG:3857', grid.srs);
        ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:3857'), proj,
            proj4Transform1.forward, proj4Transform1.inverse);
        var proj4Transform2 = proj4('EPSG:4326', grid.srs);
        ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:4326'), proj,
            proj4Transform2.forward, proj4Transform2.inverse);

是否也可以在 WKT 中找到投影的延伸,或者我是否也应该在外部查找?

proj4js 也支持 WKT 字符串。你可以直接在 proj4js 中抛出你拥有的东西(不包括 <SRS> 标签),使用相同的语法:

proj4.defs("EPSG:28353", "PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]");

使用 proj4.defs() 定义投影后,它将立即在 OpenLayers 3 中可用,并且所有变换都将被注册。所以 proj4.defs() 行就是你所需要的,除非你想设置额外的选项,比如你的投影范围。有两个选项可以做到这一点:1)全局:

ol.proj.get('EPSG:28353').setExtent(*/ ... */);

或 2) 仅适用于一个 ol.proj.Projection 实例,例如配置您的 ol.View:

var projection = new ol.proj.Projection({
  code: 'EPSG:28353',
  extent: /* ... */
});