Skip to content

Return the data pixel for point queries on pixel corners shared with nodata - #321

Open
DresdenGman wants to merge 1 commit into
perrygeo:masterfrom
DresdenGman:fix-294-corner-nodata
Open

DresdenGman wants to merge 1 commit into
perrygeo:masterfrom
DresdenGman:fix-294-corner-nodata

Conversation

@DresdenGman

Copy link
Copy Markdown

Fixes #294.

Point queries on a pixel corner (or shared edge) are equidistant from every pixel touching the point, but the two interpolation modes picked one of them blindly: nearest floored its way to a single pixel and bilinear's masked fallback used round() on a single cell. If that pixel happened to be nodata, the query returned None even when another pixel sharing the corner had data, and the two modes disagreed with each other. On the example from the issue, nearest returned [None, None, 1, None] and bilinear [None, 1, None, None].

The fix only changes the case where the selected pixel has no data:

  • In the nearest path, when the chosen pixel is masked and the point sits exactly on a pixel boundary, the other pixels touching the point are checked before giving up.
  • In the bilinear fallback, the 2x2 cells are now examined in order of distance from the point (row-major on ties) instead of a single rounded pick.

If every touching pixel is nodata the result stays None, and points not on a boundary are unaffected. The issue example now returns [1, 1, 1, 1] under both modes.

Tests: two new tests in tests/test_point.py — one for the corner/edge regression (fails before, passes after), one guarding that all-nodata neighborhoods still return None. Full suite: 117 passed / 5 skipped before, 119 passed / 5 skipped after, no regressions; ruff check and format clean.

Points falling exactly on a pixel edge or corner are equidistant from every pixel sharing the boundary. When the selected pixel was nodata, point_query returned None even if another touching pixel had data.

For interpolate='nearest', check the other pixels that touch the point when the selected pixel is nodata and the point lies exactly on a pixel boundary. For bilinear's nodata fallback, examine the 2x2 cells in order of distance from the point instead of a single fixed cell.

Fixes perrygeo#294
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.

point_query does not always return a value for coordinates at the corner of a pixel bordered by no-data

1 participant