line2poly: Line-in-polygon analysis

View source: R/line2poly.R

line2polyR Documentation

Line-in-polygon analysis

Description

Function for basic geometry calculations on polyline features, within an overlapping destination polygon layer.

Usage

line2poly(
  linez,
  polyz,
  poly_id,
  measurez = c("length", "density", "distance"),
  outvar_name = "line",
  unitz = "km",
  reproject = TRUE,
  na_val = NA,
  verbose = TRUE
)

Arguments

linez

Source polyline layer. sf object.

polyz

Destination polygon layer. Must have identical CRS to linez. sf object.

poly_id

Name of unique ID column for destination polygon layer. Character string.

measurez

Desired measurements. Could be any of "length" (sum of line lengths by polygon), "density" (sum of line lengths divided by area of polygon) and/or "distance" (distance from each polygon to nearest line feature). Default is to report all three. Character string or vector of character strings.

outvar_name

Name (root) to be given to output variable. Default is "line". Character string.

unitz

Units of measurement (linear). Defaul is "km". Character string.

reproject

Temporarily reproject layers to planar projection for geometric operations? Defaul is TRUE. Logical.

na_val

Value to be assigned to missing values (line lengths and densities only). Defaul is NA. Logical or list.

verbose

Print status messages and progress? Default is TRUE. Logical.

Value

An sf polygon object, with summary statisics of linez features aggregated to the geometries of polyz.

If measurez = "lengths", contains fields with suffixes

  • "_length". Sum of line lengths within each polygon, in km or other units supplied in unitz.

If measurez = "density", contains fields with suffixes

  • "_length". Sum of line lengths within each polygon, in km or other units supplied in unitz.

  • "_area". Area of each polygon, in km^2 or the square of linear units supplied in unitz.

  • "_density". Sum of line lengths divided by area of each polygon, in km/km^2 or other units supplied in unitz.

If measurez = "distance", contains fields with suffixes

  • "_distance". Distance from each polygon to nearest line feature, in km or other units supplied in unitz.

If measurez = c("length","density","distance") (default), contains all of the above.

Examples

# Road lengths, densities and distance from polygon to nearest highway
## Not run: 
data(hex_05_deu)
data(highways_deu1992)
out_1 <- line2poly(linez = highways_deu1992,
                   polyz = hex_05_deu,
                   poly_id = "HEX_ID")
plot(out_1["line_length"])
plot(out_1["line_density"])
plot(out_1["line_distance"])

## End(Not run)

# Replace missing road lengths and densities with 0's, rename variables
## Not run: 
out_2 <- line2poly(linez = highways_deu1992,
                   polyz = hex_05_deu,
                   poly_id = "HEX_ID",
                   outvar_name = "road",
                   na_val = 0)
plot(out_2["road_length"])
plot(out_2["road_density"])
plot(out_2["road_distance"])

## End(Not run)

zhukovyuri/SUNGEO documentation built on Nov. 5, 2023, 1:07 p.m.