我有一个使用 NAD-83 UTM 投影的 GeoJSON 特征集合,因此坐标以米为单位。我想将这个要素集合与 Turf.JS 库一起使用来执行一些轮廓。
问题是 Turf.JS 只采用 WGS84 坐标。当我使用 UTM 投影在网格上进行轮廓绘制时,生成的等值线具有错误的坐标(-XXXXXXXXX、XXXXXXXX)。
如何将我的 GeoJSON 文件转换为具有 WGS84 坐标而不是 UTM ?
这是我的代码:
var receptors1 = new ol.layer.Vector({
name: "Receptors",
visible: true,
source: new ol.source.Vector({
url: "url.json",
format: new ol.format.GeoJSON()
})
});
map.addLayer(receptors1);
receptors1.getSource().on('change', function(evt){
var source = evt.target;
if(source.getState() === 'ready'){
var feats = source.getFeatures();
var newForm = new ol.format.GeoJSON();
featColl = newForm.writeFeaturesObject(feats);
var breaks = [0, 1, 2, 3, 4, 5];
isolined = turf.isolines(featColl, 'Max', 15, breaks);
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(isolined)
})
var isoShow = new ol.layer.Vector({
source: vectorSource
})
map.addLayer(isoShow);
}
})
要将 GeoJSON 传递给 Turf.js,请执行
var formatOptions = {featureProjection: map.getView().getProjection()};
featColl = newForm.writeFeaturesObject(feats, formatOptions);
要将 Turf.js 的结果添加回您的源,请执行
features: newForm.readFeatures(isolined, formatOptions)