1
for layers in glob.glob("*.las"):
        processing.runalg("grass7:r.in.lidar", "input_las",5,1,"",1,100,"","",5,"","",False,True,True,"331289.57265,337990.42735,4558790.0,4560890.0",0,layers+"E:/las_new/.tif")

{'output': 'PNOA_2016_CAT_huso31_346-4560.lasE:/las_new/.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4562.lasE:/las_new/.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4564.lasE:/las_new/.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4566.lasE:/las_new/.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4568.lasE:/las_new/.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4570.lasE:/las_new/.tif'}
output_ras=("E:/las_Ras")

for layers in glob.glob("*.las"):
    processing.runalg("grass7:r.in.lidar", "input_las",5,1,"",1,100,"","",5,"","",False,True,True,"331289.57265,337990.42735,4558790.0,4560890.0",0,layers+"output_ras.tif")

{'output': 'PNOA_2016_CAT_huso31_346-4560.lasoutput_ras.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4562.lasoutput_ras.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4564.lasoutput_ras.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4566.lasoutput_ras.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4568.lasoutput_ras.tif'}
{'output': 'PNOA_2016_CAT_huso31_346-4570.lasoutput_ras.tif'}

for layers in glob.glob("*.las"):
    processing.runalg("grass7:r.in.lidar", "input_las",5,1,"",1,100,"","",5,"","",False,True,True,"331289.57265,337990.42735,4558790.0,4560890.0",0,"output_ras.tif")

{'output': 'output_ras.tif'}
{'output': 'output_ras.tif'}
{'output': 'output_ras.tif'}
{'output': 'output_ras.tif'}
{'output': 'output_ras.tif'}
{'output': 'output_ras.tif'}

I would like to batch process many LAS files to rasters using the PyQGIS algorithm. As you can see in the code, I think the final problem is with the output. It does not write the files out to my defined output pathway as tif files. Also how can I make sure the naming of output rasters are according to the original LAS they are generated from? What am I doing wrong here? Not a pro at Python. Started 3 days ago.

1

Try to run like this. Brief description is in the script.

import os, glob

folder = "E:/LAS/" # replace to your folder. don't forget "/"

for las_file in glob.glob(folder + "*.las"): # E:/LAS/*.las

    # get las_file name without extension.
    # [:-4] gets name without extension if extension includes just 3 characters
    new_file_name = os.path.basename(las_file)[:-4]

    new_file_path = "E:/las_new/" + new_file_name + ".tif" # E:/las_new/las_file_name.tif

    processing.runalg("grass7:r.in.lidar", las_file, 5, 1, "", 1, 100, "", "", 5, "", "", False, True, True, "331289.57265,337990.42735,4558790.0,4560890.0", 0, new_file_path)
  • Sahbaz Thank you for this information. I tried this code but when i finish with the precessinf.runlog it gives me a syntax and an indent error. 'for las_file in glob.glob(folder + "*.las"): # get las_file name without extension. # [:-4] gets name without extension if extension includes just 3 characters new_file_name = os.path.basename(PNOA_2016_CAT_huso31_346)[:-8] new_file_path = "E:/Rohan/Heimdall/data/LAS/" + new_file_name + ".tif" # .tif – RK4gis Apr 24 '18 at 15:12
  • Check indentation of your code. What is the error text? And what is PNOA_2016_CAT_huso31_346. Is it a string? It would be las_file variable, I guess. – Kadir Şahbaz Apr 24 '18 at 15:26
  • Sahbaz As I set the folder and the glo.glo, the variable is of string type:path="E:/Rohan/Heimdall/data/LAS/*.las" files=glob.glob(path). How do i import all the files in the folder as a float variable? print(files) ['E:/Rohan/Heimdall/data/LAS\\PNOA_2016_CAT_huso31_346-4560.las', 'E:/Rohan/Heimdall/data/LAS\\PNOA_2016_CAT_huso31_346-4562.las', Indent in the PyQGIS editor is fine (4 spaces after the for loop line). unable to figure this one out. Indent in the PyQGIS editor is fine (4 spaces after the for loop line) but when i copy paste into the QGIS Python console it changes. Suggestion? – RK4gis Apr 25 '18 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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