I wrote a pyqgis script that should iterate over a folder with xyz files, check if the bouding box overlaps with a polygon in my QGIS project and if yes, it should copy the file into a new folder.
I don't get an error message but nothing happens either. My output Folder remains empty. I just don't see the problem. Can someone please help me find the error, I've already spent too much time on this.
def moveFiles(self):
mask = self.getBoundingBox() #BoundingBox of polygon layer
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")
lyr.selectAll()
lyr.boundingBoxOfSelected()
outputPath = outDir + file
self.iface.addVectorLayer(file)
if mask.xMinimum() <= lyr.xMinimum() <= mask.xMaximum() and mask.yMinimum() <= lyr.yMinimum() <= mask.yMaximum():
QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", layerOptions='GEOMETRY=AS_XYZ')
if mask.xMinimum() <= lyr.xMaximum() <= mask.xMaximum() and mask.yMinimum() <= lyr.yMinimum() <= mask.yMaximum():
QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", layerOptions='GEOMETRY=AS_XYZ')
if mask.xMinimum() <= lyr.xMaximum() <= mask.xMaximum() and mask.yMinimum() <= lyr.yMaximum() <= mask.yMaximum():
QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", layerOptions='GEOMETRY=AS_XYZ')
if mask.xMinimum() <= lyr.xMinimum() <= mask.xMaximum() and mask.yMinimum() <= lyr.yMaximum() <= mask.yMaximum():
QgsVectorFileWriter.writeAsVectorFormat(lyr, outputPath, 'utf-8', lyr.crs(), "CSV", layerOptions='GEOMETRY=AS_XYZ')
I'm using QGIS 3.4