1

I have a LAS pointcloud file, I'm trying to get the projection. I've tried accessing the header and I've browsed through the las object after using laspy to import it.

    file = os.path.normpath(file)
    las = laspy.read(file)

so with las as the object I can access various attributes using:

pd.DataFrame({'x': las.x, 'y': las.y, 'z': las.z, 'red': las.red, 'green': las.green, 'blue': las.blue})

I can list all the dimensions:

for dimension in las_file.point_format.dimensions:
    print(dimension.name)

X
Y
Z
intensity
return_number
number_of_returns
scan_direction_flag
edge_of_flight_line
classification
synthetic
key_point
withheld
scan_angle_rank
user_data
point_source_id
red
green
blue

So, any idea hoew to get the projection, the CRS, the EPSG code etc.?

5

2 Answers 2

2

This is possible with a little work. There is a section of the las file header for variable length records (VLRs), and one is usually the spatial reference system as a WKT Coordinate specification. This is not guaranteed; on US government files it's usually the second entry in the VLR list but I am not sure that is an actual convention or just luck.

To get what you need, you need to find the entry in the laspy.file.File.header.vlrs list that is of type laspy.vlrs.known.WktCoordinateSystemVlr.

What you are looking for is most likely this:

import laspy
filepath = "myfile.las"

with laspy.open(filepath) as data:
     print(data.header.vlrs)

Now once you know where the entry is, you can print that one with:

print(data.header.vlrs[i].string)

where i is of course the index you want. You could of course iterate over the data.header.vlrs list and check it it's the right type to make sure you get it if you want to automate the process.

0

Not guaranteed to work, but if they were entered to the right location, you can use the built-in laspy method .parse_crs().

from pyproj import CRS
import laspy

las = laspy.read("original.las")
epsg = las.header.parse_crs().to_epsg()
print(epsg)

In my experience, the CRS is often absent in the header, but available in the file name or some supporting file. If you know the CRS and want to add it to the header for later reading:

from pyproj import CRS
import laspy

# add crs
las = laspy.read("original.las")
crs_pyproj = CRS.from_string("epsg:4326")
las.header.add_crs(crs_pyproj)
las.write("las_with_crs_added.las")  # save file with crs added to header

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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