Skip to content

v.what.rast: Sample points on the southern and eastern edge - #7918

Open
Ady0333 wants to merge 1 commit into
OSGeo:mainfrom
Ady0333:v.what.rast-region-edge
Open

Ady0333 wants to merge 1 commit into
OSGeo:mainfrom
Ady0333:v.what.rast-region-edge

Conversation

@Ady0333

@Ady0333 Ady0333 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Problem

v.what.rast checks every point twice, and the two checks disagree about the region edges.

First it checks the box:

if (!Vect_point_in_box(Points->x[0], Points->y[0], 0.0, &box)) {
    outside_cnt++;
    continue;
}

Vect_point_in_box() includes all four edges, so a point sitting on the southern or eastern edge passes here.

Then it converts the point to a cell:

row = Rast_northing_to_row(Points->y[0], &window);
col = Rast_easting_to_col(Points->x[0], &window);
if (col < 0 || col >= window.cols || row < 0 || row >= window.rows)
    continue;

On the southern edge row comes out as rows, and on the eastern edge col comes out as cols. Both are one past the end, so the point is thrown away here instead. There is no warning and no counter, so you never find out. The column just stays empty.

r.what already returns a value for the same coordinate, so the two tools disagree.

How I ran into it

I set the region from the points I wanted to sample, which is the normal way to use this tool:

g.region vector=pts
v.what.rast map=pts raster=dem column=v

g.region puts the bounding box exactly on the outermost points, so my southernmost and easternmost points were dropped every time. On a small test with the region taken from a raster, four points out of seven came back empty and nothing was printed.

Fix

I bring those two edges into the last row or column, the same way r.what does.

The equality test is deliberate. Only a point sitting exactly on the edge converts to an index that is out of range, and anything further out is still rejected by the check below.

Tests

I added a pytest file. The expected values come from r.what on the same coordinates, so they are not guesses.

Without the fix, the southern edge, the eastern edge, the corner and the comparison with r.what all fail. Interior points and the northern and western edges pass either way, and so does a point that really is outside the region.

Vect_point_in_box() includes all four edges, so a point on the southern
or eastern edge passed the region check, but converting it gave a row or
column equal to rows or cols. The bounds check below dropped the point
without a message, leaving its column unset.

Bring those two edges into the last row or column, as r.what does.
@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite labels Sep 12, 2026
@Ady0333

Ady0333 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

/cc @echoix @petrasovaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant