lutraconsulting / serval

QGIS plugin for setting raster pixel values
42 stars 12 forks source link

support editing netCDF files #41

Open visr opened 2 years ago

visr commented 2 years ago

I noticed in https://github.com/lutraconsulting/serval/pull/37/files#diff-f2560f16ca0305bd2df9c6351db8df4e106894faf5d0ad53d09fa5c6effaab4dR689 there were some updates to check_layer. One of the checks that has to pass is

os.path.isfile(layer.dataProvider().dataSourceUri()), # is it a local file?

When opening a local netCDF file in QGIS this check will always fail, since the dataSourceUri will be of the form NETCDF:"path/to/data.nc":my_var. Would it be possible to modify this check such that it passes for netCDF files? I'm not sure of a robust method that works in general, though splitting on : may be ok.

The next check check_gdal_driver_create_option, passes without problems. Though perhaps it'd be good to close the dataset created there? Is there a reason that checking the driver metadata for the creation option is not used there, like these gdal docs?

dataset = gdal.Open(layer.dataProvider().dataSourceUri(), gdal.GA_ReadOnly)
driver = dataset.GetDriver()
metadata = driver.GetMetadata()
metadata.get(gdal.DCAP_CREATE) == "YES"