Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.
#MASS CLIPPING (ogr2ogr)
#Stefan Safranek
#Shape Files by US-States

import os, glob
import subprocess
from osgeo import ogr

# Input folders
saveFolder = "C:\\Users\\Stefan\\Desktop\\experiment code\\clipping output"

# Input layers
folderOne = glob.glob("C:\\Users\\Stefan\\Desktop\\experiment code\\usa states\\*.shp")
folderTwo = glob.glob("C:\\Users\\Stefan\\Desktop\\experiment code\\boundary\\*.shp")
i = 1

for fileTwo in folderTwo:
    for fileOne in folderOne:
        stateName = str(fileOne).split('\\')
        print stateName
        last = len(stateName)
        stateName = stateName[last-1]
        saveFile = saveFolder + "\\CLIPPED_dma_" + stateName

        #OGR2OGR METHOD
        subprocess.call(["ogr2ogr", "-f", "ESRI Shapefile", "-clipsrc", fileOne, saveFile, fileTwo], shell=True)

    print "layer clipped by " + stateName[last-1]
    i += 1

print "Done!"
print str(i) + " layers clipped"
print ":-D"
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.