[gdal-dev] Use Python to open every raster or vector GDAL supported datasource under a directory

Even Rouault even.rouault at spatialys.com
Thu Feb 19 12:24:36 PST 2015


Adrien,

> 
> Using the GDAL API, preferably the Python one, i'd like to find and open
> every raster or vector GDAL supported datasource under a directory.
> 
> Is there any existing easy way to achieve this?
> 
> My goal is to perform test on datasources, topology correctness, CRS
> presence, metadata consistency etc.
> 
> I began with trying gdal.Open and ogr.Open on every file returned by
> os.walk

Sounds good. There are also datasets that consits of directories directly 
(shapefile directory, filegdb, ...)

You could use gdal.IdentifyDriver() as well which might be a bit faster if you 
don't need to know more than the driver that handle the file (which doesn't 
look like being the case given what you mention above) . Note that 
IdentifyDriver() works only on raster datasets in GDAL 1.X and has been 
extended to vector as well in GDAL 2.0


> but i'm surprised opening a .shx file returns no error, for
> example...

Yes, that's a bit odd to accept opening through the .shx file. But you'd have 
the same issue with the .dbf, which is a legitimate entry since the shapefile 
driver can handle pure .dbf files without .shp.

Even
-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list