I have a few thousand polygon shapefiles in a folder that I would like the SAGA Split Features Layer tool to perform its operation on. The operation and parameters are the same for every polygon, but just can't get it to iterate across the files. Below is the result I want.


exec(open('C:/GIS Data/ab_grids/feature_split.py'.encode('utf-8')).read()) Traceback (most recent call last): File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 11, in File "C:\OSGeo4W/apps/qgis-ltr/./python/plugins\processing\tools\general.py", line 108, in run return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context) File "C:\OSGeo4W/apps/qgis-ltr/./python/plugins\processing\core\Processing.py", line 183, in runAlgorithm raise QgsProcessingException(msg) _core.QgsProcessingException: Unable to execute algorithm Could not load source layer for SHAPES: invalid value

enter image description here ====>enter image description here

# split twp grid into 2x2 grid
import processing
import glob
import os

# folder where polygons are stored
source = "r'C:\GIS Data\ab_grids\twp_polygons'"
files = glob.glob(source + "*.shp")
output = "r'C:\GIS Data\ab_grids\twp2_2'"


1 Answer 1

# split many polygon files into nxn polygons

import processing
import glob

path = "C:/GIS/...."

for file in glob.glob("*.shp"):
    input_layer = os.path.join(path,file)
    output_layer = input_layer.replace(".shp","_split.shp")
    params = {'SHAPES':input_layer,
        'NX':2,   # for 2x2 grid

    processing.run("saga:splitfeatureslayer",params)  #saga feature split aglorithm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.