Skip to content
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

ENH: Add rasterio.vrt.BuildVRT #2573

Closed
snowman2 opened this issue Aug 26, 2022 · 12 comments · May be fixed by #2699
Closed

ENH: Add rasterio.vrt.BuildVRT #2573

snowman2 opened this issue Aug 26, 2022 · 12 comments · May be fixed by #2699

Comments

@snowman2
Copy link
Member

https://gdal.org/api/gdal_utils.html#_CPPv412GDALBuildVRTPKciP12GDALDatasetHPPCKcPK19GDALBuildVRTOptionsPi

Thoughts about adding a python interface to GDALBuildVRT ?

@sgillies
Copy link
Member

sgillies commented Sep 8, 2022

Users want something like this. Myself, I have a hard time getting over how terrible the GDALBuildVRT API is. It's got a score of optional arguments that are passed as key=value strings. We get all the downsides of a strongly typed language, but without the upsides. These arguments can't be type-checked at compile time. Trying to use GDALWarp was no fun.

@gboeing
Copy link

gboeing commented Dec 29, 2022

I second this. It'd be extremely useful.

@sgillies
Copy link
Member

@gboeing can you say more? How would you use it? What are you doing now as a workaround? Generating XML using Python? Calling gdalbuildvrt in a subprocess?

@gboeing
Copy link

gboeing commented Dec 31, 2022

@sgillies a common use case for OSMnx would be something like taking a bunch of SRTM elevation rasters, building a VRT, then attaching elevation to street network nodes. Currently OSMnx uses GDAL to build VRTs here. That means that this module imports both rasterio and osgeo.gdal. As far as I can tell, this is a no-no. From the rasterio docs:

Rasterio and GDAL’s bindings can contend for global GDAL objects. Unless you have deep knowledge about both packages, choose exactly one of import osgeo.gdal or import rasterio.

GDAL’s bindings (gdal for the rest of this document) and Rasterio are not entirely compatible and should not, without a great deal of care, be imported and used in a single Python program.

However, it works so far. But this seems pretty suboptimal. It would be wonderful if rasterio had a BuildVRT equivalent so we could exclusively use rasterio.

@snowman2
Copy link
Member Author

I have a draft implementation in #2698 I have been working on.

@snowman2
Copy link
Member Author

snowman2 commented Dec 31, 2022

This would also be useful for #2696 & #2682

UPDATE: After further inspection, that is not the case. They must have the same CRS.

@gboeing
Copy link

gboeing commented Dec 31, 2022

I have a draft implementation in #2698 I have been working on.

@snowman2 this looks great!

@sgillies
Copy link
Member

@gboeing thank you, I read the osmnx code and see what it's doing. I left some comments on #2698 for @snowman2.

@snowman2
Copy link
Member Author

snowman2 commented Jan 1, 2023

With #2698, @gboeing could change the code from:

gdal.BuildVRT(filepath, filepaths).FlushCache()

to this:

import rasterio
import rasterio.shutil

with rasterio.open(filepaths) as vrt:
    rasterio.shutil.copy(vrt, filepath)

@gboeing
Copy link

gboeing commented Jan 1, 2023

Thanks all. Yes this proposed solution looks like it would be straightforward enough.

sgillies added a commit that referenced this issue Jan 2, 2023
Instead of GDALBuildVRT

Resolves #2573
@snowman2
Copy link
Member Author

snowman2 commented Jan 3, 2023

Alternate solution in #2699.

@snowman2
Copy link
Member Author

Related: #2498

@sgillies sgillies added wontfix and removed cython labels Apr 26, 2023
sgillies added a commit that referenced this issue May 26, 2023
Instead of GDALBuildVRT

Resolves #2573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants