prepareTargetData: USGS Lidar Toolkit - Prepare Target Data

View source: R/UtilityFunctions.R

prepareTargetDataR Documentation

USGS Lidar Toolkit – Prepare Target Data

Description

Prepare features for use when querying a lidar project or tile index to determine available data coverage. The basic operation done by this function is to apply the buffer to the features.

Usage

prepareTargetData(
  x = NULL,
  y = NULL,
  buffer = 0,
  shape = "square",
  aoi = NULL,
  crs = "",
  segments = 60,
  returnType = "sf",
  useLegacyBuffering = FALSE
)

Arguments

x

Location or list of locations containing the easting for the center of the area-of-interest.

y

Location or list of locations containing the northing for the center of the area-of-interest.

buffer

Distance or list of distances added or subtracted to (x,y) to create the area-of-interest. Can be 0 when used with (x,y) to return projects providing coverage for point location(s). Can be a vector of values corresponding to the number of objects in aoi allowing a different buffer size for each object when aoi is a Spatial* or sf object. buffer can be negative with polygon features to reduce the area considered. However, you may end up with weird shapes if the distance is larger than the width of the polygon.

shape

Character string describing the shape of the sample area. Valid values are "square" or "circle". The buffer shape is the same for all objects specified by (x,y) or aoi. For polygon features, shape affects the way vertices are buffered. In most cases, use shape = "eound" for the best result.

aoi

Spatial* or sf object containing a point(s) or polygon(s) describing the area(s) of interest. Can be points or polygons.

crs

Valid proj4string string defining the coordinate reference system of (x,y). crs can also be an EPSG code (numeric). crs is required when using (x,y). crs is quietly ignored when using aoi.

segments

Number of segments to use when generating a circular area of interest. When using a SpatialPoint* or sf object with shape = "circle", set segments to a rather large value (60 or higher) that is a multiple of 4. The st_uffer function from sf is used to build the sample areas and it accepts the number of segments in a quarter circle so small values for segments may not produce good circles. Values for segments that are not a multiple of 4 will not produce circles with the correct number of segments.

returnType

Character string specifying the object type for the polygon object returned by prepareTargetData when (x,y) is used to specify the area-of-interest. Valid values are "Spatial" or "sf". returnType is ignored when aoi is specified and the return type will match the object type of aoi.

useLegacyBuffering

Boolean flag indicating that the buffer should be applied to features in their original projection. This was the original behavior of prepareTargetData prior to changes in June 2023.

Details

Prepare point or polygon data for use when querying to determine a lidar project or tile coverage. Typically this function is called by the queryUSGSProjectIndex, queryUSGSTileIndex, or queryMPCTileIndex functions but you can use prepareTargetData to build the query objects so they can be used for other purposes.

Units for buffer are always meters.

In operation, features are first projected to WGS84 LON-LAT. Then the centroid of all features is computed and used to determine the UTM zone. Features are projected to UTM and the buffer is applied. Then the features are projected back to the original projection (or LON-LAT if applicable). As a result, the actual shape of the buffered area when providing point features may not be a perfect circle or square if the original projection does not preserve distances. If this behavior causes problems, you can specify useLegacyBuffering = TRUE to any of the query functions to have the buffer applied using the native projection of the input features.

Value

A set of optionally buffered spatial features. The return type will be the same as the aoi type. When (x,y) is used, returnType specifies the object type returned by prepareTargetData.

Examples

prepareTargetData(-13540901, 5806426, 180, shape = "circle",
  crs = sp::CRS(SRS_string="EPSG:3857")@projargs)
pt1 <- sf::st_point(c(-13540901, 5806426 + 500))
pt2 <- sf::st_point(c(-13540901 + 500, 5806426 - 500))
pt3 <- sf::st_point(c(-13540901 - 500, 5806426))
pt4 <- sf::st_point(c(-13540901 + 1000, 5806426 - 1000))
id <- c("P1", "P2", "P3", "P4")
x_sf <- sf::st_sf(data.frame(ID = id, stringsAsFactors = FALSE),
  geom = sf::st_sfc(pt1, pt2, pt3, pt4),
  crs = sp::CRS(SRS_string="EPSG:3857")@projargs)
samples <- prepareTargetData(aoi = x_sf, buffer = 180)

bmcgaughey1/USGSlidar documentation built on June 23, 2024, 1:25 a.m.