Saturday 24 June 2017

python - Getting the projection of a LAS file using liblas?


I am using the python api of liblas to read/write las files. I would like to get the spatial reference information of the las file using liblas, but have been unable to figure it out.


Can anyone offer some advice on how to go about getting this information?



Answer



To be honest, I think the easiest way would be to shell out to lasinfo with the --xml argument, and then use ElementTree or some such to pluck out what you need from the XML.


You can reach all this stuff from the Python bindings too, but it's a bit of a mess. In short, open the file, fetch the header, and fetch the srs, and then ask for the wkt of the srs. This all assumes you have libLAS + GeoTIFF + GDAL enabled, and degrades poorly if you don't have all three of those things linked together.


Additionally, if all you want to do is interact with LAS files, laspy is a much better alternative to libLAS at this time. laspy doesn't allow you do anything with the coordinate system stuff in LAS other than to fetch the GeoTIFF bytes out of the file, but it is a full-featured library in every other way. It's pure Python + numpy, easy to deploy, and behaves naturally, unlike libLAS (disclaimer, I'm the libLAS author and I helped bootstrap laspy as an effort to obsolete libLAS).


Hope this helps,


Howard


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...