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

Raise ValueError if get_gis_type results in UNKOWN_TYPE #289

Merged
merged 6 commits into from
Dec 13, 2022

Conversation

dcdenu4
Copy link
Member

@dcdenu4 dcdenu4 commented Dec 13, 2022

get_gis_type returns gdal.UNKOWN_TYPE (0) if the file cannot be opened as a raster or vector. This is inconsistent with the rest of the API including get_raster_info and get_vector_info which raise a ValueError in that circumstance. It's also not intuitive that a Microsoft Word file would return a GIS type of UNKOWN_TYPE. PGP is a GIS processing library that only works with valid GIS types.

Fixes #244

@dcdenu4 dcdenu4 requested a review from phargogh December 13, 2022 16:27
@dcdenu4 dcdenu4 marked this pull request as ready for review December 13, 2022 16:27
@dcdenu4 dcdenu4 added this to the 2.3.5 milestone Dec 13, 2022
@dcdenu4
Copy link
Member Author

dcdenu4 commented Dec 13, 2022

@phargogh, I'd be curious your thoughts on keeping UNKNOWN_TYPE around as a constant in __init__.py. In PGP, get_gis_type is the only place it's used, and InVEST only uses it in HRA, directly related to a get_gis_type call.

@phargogh
Copy link
Member

@dcdenu4 much to my surprise, GDAL does actually support drivers that are neither rasters nor vectors! So yes, let's keep the UNKNOWN_TYPE flag.

Here's my rationale:

from osgeo import gdal

for i in range(gdal.GetDriverCount()):
    try:
        metadata = gdal.GetDriver(i).GetMetadata()
    except Exception as error:
        print(error, 'ERROR')
    else:
        raster_capable = 'DCAP_RASTER' in metadata
        vector_capable = 'DCAP_VECTOR' in metadata
        if not raster_capable and not vector_capable:
            print(metadata['DMD_LONGNAME'])

which outputs:

Geographic Network generic file based model
Geographic Network generic DB based model

@phargogh
Copy link
Member

Source code looks good to me; I'm just waiting for the remaining tests to finish. There were a couple of conda 500 internal server errors, which are fine and flaky.

@phargogh phargogh merged commit ff9bf0f into natcap:main Dec 13, 2022
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.

pygeoprocessing.get_gis_type should raise an exception if gdal can't open the file
2 participants