I have been looking at using OGR in/with Python. Initially I wanted to find an easy way to merge a number of shapefiles with OGR. But there appeared to be no straight forward way to do that using ogr2ogr from the commandline.
Python bindings for OGR are included in the installation for FWTools, and provided your PYTHONPATH in Windows is set up properly, all you need to get going is:
For other installations, e.g. OSGEO4W, you might need from osgeo import ogr
There is a script here (page 22) for merging shapefiles. But it works by iterating through first files and then each feature to write each one into a new shapefile. This took forever ! I guess what I was looking for was a program or way to simply take one shapefile and tack it to the “end” of the next without crawling through one field at a time and copying it over to the next file.
r = shapefile.Reader(“yourfile.shp“)
features = r.shapes()
print “Number of features: “,len(features)
for point in features[yourchoice].points:
print “Coordinates for Point “,cnt, point
Works like a char. But again, to simply aggregate many shapefile in one SHP, this would take to long. So for now Darren’s little Windows script to batch process the SHP’s with ogr2ogr has been the best way. I haven’t really used Python for such purposes but I guess you could.