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

Utility function to get GDAL driver and creation options based on output extension #7

Closed
gillins opened this issue Jun 7, 2016 · 2 comments

Comments

@gillins
Copy link
Member

gillins commented Jun 7, 2016

Original report by Daniel Clewley (Bitbucket: danclewley, GitHub: danclewley).


Would having a function to get the GDAL driver and recommended creation options from a file extension make a useful addition to RIOS as a utility function?

This would allow scripts to set the output type based on the extension of the output file rather than hard coding or using environmental variables. It could also be used to set / check the extension for output files when setting the driver using an environmental variable.

Some code I wrote do do this is available from:

https://github.com/pmlrsg/arsf_dem_scripts/blob/master/arsf_dem/get_gdal_drivers.py

Usage is:

out_ext = os.path.splitext(outimage_file)[-1]
out_format = get_gdal_drivers.GDALDrivers().get_driver_from_ext(out_ext)
out_options = get_gdal_drivers.GDALDrivers().get_creation_options_from_ext(out_ext)

controls.setOutputDriverName(out_format)
controls.setCreationOptions(out_options)

If it would be useful to include as part of RIOS where would be a good place for it? Happy to tidy up existing code to fit into RIOS standards and submit a pull request. If not useful feel free to close this issue.

@gillins
Copy link
Member Author

gillins commented Jun 8, 2016

Original comment by Neil Flood (Bitbucket: neilflood, GitHub: neilflood).


Hi Dan,

thanks for these thoughts.

I think that the creation options part of this is now handled quite well using the driver-specific environment variables - have you checked that out? This was added on 2015-11-21 (https://bitbucket.org/chchrsc/rios/commits/441dbe575a5ee32951353d22cd264a9243ed477a), and I am reluctant to add anything more there. A given site can configure what the default driver options should be for any drivers of interest, and then just the act of selecting that driver picks up the appropriate driver options. I don't think that there is any need to provide any further capacity for that.

The selection of driver based on file suffix is a thought, and I have wondered about that before, but I am a bit reluctant. However, I will think a bit more on that one, and I might implement it.

cheers
Neil

@gillins
Copy link
Member Author

gillins commented Jun 8, 2016

Original comment by Daniel Clewley (Bitbucket: danclewley, GitHub: danclewley).


Hi Neil,

I was thinking more of a case where RIOS is installed but environmental variables haven't been set, e.g., when giving someone a script to run on their own system.

I guess having functions in RIOS to set creation options using either environmental variables or the output extension is going to cause confusion, especially if using environmental variables is the preferred way of doing it.

I'll mark this as closed then.

Thanks,

Dan

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

No branches or pull requests

1 participant