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.

Could you not check the file extension before doing anything else?
–
Darren CopeJan 8 '13 at 18:58

@RagiYaserBurhum is spot on. If you want a 'clean' looking line, how about wrapping your try except into a function and calling that function. Also, I believe GDAL 2.0 was/is considering a merge of gdal and ogr.
–
Jay LauraJan 8 '13 at 19:17

@DarrenCope - I could check the file extension, but then my script would have to know exactly which file extensions are raster and which are vector. Thats a lot of constants to include in the script.
–
BrianJan 9 '13 at 15:50