Public
Edited
Oct 18, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
test = mapboxGeocoder("albuquerque, NM")
Insert cell
mapboxGeocoder = function(loc) {

const token = "pk.eyJ1IjoicnRydWppbGxvIiwiYSI6ImNsbnY4bnN3cDBqdnIyc3QzeWQ4YW85aXgifQ.f3Lo4HXmT6JoVzbBuoDuow";
const url = "https://api.mapbox.com/geocoding/v5/mapbox.places/"+encodeURI(loc)+".json?access_token="+token;
return fetch(url).then((response) => response.json())


}
Insert cell
Insert cell
Insert cell
coords = nominatumSearch("Abuquerque, NM")
Insert cell
nominatumSearch = function(address){
const url = "https://nominatim.openstreetmap.org/search?q="+encodeURI(address)+"&format=geojson"
return fetch(url).then((response) => response.json())
}
Insert cell
address = nominatumReverse(35,-106)
Insert cell
nominatumReverse = function(lat, lon){
const url = "https://nominatim.openstreetmap.org/reverse?lat="+lat+"&lon="+lon+"&format=geojson"
return fetch(url).then((response) => response.json())
}
Insert cell
Insert cell
Insert cell
geojson = {
return {
'type' : "FeatureCollection",
'features': []
}
}
Insert cell
{
for (let key in original.data) {
console.log(key + " -> " + original.data[key]);
let obj = original.data[key]
let state = obj["location"].split(" CD");
let feature = {
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": []
},
"properties" : {
state: state[0],
value: obj["value"],
mean: obj["mean"],
},
}
geojson.features.push(feature)
}
return geojson
}
Insert cell
{
geojson.features.forEach(obj =>{

/*
nominatumSearch(obj.properties.state).then(res=>{
obj.geometry.coordinates = res.features[0].geometry.coordinates;;
});
*/

//uncomment
mapboxGeocoder(obj.properties.state).then(res=>{
obj.geometry.coordinates = res.features[0].geometry.coordinates;
});
})
return geojson
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more