Skip to content

gdal_calc: detect dataset creation failed#5817

Merged
rouault merged 2 commits intoOSGeo:masterfrom
kikitte:detect-dataset-creation-failed
May 30, 2022
Merged

gdal_calc: detect dataset creation failed#5817
rouault merged 2 commits intoOSGeo:masterfrom
kikitte:detect-dataset-creation-failed

Conversation

@kikitte
Copy link
Copy Markdown
Contributor

@kikitte kikitte commented May 30, 2022

What does this PR do?

gdal_calc should raise an error if it could not create output dataset, instead of raising an unexpected error when executing some code like myOut.SetGeoTransform(GeoTransformCheck) .

# create file
myOutDrv = gdal.GetDriverByName(format)
myOut = myOutDrv.Create(
os.fspath(outfile), DimensionsCheck[0], DimensionsCheck[1], allBandsCount,
myOutType, creation_options)
# set output geo info based on first input layer
if not GeoTransformCheck:
GeoTransformCheck = myFiles[0].GetGeoTransform(can_return_null=True)
if GeoTransformCheck:
myOut.SetGeoTransform(GeoTransformCheck)

I notice that the gdal c++ library will put an error message to stderr, for example ERROR 4: Attempt to create new tiff file /w/a.tif failed: No such file or directory. But it will be useful if we detect this error in python side, because gdal_calc is not only an command line tool but a library.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants