Skip to contents

To enable the downloading of rayshader-readable data for a desired extent, it is necessary to set the rayshader-ratrix scene canvas using one of the set_canvas_x() functions. See details for additional info.

Usage

set_canvas(bounds, projection)

set_canvas_world(projection = "+proj=longlat +datum=WGS84")

set_canvas_sf(.sf, mask = F)

set_canvas_raster(.raster, mask = F)

set_canvas_centroid(
  lat,
  long,
  radius = 5000,
  projection = "+proj=longlat +datum=WGS84"
)

get_canvas(res)

canvasExent()

Arguments

bounds

numeric vector of length 4. e.g. c(xmin, xmax, ymin, ymax)

projection

...

.sf

The sf/sfc object used to set the extent and projection of the canvas

mask

Default is F. NOT WORKING YET!

.raster

The raster object used to set the extent and projection of the canvas

lat

...

long

...

radius

...

res

A resolution (i.e pixel dimensions) in the units of the canvas crs (get_canvas()$)

Details

set_canvas() offers the most control over the extent and projection of the raytrix canvas. Use set_canvas_world() for a basic WGS84 extent of the world; this is deliberately simple, for alternative global projections use set_canvas(). set_canvas_sf() sets the canvas from an sf or sfc object; this can be especially useful when you intend to plot sf features as overlays. set_canvas_centroid() allows for the provision of lat long coordinates and a buffer (in meters) around that point to set the extent; this function takes WGS84 coords by default (although this can be changed) but will always convert to Pseudo Mercator for convenience. To retrieve this information use get_canvas() which returns a list including: extent, projection and (if res is provided) dimension. canvasExent() returns a raytrix extent object which is a copy of a raster Extent object. This can be used in combination with rayshader functions such as generate_polygon_overlay() to provide the extent of the topography matrix.

Examples

# set canvas with Universal Polar Stereographic
set_canvas(c(-4e7,  4e7, -4e7,  4e7 ),'+proj=ups')
get_canvas()
#> $extent
#> [1] -4e+07  4e+07 -4e+07  4e+07
#> 
#> $projection
#> [1] "+proj=ups"
#> 
get_canvas(4e4)
#> $extent
#> [1] -4e+07  4e+07 -4e+07  4e+07
#> 
#> $projection
#> [1] "+proj=ups"
#> 
#> $dimension
#>    x    y 
#> 2000 2000 
#> 

# set canvas with tilted perspective...
set_canvas(c(-3.8e6,  3.8e6, -3.8e6,  3.8e6 ),'+proj=tpers +h=5500000 +lat_0=40')
get_canvas(4e4)
#> $extent
#> [1] -3800000  3800000 -3800000  3800000
#> 
#> $projection
#> [1] "+proj=tpers +h=5500000 +lat_0=40"
#> 
#> $dimension
#>   x   y 
#> 190 190 
#> 

# set WGS84 global extent
set_canvas_world()
get_canvas(0.7)
#> $extent
#> [1] -180  180  -90   90
#> 
#> $projection
#> [1] "+proj=longlat +datum=WGS84"
#> 
#> $dimension
#>   x   y 
#> 515 258 
#> 

# set canvas for Mt. St Helens
set_canvas_centroid(46.200732, -122.187082, radius = 7000)
#> Warning: `set_canvas_centroid() `converts coordinates to web mercator for convnience.to set a specific canvas extent and projection use `set_canvas()`
get_canvas(10)
#> $extent
#>      xmin      xmax      ymin      ymax 
#> -13608804 -13594804   5805575   5819575 
#> 
#> $projection
#> [1] "PROJCRS[\"WGS 84 / Pseudo-Mercator\",\n    BASEGEOGCRS[\"WGS 84\",\n        DATUM[\"World Geodetic System 1984\",\n            ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                LENGTHUNIT[\"metre\",1]]],\n        PRIMEM[\"Greenwich\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        ID[\"EPSG\",4326]],\n    CONVERSION[\"Popular Visualisation Pseudo-Mercator\",\n        METHOD[\"Popular Visualisation Pseudo Mercator\",\n            ID[\"EPSG\",1024]],\n        PARAMETER[\"Latitude of natural origin\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8801]],\n        PARAMETER[\"Longitude of natural origin\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8802]],\n        PARAMETER[\"False easting\",0,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8806]],\n        PARAMETER[\"False northing\",0,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8807]]],\n    CS[Cartesian,2],\n        AXIS[\"easting (X)\",east,\n            ORDER[1],\n            LENGTHUNIT[\"metre\",1]],\n        AXIS[\"northing (Y)\",north,\n            ORDER[2],\n            LENGTHUNIT[\"metre\",1]],\n    USAGE[\n        SCOPE[\"unknown\"],\n        AREA[\"World - 85°S to 85°N\"],\n        BBOX[-85.06,-180,85.06,180]],\n    ID[\"EPSG\",3857]]"
#> 
#> $dimension
#>    x    y 
#> 1400 1400 
#> 

# set canvas with sf object.
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
demo(nc, ask = FALSE, echo = FALSE)
#> Reading layer `nc.gpkg' from data source 
#>   `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG'
#> Simple feature collection with 100 features and 14 fields
#> Attribute-geometry relationship: 0 constant, 8 aggregate, 6 identity
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
set_canvas_sf(nc)
#> Warning: Canvas projection is not cartesian.Be careful of the units you use to specify `res`!
get_canvas(7e-3)
#> $extent
#>      xmin      xmax      ymin      ymax 
#> -84.32385 -75.45698  33.88199  36.58965 
#> 
#> $projection
#> [1] "GEOGCRS[\"NAD27\",\n    DATUM[\"North American Datum 1927\",\n        ELLIPSOID[\"Clarke 1866\",6378206.4,294.978698213898,\n            LENGTHUNIT[\"metre\",1]]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433]],\n    CS[ellipsoidal,2],\n        AXIS[\"geodetic latitude (Lat)\",north,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        AXIS[\"geodetic longitude (Lon)\",east,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n    USAGE[\n        SCOPE[\"unknown\"],\n        AREA[\"North America - NAD27\"],\n        BBOX[7.15,167.65,83.17,-47.74]],\n    ID[\"EPSG\",4267]]"
#> 
#> $dimension
#>    x    y 
#> 1267  387 
#> 

canvasExent()
#> An object of class "Extent"
#> Slot "xmin":
#>      xmin 
#> -84.32385 
#> 
#> Slot "xmax":
#>      xmax 
#> -75.45698 
#> 
#> Slot "ymin":
#>     ymin 
#> 33.88199 
#> 
#> Slot "ymax":
#>     ymax 
#> 36.58965 
#>