我有一个使用NAD-83 UTM投影的GeoJSON特征集,因此坐标以米为单位。我想在Turf.JS库中使用此功能集来进行一些轮廓绘制。
问题是Turf.JS只采用WGS84坐标。当我使用UTM投影在网格上进行轮廓绘制时,生成的等值线具有错误的坐标(-XXXXXXXX,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);
}
})
答案 0 :(得分:2)
要将GeoJSON传递给Turf.js,请执行
var formatOptions = {featureProjection: map.getView().getProjection()};
featColl = newForm.writeFeaturesObject(feats, formatOptions);
要将Turf.js的结果添加回源,请执行
features: newForm.readFeatures(isolined, formatOptions)