db_import_las: Import data from one or more LAS files.

Description Usage Arguments Details Value Examples

View source: R/db_functions.R

Description

First, each LAS tile is read from disk and the function checks that it is located in one of the map zones supported by the database (each zone's data is stored in a separate schema). Next, point heights are normalized, any overlap between flight lines is removed, and the counts of vegetation, ground and water points are rasterized as vertical layers defined in CERMBlidar::CERMBstrata. The point count raster layers are then imported into the database along with meta-data for tile extent, point density, etc. Optionally, building points can also be extracted from the LAS tile and imported.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
db_import_las(
  dbsettings,
  las.paths,
  dem.paths = NULL,
  mapnames = NULL,
  default.epsgs = NULL,
  purpose = c("general", "postfire"),
  check.overlap = TRUE,
  buildings = FALSE,
  union.rasters = FALSE,
  union.batch = 1
)

Arguments

dbsettings

A named list of database connection settings as returned by db_connect_postgis.

las.paths

The paths and filenames of the LAS source files. This can be an uncompressed (.las) or compressed .laz or .zip file.

dem.paths

The paths and file names of DEM (digital elevation model) rasters corresponding to the LAS source files. If a vector of paths is provided it must be the same length as las.paths. For each element that specifies the path to a raster file (e.g. GeoTIFF) or zipped raster file, the DEM data will read and used to normalize the point heights for the corresponding LAS file. Where an element is NA or an empty string, point heights for the corresponding LAS file will be normalized using Delaunay triangulation. If this argument is set to NULL (default), triangulation will be used for all LAS files.

mapnames

Specifies the mapsheet names to store for the imported LAS tiles. If NULL (default), mapsheet names are extracted from the leading alphabetic portion of the LAS file names. Alternatively it can be a character vector of either length 1 (same name for all LAS tiles) or length equal to that of las.paths.

default.epsgs

Integer EPSG codes for each of the imported LAS tiles. If NULL (default), EPSG codes will be read from the LAS headers. Sometimes (e.g. class C1 LAS files) no coordinate reference sytem is defined in the LAS header, so it is necessary to set the code manually.

purpose

Either 'general' (default) for general purpose imagery or 'postfire' for specially flown, post-fire imagery. May be abbreviated.

check.overlap

If TRUE (default), images will be checked for overlap between flight lines using the function remove_flightline_overlap in the CERMBlidar package. If an image fails the overlap check (i.e. it appears to have overlap and this cannot be removed) it will be skipped. Setting this argument to FALSE disables overlap checking. This is useful for images with unusual configurations of flight lines that cause a false positive overlap check.

buildings

If TRUE, points classified as buildings (class 6) will be imported into the building_points database table. The default (FALSE) is to not import building points.

union.rasters

See Details for why you probably do not want to use this argument. If TRUE, raster point counts derived from the LAS images will be loaded into both the point_counts table as a single record and the point_counts_union table where data for spatially adjacent, overlapping rasters are merged. If FALSE (default), raster point counts are only loaded into the point_counts table.

union.batch

If union.rasters = TRUE, this defines how many rasters to load before merging data into the point_counts_union table. The default, and minimum allowable, value is 1.

Details

Point counts for vertical layers of vegetation are stored in the database raster table point_counts, with a raster record for each imported LAS tile. Typically there will be a lower density of points in edge cells of a raster than in interior cells due to the relative position of LAS tile boundaries and raster boundaries. This can be resolved by edge-merging adjacent rasters, summing overlapping cells (e.g. using the PostGIS ST_UNION operation with the 'SUM' option). The original intention was to do this by default as part of the import process, and store an edge-merged copy of the raster point counts data in a second database table point_counts_union. However, we found that the time taken by the merging operation became excessive as the number of rasters in the database grew, although we are yet to understand exactly why this is the case. Merging can be enabled by setting the union.rasters argument to TRUE (default is FALSE) but this is not recommended. Note that when exporting point count data with function db_export_stratum_counts, the rasters for adjacent LAS tiles will be edge-merged.

Value

A vector of integer values giving the result for each input LAS file, where 1 means successfully imported; 0 means skipped because previously imported; -1 means not imported due to error (usually a problem with resolving flight line overlap).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## Not run: 
# Establish connection
Sys.setenv(PGPASSWORD = "mypassword")
DB <- db_connect_postgis("cermb_lidar")

# Import a set of LAS files. Point heights will be set relative
# to ground level via Delaunay triangulation.
LAS.FILES <- dir("c:/somewhere/LAS", pattern = "zip$", full.names = TRUE)
imported <- db_import_las(DB, LAS.FILES)
cat(sum(imported == 1), "files were imported\n",
    sum(imported == 0), "files already present were skipped\n",
    sum(imported == -1), "files failed to be imported\n")

# Import a set of LAS files with corresponding DEM (raster elevation)
# files to be used to normalize point heights.
LAS.FILES <- dir("c:/somewhere/LAS", pattern = "zip$", full.names = TRUE)
DEM.FILES <- dir("c:/somewhere/DEM", pattern = "zip$", full.names = TRUE)
imported <- db_import_las(DB, LAS.FILES, DEM.FILES)


## End(Not run)

mbedward/CERMBlidarpostgis documentation built on Nov. 14, 2021, 7:15 p.m.