Monday, 2 December 2019

python - GDAL/OGR Determine if dataset is raster or vector



I am writing a script using the GDAL/OGR Python bindings and it is possible that the user may provide a raster dataset or a vector dataset as input. If the user provides a vector dataset, the script will convert it to raster.


Is there a way to determine whether the dataset is raster or vector before opening them?


I could just try to open the dataset with OGR first and if it returns None I could try to open with GDAL, but I am looking for a more simple way like gdal.IsRaster(filepath) if it exists.



Answer



As of right now, there are two separate set of APIs for GDAL and OGR. Thus, the method you describe (try to open with OGR first and if it fails, open with GDAL) would be current way of doing it.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...