[Qgis-user] Python Code to Clip Vector layers
Thomas Gratier
osgeo.mailinglist at gmail.com
Wed May 11 08:21:04 PDT 2011
Hello,
a working example with ogr2ogr embeded
#####################################################################
# clip_shp_to_shp.py
import os
import glob
def clip_shp_to_shp(directory, shpclippath, pref="", suf="_clip"):
# List shp file in a directory (not recursive)
listResults = glob.glob(os.path.join(directory, '*.shp'))
# call ogr2ogr to clip with shpclip var
import subprocess
for source in listResults:
subprocess.call(["ogr2ogr", "-f", "ESRI Shapefile", "-clipsrc",
shpclip, os.path.basename(source) + "_clip.shp", source])
# set clipping shp path
shpclip = "/home/thomas/git/python_scripts/clipping_area.shp"
# set dir where searching shp to clip
directory = os.getcwd()
clip_shp_to_shp(directory, shpclip)
#####################################################################
Regards
ThomasG
GIS specialist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20110511/540de7f9/attachment.html>
More information about the Qgis-user
mailing list