mirrorworld.lidar: LiDAR point clouds

Point clouds for a bounding box from Entwine Point Tile (EPT) datasets, fetching only the octree nodes that intersect the box down to a chosen spacing. Returns laspy.LasData. Needs pip install mirrorworld[lidar].

USGS 3DEP

find_datasets(north, west, south, east, refresh=False)[source]

Lists the surveys whose coverage intersects a bounding box, newest first.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • refresh (bool) – (optional) Re-download the coverage index (~9 MB, cached for the session).

Returns:

A list of Dataset objects.

Return type:

List[Dataset]

get_points(north, west, south, east, dataset=None, resolution=None, classes=None, max_points=50000000)[source]

Reads 3DEP LiDAR points inside a bounding box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • dataset (str | None) – (optional) Survey name from find_datasets(). Defaults to the newest one covering the box.

  • resolution (float | None) – (optional) Wanted point spacing in meters (Web Mercator units). Defaults to all points.

  • classes (Iterable[int] | None) – (optional) Keep only these ASPRS classes, e.g. [6] for buildings.

  • max_points (int) – (optional) Refuse larger requests. Defaults to 50 million.

Returns:

A laspy.LasData in EPSG:3857.

async get_points_async(north, west, south, east, session, dataset=None, resolution=None, classes=None, max_points=50000000)[source]
Parameters:
download_points(north, west, south, east, path, **kwargs)[source]

Same as get_points(), then writes a .laz or .las file.

Parameters:
Returns:

The laspy.LasData.

class Dataset(name, url, points, year)[source]

One 3DEP LiDAR survey.

Parameters:
  • name (str)

  • url (str)

  • points (int | None)

  • year (int | None)

name: str

Survey name, e.g. WA_KingCo_1_2021.

url: str

EPT dataset URL.

points: int | None

Total number of points.

year: int | None

Year parsed from the name, if any.

Usage sample:

from mirrorworld.lidar import usgs3dep

print(usgs3dep.find_datasets(47.6068, -122.3340, 47.6058, -122.3325))
las = usgs3dep.download_points(47.6068, -122.3340, 47.6058, -122.3325, "seattle.laz", resolution=1.0)
ground = las.points[las.classification == 2]

Environment Agency National LIDAR Programme (England)

Environment Agency LiDAR point clouds for England, from the Defra Survey Data Download service (https://environment.data.gov.uk/survey). Open Government Licence v3 (attribution: Environment Agency), no key.

The default product is the National LIDAR Programme (NLP) point cloud, surveyed since 2016/17. The data comes as whole 5 km British National Grid tiles (e.g. TL4055), one zipped LAZ per tile and survey year, typically 0.2-0.4 GB each: there is no way to fetch only part of a tile. Tiles are downloaded once into a cache directory and cropped locally.

Points are in EPSG:27700 with heights in meters above Ordnance Datum Newlyn, classified to ASPRS codes (1 unclassified, 2 ground, 3-5 vegetation, 6 building, 7 noise), without RGB. Surveys up to 2021 are mostly LAS 1.2 point format 1, later ones LAS 1.4 point format 6; density is about 2-6 points per m², higher in recent years. The year is the survey’s nominal year; the file name records the flight dates, which can start in the previous winter.

search() asks the service which tiles, products and years cover a box (the same request as the download page’s “Get available tiles”). Don’t guess years by requesting tile URLs: under load the service answers “no data” for tiles that exist.

get_points(north, west, south, east, year=None, directory=None, classes=None, max_tiles=4, product='national_lidar_programme_point_cloud')[source]

Reads point cloud data inside a bounding box, downloading the 5 km tiles it touches if they are not cached.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • year (int | None) – (optional) Survey year for every tile. Defaults to the newest year of each tile, so a box across a tile edge can mix survey years.

  • directory (str | None) – (optional) Where to keep the downloaded tiles. Defaults to cache_dir().

  • classes (Iterable[int] | None) – (optional) Keep only these ASPRS classes, e.g. [2] for ground.

  • max_tiles (int) – (optional) Refuse boxes needing more tiles than this (each is a 0.2-0.4 GB download). Defaults to 4.

  • product (str) – (optional) Point cloud product ID. Defaults to the NLP point cloud.

Returns:

A laspy.LasData in EPSG:27700, heights above Ordnance Datum Newlyn.

Raises:

ValueError – If the box needs too many tiles, or no tile has data.

download_points(north, west, south, east, path, **kwargs)[source]

Same as get_points(), then writes a .laz or .las file.

Parameters:
Returns:

The laspy.LasData.

search(north, west, south, east, product='national_lidar_programme_point_cloud')[source]

Lists the tiles covering a bounding box, from the service’s own tile search.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • product (str | None) – (optional) Keep only this product. Defaults to the NLP point cloud; None returns every survey product (DTM/DSM rasters, older lidar_point_cloud surveys, aerial photography, …).

Returns:

Tiles sorted by tile name, then newest year first.

Return type:

List[Tile]

find_years(tile, product='national_lidar_programme_point_cloud')[source]

Lists the survey years available for a 5 km tile, newest first.

Parameters:
  • tile (str) – Tile name, e.g. TL4055.

  • product (str) – (optional) Product ID. Defaults to the NLP point cloud.

Returns:

Years with data (possibly empty).

Return type:

List[int]

download_tile(tile, year=None, directory=None, product='national_lidar_programme_point_cloud')[source]

Downloads one tile and extracts its LAZ, unless it is already in directory. The zip is not kept.

Parameters:
  • tile (str) – Tile name, e.g. TL4055.

  • year (int | None) – (optional) Survey year. Defaults to the newest available.

  • directory (str | None) – (optional) Where to keep the LAZ files. Defaults to cache_dir().

  • product (str) – (optional) Point cloud product ID. Defaults to the NLP point cloud.

Returns:

Path of the LAZ file, <directory>/<product>/<year>/<name>.laz, keeping the provider’s file name (tile, survey project and flight dates, e.g. TL4055_P_12744_20230213_20230213.laz).

Raises:

ValueError – If the tile has no data (for that year), or the zip does not hold exactly one LAZ.

Return type:

str

tile_name(easting, northing)[source]

Name of the 5 km tile containing a British National Grid point, e.g. TL4055 for E 541000, N 257500.

Parameters:
  • easting (float) – Easting in meters (EPSG:27700).

  • northing (float) – Northing in meters.

Returns:

Two grid letters, then the easting and northing km of the tile’s south-west corner (two digits each).

Return type:

str

tile_bounds(tile)[source]

Bounds of a 5 km tile in EPSG:27700.

Parameters:

tile (str) – Tile name, e.g. TL4055.

Returns:

minx, miny, maxx, maxy in meters.

Return type:

Tuple[float, float, float, float]

crop_files(paths, bounds, classes=None, chunk_size=5000000)[source]

Crops LAS/LAZ files to a box and merges them, reading in chunks so whole tiles never sit in memory.

Parameters:
  • paths (List[str]) – LAS/LAZ files in one CRS.

  • bounds (Tuple[float, float, float, float]) – minx, miny, maxx, maxy in the files’ CRS.

  • classes (Iterable[int] | None) – (optional) Keep only these ASPRS classes.

  • chunk_size (int) – (optional) Points read at a time.

Returns:

A laspy.LasData with the header (point format, scales, offsets, CRS) of the first file with points in the box; points from files in another point format are converted to it.

cache_dir()[source]

Default tile cache: $MIRRORWORLD_CACHE/ea-lidar if set, else $XDG_CACHE_HOME/mirrorworld/ea-lidar, else ~/.cache/mirrorworld/ea-lidar.

Return type:

str

class Tile(product, year, resolution, tile, label, url)[source]

One downloadable tile of one survey product and year.

Parameters:
product: str

Product ID, e.g. national_lidar_programme_point_cloud or national_lidar_programme_dtm.

year: int

Survey year.

resolution: str

Resolution ID as the service gives it (1 for 1 m rasters and NLP point clouds; may be NaN).

tile: str

5 km tile name, e.g. TL4055.

label: str

The service’s label, e.g. national_lidar_programme_point_cloud-2023-1m-TL45ne.

url: str

Download URL of the zip.

Usage sample:

from mirrorworld.lidar import ea

print(ea.search(51.5085, -0.1290, 51.5070, -0.1260))            # tiles and survey years covering the box
las = ea.get_points(51.5085, -0.1290, 51.5070, -0.1260)         # downloads and caches each tile once
ground = las.points[las.classification == 2]

Any EPT dataset

get_info(url)[source]

Reads the header of an EPT dataset.

Parameters:

url (str) – Dataset URL, with or without /ept.json.

Returns:

An EptInfo.

Return type:

EptInfo

async get_info_async(url, session)[source]
Parameters:
  • url (str)

  • session (ClientSession)

Return type:

EptInfo

get_points(url, north, west, south, east, resolution=None, classes=None, max_points=50000000, max_concurrency=8)[source]

Reads the points of an EPT dataset inside a bounding box.

Parameters:
  • url (str) – Dataset URL.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • resolution (float | None) – (optional) Wanted point spacing in CRS units; deeper (denser) octree levels are skipped. Defaults to all points.

  • classes (Iterable[int] | None) – (optional) Keep only these ASPRS classification codes, e.g. [2] (ground) or [6] (building). Defaults to all.

  • max_points (int) – (optional) Refuse requests whose candidate nodes hold more points than this. Defaults to 50 million.

  • max_concurrency (int) – (optional) Maximum number of simultaneous downloads. Defaults to 8.

Returns:

A laspy.LasData in the dataset’s CRS (written into the header).

async get_points_async(url, north, west, south, east, session, resolution=None, classes=None, max_points=50000000, max_concurrency=8)[source]
Parameters:
download_points(url, north, west, south, east, path, **kwargs)[source]

Same as get_points(), then writes a .laz or .las file.

Parameters:
Returns:

The laspy.LasData.

class EptInfo(url, bounds, bounds_conforming, span, points, crs, schema)[source]

The header of an EPT dataset (ept.json).

Parameters:
url: str

Base URL of the dataset (without /ept.json).

bounds: Tuple[float, float, float, float, float, float]

Octree cube: minx, miny, minz, maxx, maxy, maxz.

bounds_conforming: Tuple[float, float, float, float, float, float]

Tight bounds of the actual points.

span: int

Grid cells per node edge; the root node’s point spacing is cube width / span.

points: int

Total number of points.

crs: str | None

Horizontal CRS, e.g. EPSG:3857.

schema: List[dict]

Point dimensions with scale/offset.

spacing(depth)[source]

Approximate point spacing in CRS units at an octree depth.

Parameters:

depth (int)

Return type:

float

depth_for_resolution(resolution)[source]

Shallowest depth whose point spacing is at most resolution.

Parameters:

resolution (float)

Return type:

int