2016-02-12 125 views
0

我有一个使用NAD-83 UTM投影的GeoJSON要素集合,所以坐标以米为单位。我想在Turf.JS库中使用这个特征集合来做一些轮廓。将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); 
    } 
}) 

回答

1

要通过以GeoJSON到Turf.js,做

var formatOptions = {featureProjection: map.getView().getProjection()}; 
featColl = newForm.writeFeaturesObject(feats, formatOptions); 

将结果添加从Turf.js回源,做

features: newForm.readFeatures(isolined, formatOptions) 
相关问题