Repository navigation
fix: warp rendered GeoTIFFs to Web Mercator so overlays land in place - #20
Merged
Merged
Conversation
The browser places a GeoTIFF overlay by its four lon/lat corners and stretches it linearly in Web Mercator, but the image was rendered on the file's native grid and placed by transform_bounds' lon/lat envelope. Any non-Mercator raster (eo-gpt writes UTM, EPSG:6933, EPSG:3832) landed rotated and stretched: up to 9.5 km off for a 180 km UTM raster at 68N, ~0.7 km for a 40 km one, ~140 m for 10 km. Two rasters in different projections stopped overlapping, and imagery slid against vector polygons. _to_web_mercator() warps the finished RGBA (nearest neighbour; masking still runs on the native grid, unchanged) onto a Web Mercator grid and returns its exact lon/lat bounds. EPSG:3857 input is passed through; rasters reaching past 85.05 degrees keep the old placement with a warning. Tests place the PNG the way the browser does: three markers on an 80 x 60 km UTM raster at 68-69N land within one 100 m pixel (36-75 m) where the native-grid placement put the worst 1.3 km off. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GeoTIFF overlays were drawn in the wrong place whenever the raster was not already in Web Mercator. This warps each rendered image onto a Web Mercator grid before it is sent to the browser, so overlays line up with the basemap, with vector layers, and with each other.
The problem
process_geotiff_rgb/process_geotiff_singlebandrendered the PNG on the file's native grid and reported its lon/lat bounding box (transform_bounds). The browser places an image source by those four corners and stretches it linearly in Web Mercator. For a UTM or equal-area raster this rotates and stretches the image:Two rasters in different projections (e.g. UTM and EPSG:6933) are misplaced differently, so they visibly fail to overlap. Vector polygons are unaffected, so imagery appears to slide against them.
The fix
_to_web_mercator()takes the finished RGBA from_process_rgb/_process_singlebandand reprojects it with nearest-neighbour resampling onto a Web Mercator grid. Pixels outside the source footprint get alpha 0. It returns exact lon/lat bounds, which form an axis-aligned box in both CRSs, so four-corner placement is exact.Tests
server/tests/test_geotiff_placement.py:The rest of the suite is unchanged relative to
main(same pre-existing failures/errors in the MCP and screenshot harness).🤖 Generated with Claude Code