我正在寻找一种方法(javascript)(ol3的外部或内部部分),它可以将投影WKT解析为其proj4文本并创建投影。
<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中找到投影的延伸,还是应该在外部查看?
答案 0 :(得分:2)
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: /* ... */
});