I'm writing a standalone script for QGIS. In this script I want to import a couple of text files saved as .xyz. When I import them in QGIS I have to use "Import layers as delimited text", thus they are not rasters. They are text files with lots of rows and each row contains x,y and z coordinates.
After I import them I want to check a condition and export them to a new folder. The import part works fine but I get no export files in my output folder. That's the export part of the script:
lyr = QgsVectorLayer(uri, name, "delimitedtext") outDir = 'C:/Users/user/Desktop/output' fields = lyr.fields() QgsVectorFileWriter.writeAsVectorFormat(lyr, outDir, "utf-8", fields, "CSV", layerOptions=['GEOMETRY=AS_XYZ'])
When I try to run the script, I don't get an error message but there are also no files in my output folder. I don't see the error. Can someone help me?
I'm using QGIS 3.4.13
I checked the answers and modified the code but it is still not working. Still no error message and still no files in my output folder.
This is the whole function without the condition:
def moveFiles(self): inputDir = self.dlg.input_folder.text() #directory of xyz files - "Users/denni/Desktop/xyz_data" outDir = self.dlg.output_folder.text() #output directory - "C:/Users/denni/Desktop/output/" crs = "EPSG:25832" for file in glob.glob("*.xyz"): uri = "file:///" + inputDir +"/"+ file + "?type=csv&delimiter=%s&crs=%s&xField=%s&yField=%s" % (" ", crs, "field_1", "field_2") name = file.replace('.xyz', '') lyr = QgsVectorLayer(uri, name, "delimitedtext") outputPath = outDir + file QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", layerOptions='GEOMETRY=AS_XYZ')
What could be the problem?