Note: After reviewing some possible solutions mentioned in this thread, I found that .map
is the perfect fit for what I need, which was not covered in the original post. Thomas's response below addresses my specific requirement.
In JavaScript, how can I create an array of values representing a specific property from each feature in a GeoJSON file? Essentially, how do I transform this:
['caiparinha','caucasian','margarita']
into this?
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "brasil",
"beverage": "caiparinha"
},
"geometry": {
"type": "Point",
"coordinates": [
-56.953125,
-8.754794702435605
]
}
},
{
"type": "Feature",
"properties": {
"name": "russia",
"beverage": "caucasian"
},
"geometry": {
"type": "Point",
"coordinates": [
39.0234375,
57.136239319177434
]
}
},
{
"type": "Feature",
"properties": {
"name": "mexico",
"beverage": "margarita"
},
"geometry": {
"type": "Point",
"coordinates": [
-105.1171875,
25.165173368663954
]
}
}
]
}
When dealing with CSV data, it's as simple as selecting/parsing a single column, but in GeoJSON, the properties (similar to columns) are deeply nested. I have struggled to achieve this using .map
and would prefer to avoid looping if possible, although I'm open to any suggestions.
The goal is to extract distribution information linked to each "variable" associated with the features being mapped, similar to functionality discussed here.