[英]How to read a geojson file in javascript and get min or max of property?
如果这是一个愚蠢的问题,我是 js 的新手,抱歉。 我想我的问题有两个部分。
使用 javascript 读取 geojson 文件的最简单方法是什么?
现在我正在使用:
var centrisData = $.getJSON( "Path to geojson");
我的文件看起来像这样:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"type": "Maison\u00a0",
"utilisation": "null",
"piecesBeta": "20.0",
"price": 3995000.0,
"prixPiece_beta": 199750.0,
},
},
{
"type": "Feature",
"properties": {
"type": "Condo\u00a0",
"utilisation": "null",
"piecesBeta": "6.0",
"price": 448900.0,
"prixPiece_beta": 74816.67
}
}
我希望能够获得财产“价格”的最小值和最大值。 这样做的最简单方法是什么?
提前致谢 !
您可以遍历所有功能,并将当前的最低和最高价格作为变量保存和存储。
const centrisData = { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "type": "Maison\ ", "utilisation": "null", "piecesBeta": "20.0", "price": 3995000.0, "prixPiece_beta": 199750.0, }, }, { "type": "Feature", "properties": { "type": "Condo\ ", "utilisation": "null", "piecesBeta": "6.0", "price": 448900.0, "prixPiece_beta": 74816.67 } } ] }; let min = Infinity, max = -min; for(const {properties: {price}} of centrisData.features){ min = Math.min(min, price); max = Math.max(max, price); } console.log("Min:", min); console.log("Max:", max);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.