This might be a dumb question, but I wasn't able to find the answer anywhere.
Reading the metadata of a raster file in Python using GDAL is as easy as:
result = str(gdal.Info(raster.tif))
print result
In this case I want to do the same for a shapefile. I know I can use ogrinfo -ro -so -al foo.shp
in the shell, but I have not found a way to do the same only in Python within a single line.
I'm looking for something like:
result = str(ogr.Info(shapefile.shp))
print result
Am I missing something obvious or is there really no function like this?
Best Answer
Here is a more convoluted way to call anything gdal-related, using the subprocess module :
This acts as a virtual shell of sorts, and prints out whatever the shell returns. Here's some documentation about subprocess. It might be a bit heavy for what you want to do, but I've found it very useful for some tasks I had to do which weren't do-able using the GDAL module.
(NB. The decode/strip part is there just so that the output looks nicer.)