-
Notifications
You must be signed in to change notification settings - Fork 534
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
Switch to warped vrt internally for boundless reads #1161
Conversation
Note this is somewhat related to #1131, in which we've found the limits of very large warped VRTs. |
Short answer: no, source overviews will not be used that way Long answer: I see you use GDALCreateWarpedVRT(), and this function will not try to use sourcce overviews. Preliminary steps: create dataset of size 2048x2048, with uniform grey overview of size 1024x1024
Now test.c that basically use GDALCreateWarpedVRT() to create a view of reduced resolution at 1024x1024 pixels
Running this executable will generate
One possibility would be to use the return of the GDALCreateOverviewDataset() function as the hSrcDS argument of GDALCreateWarpedVRT(), but GDALCreateOverviewDataset() is C++/internal only.
generates
Note the addition of
Regarding |
I've uploaded wheels made from commit 82beae8 to S3 for testing.
To install the wheel for Python 3.6 on OS X (for example) into a new virtualenv (because this is a pre-release), execute the following command.
|
@sgillies Excellent, the wheels work well but the size might be a problem. |
Oh ok, I've actually tried this branch and now understand how you use GDAL. Sean's comment "Notice that we read from the VRT at its full resolution" made me take a wrong assumption on how you built the warped VRT. From what I see, you actually build a VRT at its full resolution, but you use GDADatasetRasterIOEx() to read it at lower resolution, and then https://github.com/OSGeo/gdal/blob/8372431040f2b17bb5f6b643c2bfdfcec8d6f630/gdal/frmts/vrt/vrtsourcedrasterband.cpp#L169 kicks in to select the appropriate source overview. Mystery solved |
Excellent! Thanks @rouault for having a 👀 at it ;-) |
Yes, thank you, @rouault! I've used the warped VRT because the non-warped VRT class doesn't expose floating point windows. I'll try to remember to search for or file a GDAL ticket about that. |
Rasterio has offered "boundless reads" as a feature – you can read an image window (in pixel space) that goes beyond the source raster's rows and columns and rasterio performs VRT-like source reading and compositing. The math has been buggy: at best it doesn't exactly match GDAL's math and, at worst, can drop a line or row of data.
This PR fixes the bug by switching from an approximation of GDAL's VRT logic to the use of a temporary VRT that represents the boundless window. It provides more accurate and reliable results and eliminates 2 chunks of brittle code in _io.pyx.
I'm using a warped VRT because GDAL doesn't surface a non-warped VRT constructor in its C API. As far as I can tell, reprojection is short-circuited when the input and output crs are the same. I think this is good enough for 1.0 and we could look at a more optimal implementation after that.
I'm concerned that source overviews will be skipped when we use the VRT like this. Notice that we read from the VRT at its full resolution. It seems that the test at https://github.com/OSGeo/gdal/blob/8372431040f2b17bb5f6b643c2bfdfcec8d6f630/gdal/frmts/vrt/vrtsourcedrasterband.cpp#L169 will thus fail and source overviews would be skipped. I'm going to ask GDAL developers for confirmation and guidance on this point.