-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create_cutline expose rasterio rowcol op parameter to fix pixel raste… #759
create_cutline expose rasterio rowcol op parameter to fix pixel raste… #759
Conversation
…r x,y approximation
thanks @Martenz |
It will take some time from my side |
…lue. TODO: next need to test with specific feat and round or ceiling operators
…not one of the accepted methods by rasterio.transform.rowcol
Hi, I added the operator parameter to the existing unit tests, and I also added a test to check and raise an exception if the operator is not one of the accepted methods for the rasterio.transform.rowcol function. This means the cutline is now tested against previous implementations, allowing future users to specify something other than math.floor to obtain XS, YS pixel values if needed. As for testing my specific issue (#758), I'm not entirely sure how to proceed. I think the problem arises because the mask is the exact contour line of a group of pixels, and with the applied approximations, the default math.floor operator primarily selects the pixels on the left side, with a few pixels inside the mask. This happens regardless of any adjustments to vrt_options. Using the round operator seems to be the only solution for accurate pixel selection in this case. To test this behavior, I might add a fixture with a cog.tif file and a small feature mask that matches the exact pixel boundaries. However, I'm unsure about what exactly to assert in this case. Anyhow just to double check I run all test also replacing the operator op to all test with "round" and they pass successfully 100%. Apologies if my unit testing skills are lacking, and thank you for your support. |
…ature/improve-cutline-pixel-approx
src_y, src_x = rowcol(src_dst.transform, xs, ys) | ||
polygon = ", ".join([f"{x} {y}" for x, y in list(zip(src_x, src_y))]) | ||
src_y, src_x = rowcol(src_dst.transform, xs, ys, op=op) | ||
polygon = ", ".join([f"{int(x)} {int(y)}" for x, y in list(zip(src_x, src_y))]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cast x and y to int
to avoid rasterio/rasterio#3219
geometry_crs="epsg:4326", | ||
op=np.ceil, | ||
) | ||
assert cutline_npceil != cutline_npfloor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added specific tests to show the difference between operators
@Martenz made some edits to your PR, hope you're 👍 I'll wait for your 👍 before merging |
Thanks @vincentsarago for your support on this, and sorry for my late reply. I think is fine as far as I can use the round now. I will test it tomorrow. |
Works great as tested. Thanks again, I hope to contribute more. |
create_cutline expose rasterio rowcol op parameter to fix pixel raster x,y approximation
Related issue: #758