Skip to content

Instantly share code, notes, and snippets.

@eknowles
Created June 6, 2024 10:28
Show Gist options
  • Save eknowles/1ffad8c062a69e45e5453980bf97e531 to your computer and use it in GitHub Desktop.
Save eknowles/1ffad8c062a69e45e5453980bf97e531 to your computer and use it in GitHub Desktop.
UPRN PMTiles
bun --watch index.ts
pmtiles serve ./files/script --port 9421 --public-url http://localhost:9421 --cors http://localhost:9420
Bun.serve({
port: 9420,
hostname: "localhost",
fetch() {
return new Response(Bun.file("map.html"));
},
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>UPRN</title>
<script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script>
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl/dist/maplibre-gl.css">
<style>
html,body { padding: 0; margin: 0; }
#map {
width:100vw;
height:100vh
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = new maplibregl.Map({
container: 'map', // container id
style: 'https://api.maptiler.com/maps/uk-openzoomstack-outdoor/style.json?key=ynz58rRjiygeONss49bn', // style URL
center: [-1.3545053, 52.056308], // starting position [lng, lat]
zoom: 13 // starting zoom
});
map.on('style.load', () => {
const waiting = () => {
if (!map.isStyleLoaded()) {
setTimeout(waiting, 200);
} else {
map.addSource('uprn_source', {
type: 'vector',
url: 'http://localhost:9421/uprn.json'
});
map.addLayer(
{
'id': 'uprn-points',
'type': 'circle',
'source': 'uprn_source',
'source-layer': 'points',
'paint': {
"circle-color": "rgb(185,38,38)",
"circle-opacity": 0.8,
}
},
);
}
};
waiting();
});
</script>
</body>
</html>
#!/usr/bin/env bash
curl 'https://api.os.uk/downloads/v1/products/OpenUPRN/downloads?area=GB&format=CSV&redirect' -L -o 'files/script/uprn.zip'
tar -zxvf 'files/script/uprn.zip' 'osopenuprn_202405.csv'
mv 'osopenuprn_202405.csv' 'files/script/uprn.csv'
duckdb -c "install spatial;load spatial;copy (select st_point(LONGITUDE, LATITUDE) as geometry, UPRN as uprn from 'files/script/uprn.csv') to 'files/script/uprn.fgb' WITH (FORMAT GDAL, DRIVER 'FlatGeobuf');"
tippecanoe -z13 -rg -K5 -kg -X -f -o 'files/script/uprn.pmtiles' -l points 'files/script/uprn.fgb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment