Learn R Programming

lidR (version 2.0.2)

epsg: Get or set epsg code of a LAS* object

Description

Currently, at least in R, the only way to store the CRS in a las file is to store the epsg code of the CRS. On the other hand, all spatial R packages use the proj4string to store the CRS. This is why the CRS is duplicated in a LAS object. The proj4string is accessible with the functions projection from raster or proj4string from sp. These functions do nothing special except they return or update the proj4string, which is not recognized in a las file. The function epsg, in turn, updates the header of the LAS object and updates the proj4string and thus should be preferred to ensure that the CRS will be written into a las file.

Usage

epsg(object, ...)

epsg(object) <- value

# S4 method for LASheader epsg(object, ...)

# S4 method for LASheader epsg(object) <- value

# S4 method for LAS epsg(object)

# S4 method for LAS epsg(object) <- value

Arguments

object

An object of class LAS or eventually LASheader (regular users don't need to manipulate LASheader objects)

...

Unused

value

integer. EPSG code.

Examples

Run this code
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)

projection(las)
epsg(las)

# Changing the CRS via projection updates the proj4string but not the header
# The proj4string will be propagated in all subsequent spatial objects but the las file
# itself will still have the epsg code 26917 if written on the disk
projection(las) = sp::CRS("+init=epsg:2567")
projection(las)
epsg(las)

# Changing the CRS via epsg updates the proj4string and the header. This way the good CRS will
# written in the las file (if written).
epsg(las) = 2567
epsg(las)
projection(las)
# }

Run the code above in your browser using DataLab