Published
Edited
Feb 25, 2020
3 forks
Importers
8 stars
Insert cell
Insert cell
cities.filter(city => city.name.match('Albuquerque'));
Insert cell
Insert cell
Insert cell
data = cities
.filter(city => city.population > 1e5)
.sort((a, b) => b.population - a.population)
Insert cell
Insert cell
Insert cell
Insert cell
// adapted from: https://github.com/zeke/all-the-cities/
cities = {
const pbf = new Pbf(await FileAttachment("cities@1.pbf").arrayBuffer());
const cities = [];
let lastLon = 0;
let lastLat = 0;
function readCity(tag, city, pbf) {
if (tag === 1) city.cityId = pbf.readSVarint();
else if (tag === 2) city.name = pbf.readString();
else if (tag === 3) city.country = pbf.readString();
else if (tag === 4) city.altName = pbf.readString();
else if (tag === 5) city.muni = pbf.readString();
else if (tag === 6) city.muniSub = pbf.readString();
else if (tag === 7) city.featureCode = pbf.readString();
else if (tag === 8) city.adminCode = pbf.readString();
else if (tag === 9) city.population = pbf.readVarint();
else if (tag === 10) {
lastLon += pbf.readSVarint();
city.loc.coordinates[0] = lastLon / 1e5;
} else if (tag === 11) {
lastLat += pbf.readSVarint();
city.loc.coordinates[1] = lastLat / 1e5;
}
}
while (pbf.pos < pbf.length) {
cities.push(pbf.readMessage(readCity, {
cityId: "",
name: "",
altName: "",
country: "",
featureCode: "",
adminCode: "",
population: 0,
loc: {
type: "Point",
coordinates: [0, 0]
}
}));
}
return cities
}
Insert cell
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