I have over 400 layers, and I need to extract the extent information into a list.
Is there any way I can extract the extent for all 400 layers into a single file?
Copy and pasting one by one isn't practical.
I have over 400 layers, and I need to extract the extent information into a list.
Is there any way I can extract the extent for all 400 layers into a single file?
Copy and pasting one by one isn't practical.
A quick google on GIS Stack Exchange has the following resources:
Put those together with a simple csv write command using pyQGIS suggests the following as a first attempt:
with open ("outputfile.csv","w") as off:
off.write("LAYERNAME,MINX,MAXX,MINY,MAXY")
#get all map layers:
layers = QgsProject.instance().mapLayers().values()
#loop through layers
for layer in layers:
#get extent of current layer
ext = layer.extent()
xmin = ext.xMinimum()
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum()
#write to csv file
off.write("\n"+layer.name()+","+str(xmin)+","+str(xmax)+","+str(ymin)+","+str(ymax))
Disclaimer: put together from code snippets and not tested. However this does give a quick idea of an initial method for further development.