New answers tagged qgis-processing
Assuming that you always want to match like files from Original and Processed folders (i.e. Paris(O).shp always matched with Paris(P).shp or New York City(O).shp always matched with New York City(P).shp), You need to add a conditional after your second for loop to filter out everything you are grabbing from the processed folder. for f in glob.glob(root_dir ...
I've tested the following script on GNU/Linux, QGIS v.2.8.1, Processing v.2.6 and Processing v.2.9.1. import sys,os,glob from qgis.core import * from PyQt4.QtGui import * app = QApplication() QgsApplication.setPrefixPath("/usr", True) # Adjust it to your path QgsApplication.initQgis() path_dir = "/docs/borrar/test/" path_res = path_dir + "results/" ...
For the first question: You need to create a QgsVectorLayer object from your Shapefile path. Only then you can access the getFeatures() function. That is: for fname in glob.glob(path_dir + "*.shp"): for feature in QgsVectorLayer(fname,"any name","ogr").getFeatures(): My recommended way of doing it You don't actually need to access getFeatures() nor ...
Try this: import os, glob, shutil root_dir = "C:\Users\xxxx\Desktop\Test\\" country_dir = "Country_" grid_path = "C:\Users\xxxx\Desktop\Test\Grid\Grid.shp" # Get all files that constitute the Grid Shapefile gridShpFiles = glob.glob(grid_path[:-3]+"*") for path,dirname,files in os.walk(root_dir): if country_dir in path: for f in gridShpFiles: ...
os.walk returns a tuple of three values: for path, dirs, files in os.walk() Also consider http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
Following the idea from Cannot rename output file using standalone script for QGIS, I would do something like this: for file in files: if file.endswith('.shp'): pieces = list(os.path.splitext(file)) pieces=pieces[:-3]+"(B)" newFile = "".join(pieces) outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], ...
Try changing this line: outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], file, os.path.sep.join(path.split(os.path.sep)[:-1]) + os.path.sep + processed_dir + os.path.sep + file) to: outputs_2=general.runalg("qgis:clip", outputs_1['SAVENAME'], file, os.path.join(os.path.dirname(path), processed_dir, file))
Processing offers two approaches: using the file name or using the output name specified in the scripts. You can change the behavior in the Processing options:
The message points to variables result and fields not being what QgsVectorFileWriter expects them to be. There is a QString definition as unicode, so probably you can just cast variable Results as QString(Results). If that doesn't work, you'd get rid of the problem by specifying an Ascii filename (I suppose you specified Results as a filename). I couldn't ...
Top 50 recent answers are included