0

I need to use pyQGIS to write a script that will run the r.in.lidar GRASS 7 on a set of LAS files.

I am terrible at Python, but I need this for my task. I would like to process as a batch. How can I set up my script in the PyQGIS console? And how do I set input in the arguments?

enter image description here

0

1 Answer 1

1

A few things to note:

  1. Do not include spaces in names (i.e. LAS to GTIFF should instead be something like LAS_to_GTIFF).

  2. If using backward slashes, make sure to escape them using double slash ("E:\las\\PNOA_2016.las") or use the raw string (`r"E:\las\PNOA_2016.las").

    Or you could use single forward slashes ("E:/las/PNOA_2016.las")

  3. If you want to define the parameters inside the script (i.e.input, type etc), you need to put these into a dictionary. You can also check how to set the parameters because not all accept string. E.g. the method parameter requires you to select from a list of available options. You can see these options if you use:

     processing.alghelp("grass7:r.in.lidar")
    

Can't test this but perhaps try something like:

processing.runalg("grass7:r.in.lidar",
                 {"input":"E:/las/PNOA_2016_CAT_huso31_346-4560.las",
                  "method":5,
                  "type":1,
                  "resolution":5,
                  "GRASS_REGION_PARAMETER":"342511.450382,351488.549618,4557950.0,4560050.0",
                  "output":"path/to/output"})
6
  • Thank you for these tips. I tried something similar as you have provided. Unfortunately it says: Missing parameter value for parameter GRASS_REGION_PARAMETER. i tried to include this also as the canvas extent but still get an error File "<input>", line 6. The extent i took from the use canvas extent option from r.in.lidar tool. "GRASS_REGION_PARAMETER":343778.474114,350221.525886,4557950.0,4560050.0 - does the coords have to be in quotes?
    – RK4gis
    Commented Apr 18, 2018 at 12:48
  • @RK4gis - Yes, they need to be in quotes. Also, some parameters are required, hence why you might see some missing parameter messages :)
    – Joseph
    Commented Apr 18, 2018 at 12:58
  • @RK4gis, please include all your code attempts in the question (not comments). Edit your question to include them. Post the code as text, not in pictures. This way people can copy and paste the code to test it somewhere else. Also take a look here. Will help you improve your question. Tks. Commented Apr 19, 2018 at 18:47
  • processing.runalg("grass7:r.in.lidar", "E:/las_new/PNOA_2016_CAT_huso31_346-4560.las",5,1,"",1,100,"","",5,"","",False,True,True,"338801.966653,356687.898212,4557499.49324,4565899.49324",0,"E:/las_new/trial.tif")
    – RK4gis
    Commented Apr 20, 2018 at 7:14
  • How do i set a standard region extent? In this case I asked for OTF canvas extent. Saving the coords didnt seem to work. print(canvas_extent) (342511.450382, 351488.549618, 4557950.0, 4560050.0) processing.runalg("grass7:r.in.lidar", "E:/las_new/PNOA_2016_CAT_huso31_346-4560.las",5,1,"",1,100,"","",5,"","",False,True,True,"canvas_extent",0,"E:/las_new/trial.tif") Error: Wrong parameter value: canvas_extent
    – RK4gis
    Commented Apr 20, 2018 at 7:19

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