2016-02-12 188 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) 
相關問題