我正在尝试做的事情:
我有一个家庭收入在美国的县的GEOJSON文件。每个县看起来像这样:
{
"type": "Feature",
"properties": {
"GEO_ID": "0500000US28137",
"STATE": "MS",
"COUNTY": "137",
"NAME": "Tate",
"LSAD": "County",
"CENSUSAREA": 404.759,
"Income": 77000
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-90.200199,
34.724418
],
[
-90.128906,
34.760537
],
[
-90.030051,
34.70795
],
[
-89.912202,
34.772506
],
[
-89.723635,
34.772121
],
[
-89.722333,
34.685504
],
[
-89.66916,
34.685786
],
[
-89.668448,
34.554367
],
[
-89.721341,
34.554274
],
[
-90.198631,
34.554425
],
[
-90.239971,
34.626237
],
[
-90.200199,
34.724418
]
]
]
}
}
我还有另一个GEOJSON,其中包含独特主题的详细信息。目的是使主题的地址与县列表匹配,以查看该主题所属的县。然后,将来自县GEOJSON的“收入”传递给主题。 GEOJSON中的每个主题如下:
{
"type": "Feature",
"id": 1,
"geometry": {
"type": "Point",
"coordinates": [
-95.980577,
41.287989
]
},
"properties": {
"CommunityPartner": "Abide Omaha",
"Address": "3223 N 45th St",
"City": "Omaha",
"State": "NE",
"Zip": "68104",
"Location": "Omaha, NE",
"Latitude": 41.287989,
"Longitude": -95.980577,
"PhoneNumber": "402-455-7807",
"Website": "www.abideomaha.org",
"PrimaryMissionFocus": "Social Justice",
"SecondaryMissionFocus": "Economic Sufficiency",
"WeitzCECPartner": "No",
"Enteredby": "Service Learning Academy",
"Notes": "",
"semester": [
"Spring 2018"
],
"time": "Spring 2018"
}
}
我的代码如下:
var counties = [];
var countyData = "";
$.get("static/GEOJSON/USCounties_2.geojson", function(data) { //load JSON file from static/GEOJSON
countyData = jQuery.parseJSON(data);
var features=countyData["features"];
features.forEach(function(feature){
counties.push({
"county": feature.properties["NAME"], "coordinates": feature.geometry.coordinates,
"Income": feature.properties["Income"]
})
})
});
var communityData = "";
var referencedincome = 0;
$.get("static/GEOJSON/CommunityPartners.geojson", function(data) { //load JSON file from static/GEOJSON
communityData = jQuery.parseJSON(data);
var features=communityData["features"];
features.forEach(function(feature){
if (feature.geometry !== null) {
var point = feature.geometry.coordinates;
point = turf.point(point);
for (var i = 0; i < counties.length; i++){
var coord = counties[i].coordinates;
var countycoord = turf.polygon(coord);
if (turf.booleanPointInPolygon(point,countycoord)){ //use Turf js to determine if a point is in a polygon or not
referencedincome = counties[i]["Income"]
}
}
}
feature.properties["income"] = referencedincome;
});
});
我现在所拥有的看起来像这样。查看弹出窗口中的“家庭收入”行。它仍然为0。显然,“ counties”数组为空,即使我的代码没有收到任何错误。
我已经尝试了几个小时来修复它,但是没有成功。如果您有任何建议,将不胜感激。谢谢!