This repository is an R package that provides helpers for working with the National Library of Scotland (NLS) OS town-plan XYZ tile pyramids, used for the Leeds tram mapping case study.
Core package functions
Tile maths:
-
tile_coords_to_xy()(lon/lat -> x/y) -
tile_xy_to_lonlat()(x/y -> lon/lat) -
tile_webmerc_extent()(tile -> EPSG:3857 extent)
NLS tile access:
-
nls_tile_rast_zxy()(read a z/x/y tile into a georeferencedterraraster) -
nls_tile_rast_lonlat()(read the tile containing a lon/lat)
Tile selection:
-
nls_tiles_near_lonlat()(compact set of nearby tiles, useful for small mosaics) -
nls_tiles_for_polygon()(tile indices intersecting ansfpolygon)
Downloading/stitching a larger Leeds mosaic
For a reproducible end-to-end download/stitch workflow (including chunked merging), see the standalone script:
scripts/download_leeds_nls_tiles.R
That script caches downloaded tiles under .cache/ and writes tiles_merged_leeds.tif (these outputs are gitignored).
You can download a 100MB file with all of the tiles in a 1km radius of central Leeds from the releases of this repo and open up in QGIS or similar as shown below:

Documentation
- User vignette:
vignettes/nls-tiles.Rmd - pkgdown site: https://itsleeds.github.io/leedstrams/
- Developer-only one-off checks:
dev/tests.Rmd
Notes
Keep remote tile downloads limited when rendering documentation, and prefer running larger downloads via the script above.
Plan
- Download the town map dataset from Scottish Library: https://maps.nls.uk/os/townplans-england/leeds2.html
- Digitise the tramway centerlines from there
- Digitise the tram network from Alex’s image data
- Combine both datasets into a single tramway network
- Bonus: track lines
- Comparing with OSM
Town plan data
Individual tiles can be accessed from URLs such as https://mapseries-tilesets.s3.amazonaws.com/os/town-england/North/19/259898/168840.png.
This is a raster tile pyramid: zoom level 19, tile coordinates 259898, 168840.
The general pattern is: https://mapseries-tilesets.s3.amazonaws.com/os/town-england/North/{z}/{x}/{y}.png
You can copy-paste that URL into QGIS ‘XYZ Tiles’ to access the tiles directly as shown below:

You can also use the ceramic package to download tiles:
