vector_to_overlay: Turn spatial vector data into an image overlay

Description Usage Arguments Value See Also Examples

View source: R/vector_to_overlay.R

Description

This function allows users to quickly transform any vector data into an image overlay, which may then be imported as a texture into Unity.

Usage

1
2
3
4
5
6
7
8
vector_to_overlay(
  vector_data,
  reference_raster,
  output_file = NULL,
  target_crs = 4326,
  transparent = "#ffffff",
  ...
)

Arguments

vector_data

The spatial vector data set to be transformed into an overlay image. Users may provide either an sf object or a length 1 character vector containing a path to a file readable by sf::read_sf.

reference_raster

The raster file to produce an overlay for. The output overlay will have the same extent and resolution as the input raster. Users may provide either a Raster* object or a length 1 character vector containing a path to a file readable by raster::raster.

output_file

The path to save the image overlay to. If NULL, saves to a tempfile.

target_crs

The CRS (as an EPSG integer code) to transform vector data into. If using raster images from get_tiles, the default of 4326 is typically appropriate.

transparent

The hex code for a color to be made transparent in the final image. Set to FALSE to not set any colors to transparent.

...

Arguments passed to ... in either ggplot2::geom_point (for point vector data), ggplot2::geom_line (for line data), or ggplot2::geom_polygon (for all other data types).

Value

output_file, invisibly.

See Also

Other data manipulation functions: combine_overlays(), georeference_overlay(), merge_rasters(), raster_to_raw_tiles()

Other overlay creation functions: combine_overlays(), georeference_overlay()

Other visualization functions: combine_overlays(), geom_spatial_rgb(), raster_to_raw_tiles()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 

# Generate points to download raster tiles for
set.seed(123)
simulated_data <- data.frame(
  id = seq(1, 100, 1),
  lat = runif(100, 44.1114, 44.1123),
  lng = runif(100, -73.92273, -73.92147)
)

# Create an sf object from our original simulated data

simulated_data_sf <- sf::st_as_sf(simulated_data, coords = c("lng", "lat"))
sf::st_crs(simulated_data_sf) <- sf::st_crs(4326)

# Download data!

downloaded_tiles <- get_tiles(simulated_data_sf, tempfile())

merged_file <- merge_rasters(
  downloaded_tiles[[1]],
  tempfile(fileext = ".tif")
)


# Create an overlay image
vector_to_overlay(simulated_data_sf, merged_file[[1]], na.rm = TRUE)

## End(Not run)

terrainr documentation built on Feb. 23, 2021, 9:06 a.m.