[R-sig-Geo] Open source GIS cataloging software?
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu Feb 12 00:31:56 CET 2009
2009/2/11 Dylan Beaudette <debeaudette at ucdavis.edu>:
> Nice idea. I think that a simple python script should be able to do this,
> using the gdal/ogr module. Note that the bounding boxes will only be useful
> if:
> 1) the data are all in the same coordinate system
> 2) the data all contain enough SRS information to convert to a common
> coordinate system
hup ho, here we go - a little python script. This one just does ogr.
Save as 'catalogger.py' and run with 'python catalogger.py
/path/to/maps'. The output is just raw python dicts at the moment, but
easy enough to turn into a CSV file. Some notes:
* shapefiles appear lots of times since the .dbf, .shx and .shp
(maybe others) all seem to be valid ogr descriptors.
* shapefiles are also sub-layers of the directories they are in
* extents for multi-layer ogr datasources are only meaningful if the
SRSs are the same.
import ogr
def testOgr(filepath):
try:
f = ogr.Open(filepath)
extent = [None,None,None,None]
for i in range(f.GetLayerCount()):
l = f.GetLayer(i)
e = l.GetExtent()
extent=[max(e[j],extent[j]) for j in range(4)]
return {'Name': f.GetName(), 'Extent': extent, 'Layers':
f.GetLayerCount()}
except:
return None
import os
def dirwalk(dir):
"walk a directory tree, using a generator"
for f in os.listdir(dir):
fullpath = os.path.join(dir,f)
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
for x in dirwalk(fullpath): # recurse into subdir
yield x
else:
yield fullpath
def ogrWalk(path):
for p in dirwalk(path):
t = testOgr(p)
if t:
print t
if __name__=="__main__":
import sys
path = sys.argv[1]
ogrWalk(path)
More information about the R-sig-Geo
mailing list