Skip to content

Restore compatibility with rasterio >= 1.3#48

Open
wboykinm wants to merge 1 commit into
masterfrom
modernize/rasterio-compat
Open

Restore compatibility with rasterio >= 1.3#48
wboykinm wants to merge 1 commit into
masterfrom
modernize/rasterio-compat

Conversation

@wboykinm
Copy link
Copy Markdown

@wboykinm wboykinm commented May 5, 2026

Fixes #39

Summary

The mbtiler path no longer ran on current rasterio (tested against 1.4.4). Three API breaks fixed:

  • rasterio._io.virtual_file_to_buffer was a private API and has been removed. Switched _encode_as_png to the public rasterio.io.MemoryFile.
  • The affine profile key was deprecated in rasterio 1.0 in favor of transform. It was being silently ignored, so output PNG tiles had no transform set.
  • transform_bounds(..., densify_pts=0) is now rejected when the destination CRS is geographic (densify_pts must be at least 2 if the output is geograpic). Dropped the override; rasterio's default (21) is appropriate here.

Also dropped a brittle assert len(test_bytearray) == 34 in test_webp_writer — the exact webp byte count varies across libwebp / Pillow versions (currently 42 with Pillow 10), and the relative comparison right after it (complex data encodes larger than zero-data) still covers the intent.

Test plan

  • pytest — 19/19 pass against rasterio==1.4.4, Pillow==10.x, Python 3.10
  • End-to-end CLI smoke against test/fixtures/elev.tif:
    rio rgbify test/fixtures/elev.tif out.mbtiles \
      --base-val -100 --interval 0.1 \
      --min-z 10 --max-z 13 --format webp -j 4
    
    Produces a valid 84 KB mbtiles with tiles at z10–13 (1, 1, 2, 2).

The mbtiler path relied on three rasterio APIs that have since been
removed or tightened:

- rasterio._io.virtual_file_to_buffer is private and was removed; use
  the public rasterio.io.MemoryFile instead.
- The "affine" profile key was deprecated in rasterio 1.0 in favor of
  "transform".
- transform_bounds(..., densify_pts=0) is rejected when the destination
  CRS is geographic; use the default densification.

Also drops a brittle byte-length assertion in test_webp_writer; the
exact webp byte count varies across libwebp/Pillow versions and the
adjacent relative comparison still covers the intent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wboykinm wboykinm marked this pull request as ready for review May 5, 2026 20:40
@wboykinm wboykinm requested a review from pratikyadav May 6, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rasterio._err.CPLE_AppDefinedError: densify_pts must be at least 2 if the output is geograpic

1 participant