Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

projection

Get or set the projection of a LAS* object


Description

Get or set the projection of a LAS* object.

Usage

epsg(object, ...)

epsg(object) <- value

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

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

## S4 method for signature 'LAS'
epsg(object)

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

wkt(object) <- value

## S4 method for signature 'LASheader'
wkt(obj)

## S4 replacement method for signature 'LASheader'
wkt(object) <- value

## S4 method for signature 'LAS'
wkt(obj)

## S4 replacement method for signature 'LAS'
wkt(object) <- value

## S4 method for signature 'LASheader'
projection(x, asText = TRUE)

## S4 method for signature 'LAS'
projection(x, asText = TRUE)

## S4 replacement method for signature 'LAS'
projection(x) <- value

## S4 method for signature 'LAScatalog'
projection(x, asText = TRUE)

## S4 method for signature 'LASheader'
crs(x, asText = FALSE)

## S4 method for signature 'LAS'
crs(x, asText = FALSE)

## S4 replacement method for signature 'LAS'
crs(x, ...) <- value

## S4 method for signature 'LAScatalog'
crs(x, asText = FALSE)

Arguments

object, x, obj

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

...

Unused.

value

A CRS object or a proj4string string or WKT string or an EPSG code.

asText

logical. If TRUE, the projection is returned as text. Otherwise a CRS object is returned.

Details

There are two ways to store the CRS of a point cloud in a LAS file:

  • Store an EPSG code (for LAS 1.0 to 1.3)

  • Store a WTK string (for LAS 1.4)

On the other hand, R sptial packages use a proj4string to store the CRS (but the ecosystem is moving to WKT). This is why the CRS is duplicated in a LAS object. The information belongs within the header in a format that can be written in a LAS file and in the slot proj4string in a format that can be understood by R packages.

  • projection<-: assigns a CRS from a CRS (sp), a crs (sf), a WKT string, a proj4string or an epsg code. It updates the header of the LAS object either with the EPSG code for LAS formats < 1.4 or with a WKT string for LAS format 1.4 and updates the proj4string slot.

  • projection: returns the CRS in sp format

  • crs and crs<- are equivalent to projection and projection<-

  • epsg<-, wkt<- : legacy functions superseded by projection<-

  • sf::st_crs return the CRS in sf format.

  • epsg: reads the epsg code from the header.

  • wkt: reads the WKT string from the header.

Examples

LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)

# Get the EPSG code stored in the header (returns 0 if not recorded)
epsg(las)

# Get the WKT string stored in the header (LAS >= 1.4)
wkt(las)

if (rgdal::new_proj_and_gdal())
{
   # Get the WKT of the CRS
   sp::wkt(crs(las))

   # Recorded CRS is "NAD83 / UTM zone 17N"
   sf::st_crs(las)$input
}

# Overwrite the CRS (but does not reproject)
crs <- sp::CRS("+init=epsg:26918")
projection(las) <- crs
sf::st_crs(las)$input

# Uses the EPSG code
projection(las) <- 26919
sf::st_crs(las)$input

# Uses a crs from sf
crs <- sf::st_crs(3035)
projection(las) <- crs

lidR

Airborne LiDAR Data Manipulation and Visualization for Forestry Applications

v3.1.2
GPL-3
Authors
Jean-Romain Roussel [aut, cre, cph], David Auty [aut, ctb] (Reviews the documentation), Florian De Boissieu [ctb] (Fixed bugs and improved catalog features), Andrew Sánchez Meador [ctb] (Implemented wing2015() for segment_snags()), Bourdon Jean-François [ctb] (Contributed to Roussel2020() for track_sensor()), Gatziolis Demetrios [ctb] (Implemented Gatziolis2019() for track_sensor())
Initial release
2021-03-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.