Public
Edited
Jan 17
4 forks
25 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getQueryTags = (bbox) => `
//WAYS

// Roads
way["highway"](${bbox});

// Buildings
relation["building"](${bbox});
way["building"](${bbox});

// Water bodies
relation["water"](${bbox}); // all water!
relation["natural"="water"](${bbox});
way["natural"="water"](${bbox});
way["water"="pond"](${bbox});
way["water"="lake"](${bbox});
way["water"="river"](${bbox});
way["waterway"="river"](${bbox});
way["waterway"="stream"](${bbox});
// Parks and recreational areas
way["leisure"="park"](${bbox});
relation["leisure"="park"](${bbox});

// Forests
relation["natural"="forest"](${bbox});
way["natural"="forest"](${bbox});
// Railways
way["railway"](${bbox});

// all landuse
relation["landuse"="meadow"](${bbox});
way["landuse"="meadow"](${bbox});
way["landuse"="grass"](${bbox});
way["landuse"="construction"](${bbox});
// way["landuse"](${bbox});

// Query to fetch rivers and other water features (e.g., streams, lakes)

way["leisure"="pitch"](${bbox});

//trees
node["natural"="tree"](${bbox});

`
Insert cell
osmData = {
const bbox = MAP_BBOX.join(",");
const tags = getQueryTags(bbox);
const query = `
[out:json];
(
${tags}
);
(._;>;);
out body;
`;
return fetch(
`https://overpass-api.de/api/interpreter?data=${encodeURIComponent(query)}`
)
.then((response) => response.json())
.then((data) => data.elements)
.catch((error) => {
console.error("Error fetching OSM data:", error);
return [];
});
}
Insert cell
osmWaysNodesAndRelations = {
const nodes = {};
const ways = [];
const relations = [];
const trees = []; // Separate array for trees

osmData.forEach((element) => {
if (element.type === "node") {
// Check if it's a tree
if (element.tags && element.tags["natural"] === "tree") {
trees.push({
id: element.id,
lat: element.lat,
lon: element.lon,
tags: element.tags
});
} else {
nodes[element.id] = { lat: element.lat, lon: element.lon };
}
} else if (element.type === "way") {
ways.push(element);
} else if (element.type === "relation") {
relations.push(element);
}
});

return { nodes, ways, relations, trees }; // Include trees in the returned object
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
coordinates = ({
cardiff: [51.4837, -3.185738],
copenhagen: [55.6768155, 12.5706028],
paris: [48.858258, 2.294531],
poznan: [52.4063664, 16.9297639],
tampere: [61.4986082, 23.755491],
newYork: [40.7804843, -73.9791474],
amsterdam: [52.3676, 4.9041]
})
Insert cell
Insert cell
d3 = require("d3@7")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more