2017-10-09 147 views
0

我有折線100的一個GeoJSON的文件, 如:如何使用座標計算兩點的距離?

{ 
    "type":"MultiLineString", 
    "coordinates": 
    [ 
    [ 
     [73.970889292119,15.272263607379], 
     [73.970743508934,15.272184655773] 
    ] 
    ] 
} 

如何計算折線的距離公里或如何計算相同的傳單?

+1

這 - https://stackoverflow.com/questions/31221088/how-to-calculate-the-distance-of-a-polyline-in- leaflet-like-geojson-io - 可能會幫助 –

+0

請參閱https://stackoverflow.com/questions/33939754/layer-circumference-length-in-leaflet-js/33942460#33942460,但您可能需要進一步將其自定義爲適應'MultiLineString'。 – ghybs

回答

0

鑑於polylines數組,你可以爲了找出兩個距離應用math公式,當我們知道coordonates點的

enter image description here

let polylines=[{ 
 
    "type":"MultiLineString", 
 
    "coordinates": 
 
    [ 
 
    [ 
 
     [73.970889292119,15.272263607379], 
 
     [73.970743508934,15.272184655773] 
 
    ] 
 
    ] 
 
},{ 
 
    "type":"MultiLineString2", 
 
    "coordinates": 
 
    [ 
 
    [ 
 
     [34.970889292119,15.272263607379], 
 
     [67.970743508934,67.272184655773] 
 
    ] 
 
    ] 
 
}]; 
 
polylines=polylines.map(function(item){ 
 
    let latitude1=item.coordinates[0][0][0]; 
 
    let longitude1=item.coordinates[0][0][1]; 
 
    let latitude2=item.coordinates[0][1][0]; 
 
    let longitude2=item.coordinates[0][1][1]; 
 
    let distance=Math.sqrt(Math.pow((latitude1-latitude2),2)+Math.pow((longitude1-longitude2),2)); 
 
    return {type:item.type, distance:distance}; 
 
}); 
 
console.log(polylines);

+0

您假定平面幾何。請注意,GeoJSON格式通常用於地球上的特徵,即在一個或多或少的球形幾何體上。 – ghybs