Raster¶
The georeferenced raster returned by mirrorworld.services, mirrorworld.elevation,
mirrorworld.satellite and mirrorworld.aerial.pdok.
- class Raster(data, crs, transform, nodata=None, band_names=None, metadata=<factory>)[source]¶
A georeferenced raster.
transformuses the affine convention of rasterio/GDAL: a pixel’s top left corner at columncand rowris atx = a*c + b*r + xoffandy = d*c + e*r + yoff, stored as(a, b, xoff, d, e, yoff). For north-up rastersb = d = 0andeis negative.
- Parameters:
- data: ndarray¶
Pixel values with shape (bands, rows, columns).
- transform: Tuple[float, float, float, float, float, float]¶
Affine transform from pixel to CRS coordinates.
- to_image(bands=None, percentiles=(2, 98))[source]¶
Renders one or three bands as an 8-bit PIL image, e.g. for previews or RGB inputs to a model.
8-bit data is used as is; other data is stretched between the given percentiles.
- save(path, pil_args=None)[source]¶
Saves the raster with its georeferencing.
.tif/.tiffwrites a GeoTIFF with all bands, data type, CRS and nodata (needsrasterio)..png/.jpgwrites an 8-bit rendering (seeto_image()) with a world file and a GDAL.aux.xmlCRS sidecar. Either way a.jsonfile withmetadataand band names is written beside it.
- utm_crs(lat, lon)[source]¶
Returns the WGS 84 / UTM zone CRS containing a point, a good default metric CRS for local work.
- bbox_to_crs(north, west, south, east, crs)[source]¶
Transforms a WGS84 bounding box to another CRS, densifying the edges so the result encloses it.
- read_cog(url, north, west, south, east, resolution=None, crs=None, resampling='nearest', band_names=None)[source]¶
Reads a bounding box from any cloud-optimized GeoTIFF over HTTP, fetching only the bytes needed, e.g. the whole-country LiDAR models that national agencies publish as single COGs.
- Parameters:
url (str) – HTTP(S) URL of the GeoTIFF.
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) Pixel size in units of
crs. Defaults to the file’s own.crs (str | None) – (optional) Output CRS. Defaults to the file’s own.
resampling (str) – (optional) Resampling method when the grid differs. Defaults to nearest.
band_names (List[str] | None) – (optional) Names for the bands.
- Returns:
The raster.
- Return type: