LibLAS to GRASS r.in.xyz

I wrote some python to pipe las2txt to GRASS’s r.in.xyz on using subprocess which is what most of the GRASS python scripts use. Its not very sophisticated at all but seems to work decently well however I suspect Howard’s point about it not being much better than the text file approach is true. Its based on the GRASS LIDAR wiki page(GRASS Wiki): Heres an example:

from liblas import file, header 
import subprocess as sub
import grass.script as grass

def run(cmd, **kwargs):
    grass.run_command(cmd, quiet = True, **kwargs)

path='../data/las/ucd_01.las'
dbname='ucd_01.las'
h=file.File(path).header
run("g.region", e=h.max[0], w=h.min[0], s=h.min[1], n=h.max[1])
pts=sub.Popen('las2txt -i %s --parse xyz --delimiter "|" --keep-classes 2 --stdout'%path, shell=True, stdout=sub.PIPE)
mkInRast=grass.feed_command("r.in.xyz", input="-", output=dbname, method='mean')
mkInRast.stdin.write(pts.communicate()[0])
mkInRast.stdin.close()
mkInRast.wait()

#this stuff is based on the wiki page for interpolating/filtering the resulting GRASS dataset

run("r.to.vect", flags='z', input=dbname, output=dbname+'_pt', feature='point')    
run("v.surf.rst", layer='0', input=dbname+'_pt', elev= dbname+'_rst')
run("g.remove", vect='%s_pt'%dbname)
run("g.remove", rast=dbname)

DEM from LiDAR

DEM from LIDAR


Hillshade from  LiDAR

Hillshade from LiDAR using GRASS and LibLAS from python

This entry was posted in Geospatial, LiDAR and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *