[英]How do I convert a JSON document collection into a GeoJSON FeatureCollection
[英]How can I find property value from a json FeatureCollection by coordinates?
如何使用javascript / jQuery通過坐標從JSON FeatureCollection查找屬性值(在本例中為“ icao”)?
我有這個:
var coord = "-86.7703018188,34.8647994995";
結果應為:00AL(“ icao”:“ 00AL”,)
到目前為止的腳本:
var json = (function () {
json = null;
$.ajax({
'async': false,
'global': false,
'url': 'myfile.geojson',
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
points = json;
myfile.geojson:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-151.695999146,
59.94919968
]
},
"properties": {
"icao": "00AK",
"name": "Lowell Field",
"elevation": 450,
"tz": "America/Anchorage"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-86.7703018188,
34.8647994995
]
},
"properties": {
"icao": "00AL",
"name": "Epps Airpark",
"elevation": 820,
"tz": "America/Chicago"
}
}
]
}
謝謝你的幫助!
我自己解決了
var geoJSON = json;
var coord = "-86.7703018188,34.8647994995";
var icao;
for(var i = 0; i < geoJSON.features.length; i++){
if (geoJSON.features[i].geometry.coordinates == coord) {
icao = geoJSON.features[i].properties.icao;
}
}
console.log("coordinates " + coord + " == ICAO: " + icao);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.