Published
Edited
Jan 9, 2020
Insert cell
md`# Detect County from a coordinate`
Insert cell
Insert cell
Insert cell
coord = [53.3885996, -6.3821885]; // Dublin (lat, long)
Insert cell
Insert cell
detectRegion(coord, polygons)
Insert cell
Insert cell
Insert cell
detectRegion(southDublin, polygons)
Insert cell
c = [53.0328123, -7.298793300000001]; // Laoighis
Insert cell
detectRegion(c, polygons)
Insert cell
cork = [51.976779, -8.462159];
Insert cell
detectRegion(cork, polygons)
Insert cell
md`## function implementation`
Insert cell
function detectRegion(point, features) {
var geometry = {
"type": "Point",
"coordinates": [point[1], point[0]]
};
var feature = features.filter(d => {
return turf.booleanContains(d.geometry, geometry)
})[0];
if (feature) {
return feature.properties.NAME_1;
}
return "";
}
Insert cell
Insert cell
polygons = {
var featuresArr = features.features;
return featuresArr.map(feature => {
return turf.flatten(feature).features
}).flat()
}
Insert cell
Insert cell
md`## Dependencies`
Insert cell
Insert cell
Insert cell
Insert cell
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