Skip to main content

Package for tiling georeferenced Rasterio DatasetReader objects according to the XYZ tiles standard.

Project description

pypi version pypi downloads publish ci security: bandit

RasterioXYZ

RasterioXYZ is a lightweight package for tiling georeferenced rasterio.DatasetReader objects according to the XYZ tiles standard written in and depending on the following:

  • python ^3.13
  • rasterio ^1.4.3

For greater functionality in navigating the tile-tree, see Mercantile.

Design

Memory efficiency

While faster tiling may be achieved by reprojecting and/or resampling the entire source image to the required CRS and maximum resolution, respectively, such an approach precludes tiling larger-than-memory rasters or those with the potential to be so (i.e. with resampling). By lazily reading and, if needed, resampling, reprojecting, and dtype casting windows of the source dataset for each tile, memory use is kept low.

Flexibility

Some basic design decisions for flexibility:

  • Imagery of all data types and PROJ-recognised projections can be tiled with no alterations made to the original dataset prior to tiling.
  • Tiles need not be generated for all zoom levels in a range - simply pass a sequence of integer zoom levels between 0 and 25 in any order.
  • Tiles can be saved in PNG or JPEG format, though the XYZ standard dictates the former (also lossless and appears to produce better colour balancing).
  • Use of any resampling technique through rasterio.enums.Resampling.
  • Creation of standard (256 px) or high (512 px) resolution tiles.
  • Ability to skip tiling at zoom levels requiring resolution upsampling.

Examples

import rasterio
import rasterioxyz

img = rasterio.open("georeferenced_image.tif")
tiles = rasterioxyz.Tiles(
  image=img,
  zooms=range(26),
  pixels=512,
  resampling=rasterio.enums.Resampling.bilinear,
  allow_upsample=False,
)
tiles.write()
# OR
tiles.serve()

Several pre-emptive measures can be taken to improve the speed of tiling:

  • Project source data in EPSG:3857
  • Cast and scale source data to uint8
  • Use the default value of 256 for pixels
  • Use the default value of rasterio.enums.Resampling.nearest for resampling
  • Set allow_upsample to False

Previously, tiles had to be written to disk before testing in desktop GIS platforms. With v0.1.1, tiles can be dynamically generated and served. Simply create a Tiles object with your data, call .serve(), then add the logged URL as an XYZ source or format it with a zoom, column, and row and request tiles through a browser. This is useful in testing and evaluating results prior to incurring cloud storage I/O costs. Software like QGIS cache tiled data and may ignore HTTP headers like If-Modified-Since. When tiling different datasets in quick succession, clearing the cache prevents tiles from previous datasets appearing in requests for newly tiled data. Alternatively, serve on a different port for each dataset.

Also added in v0.1.1 was the RasterioXYZ CLI. Once installed, enter rasterioxyz -h in a terminal to check it out.

Roadmap

Check the repository issues for possible future additions.

See the project changelog for fixes and improvements.

Contributions

Feel free to raise any issues, especially bugs and feature requests!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rasterioxyz-0.1.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rasterioxyz-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file rasterioxyz-0.1.1.tar.gz.

File metadata

  • Download URL: rasterioxyz-0.1.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for rasterioxyz-0.1.1.tar.gz
Algorithm Hash digest
SHA256 45595fe3e67dbcf56696e031a59e2ca89c0359e97f529ce36ea37717de4c1f04
MD5 7ef96ee589e8855f6117ad404edc8684
BLAKE2b-256 b20fc3efc6795fa5f5d006583a1a87d161df83d470de48fc4b2fc563fc197aaf

See more details on using hashes here.

File details

Details for the file rasterioxyz-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rasterioxyz-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7889098622828f886ffd883d22bd9a8e9bc2dd562c795ebc13262b177fbf204f
MD5 07bfa3ea1a221f8e0fc438bc9e574d7b
BLAKE2b-256 75d091f7efc17c074310754b56569ba0d26edce5fcb3a8cef3fee85e545f1e1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page