Title: | Generate Raster Data Lazily from 'GDAL' |
---|---|
Description: | Read raster data at a specified resolution on-demand via 'GDAL' (the Geospatial Data Abstraction Library <https://gdal.org/>). Augments the 'raster' package by never reading data from a raster source until necessary for generating an in-memory 'raster' object. A 'lazyraster' object may be cropped and converted to 'raster' object, and by default will only read a small amount of data sufficient for an overall summary. The amount of data read can be controlled by specifying the output dimensions. |
Authors: | Michael Sumner [aut, cre] |
Maintainer: | Michael Sumner <[email protected]> |
License: | GPL-3 |
Version: | 0.5.0.9010 |
Built: | 2024-10-29 04:17:20 UTC |
Source: | https://github.com/hypertidy/lazyraster |
Create an actual raster::raster object by breaking the lazy contract and demanding pixel values at a given resolution.
as_raster( x, dim = NULL, resample = "NearestNeighbour", native = FALSE, band = 1L )
as_raster( x, dim = NULL, resample = "NearestNeighbour", native = FALSE, band = 1L )
x |
|
dim |
dimensions, pixel size in rows and columns |
resample |
resampling method, see vapour::vapour_read_raster |
native |
return raster at native resolution, default is |
band |
set to 1-based band numbers to return (independently of those set with |
Control the dimensions and method for resampling with the 'dim' and 'resample' arguments.
If dim
is non-integer it is rounded according to what raster does with the
dimensions.
When native = TRUE
the dim
argument is ignored, and no resampling is performed.
a regular raster 'BasicRaster' in-memory object
A lazyraster is a metadata-only shell around a raster file source. Only metadata is read and and used for extent and resolution logic. A lazyraster may be cropped lazily and if plotted or converted to in-memory raster only a reasonable level-of-detail is actually used.
lazyraster(gdalsource, band = NULL, sds = NULL, ...)
lazyraster(gdalsource, band = NULL, sds = NULL, ...)
gdalsource |
a file name or other source string |
band |
which band to use, defaults to all present |
sds |
which subdataset to use, set to 1 if in doubt (see |
... |
ignored for now |
See crop()
for cropping - it works the same but returns a lazyraster,
and as_raster()
for converting to an in-memory raster.
a lazyraster object, a simple shell around a GDAL raster source
If the inferred Y extents appear to be reversed (ymax > ymin) then they are reversed, with a warning. This occurs for any GDAL data source that does not have a geotransform and so is required for use with raster. This might not be the right interpretation, geotransforms are very general and it might mean the data is meant to be oriented that way. (I don't know why GDAL sets a positive Y pixel height as the default, it's a bit of a pain - should the data be flipped, or should Y be interpreted negative - no way to know!).
sstfile <- system.file("extdata/sst.tif", package = "vapour") lazyraster(sstfile) ## convert to raster (in memory, but not all of the source) as_raster(lazyraster(sstfile)) ## crop and stay as lazyraster crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45)) ## crop and convert to raster as_raster(crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45)))
sstfile <- system.file("extdata/sst.tif", package = "vapour") lazyraster(sstfile) ## convert to raster (in memory, but not all of the source) as_raster(lazyraster(sstfile)) ## crop and stay as lazyraster crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45)) ## crop and convert to raster as_raster(crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45)))
Print and format for lazyraster.
Plot for lazyraster, data pulled on-demand at a reasonable level-of-detail.
## S3 method for class 'lazyraster' print(x, ...) ## S3 method for class 'lazyraster' format(x, ...) ## S3 method for class 'lazyraster' plot(x, y, ...)
## S3 method for class 'lazyraster' print(x, ...) ## S3 method for class 'lazyraster' format(x, ...) ## S3 method for class 'lazyraster' plot(x, y, ...)
x |
|
... |
passed to raster::plot |
y |
ignored |
Data is pulled from the GDAL source at a resolution suited for the currently open graphics device.
fl <- system.file("images/ga_srtm.png", package = "lazyraster") print(lazyraster(fl)) ## won't work with dumb images with gdalwarp, need rethink #plot(lazyraster(fl))
fl <- system.file("images/ga_srtm.png", package = "lazyraster") print(lazyraster(fl)) ## won't work with dumb images with gdalwarp, need rethink #plot(lazyraster(fl))
These methods are generics from the raster package, extended to work for lazyrasters.
## S4 method for signature 'lazyraster' crop(x, y, ...)
## S4 method for signature 'lazyraster' crop(x, y, ...)
x |
various (raster, extent) |
y |
an object with extent (for crop) |
... |
arguments passed to underlying raster function |
For crop()
this set an active window of data using the same crop()
function as the raster package. This is the data window that will be pulled
by conversion to an actual raster by as_raster()
.
lazyraster()
and crop()
return a lazyraster object, extent()
returns
a regular raster extent
raster::raster()
, raster::extent()
, raster::crop()
sstfile <- system.file("extdata/sst.tif", package = "vapour") lr <- lazyraster(sstfile) ## crop and stay as lazyraster crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45))
sstfile <- system.file("extdata/sst.tif", package = "vapour") lr <- lazyraster(sstfile) ## crop and stay as lazyraster crop(lazyraster(sstfile), raster::extent(142, 143, -50, -45))
Create an extent in Mercator projection from a longitude, latitude, and a width,height.
merc(x = 146.7, y = -42, wh = 256000)
merc(x = 146.7, y = -42, wh = 256000)
x |
longitude |
y |
latitude |
wh |
width and height, in metres - if only one vaue provided it is also used for height |
four values, xmin, xmax, ymin, ymax in global Mercator
merc() ## a parochial default library(lazyraster) vearth <- '<GDAL_WMS> <Service name="VirtualEarth"> <ServerUrl>http://a${server_num}.ortho.tiles.virtualearth.net/tiles/a${quadkey}.jpeg?g=90</ServerUrl></Service> <MaxConnections>4</MaxConnections> <Cache/> </GDAL_WMS>' lr <- lazyraster(vearth) ## Not run: \donttest{ raster::plotRGB(as_raster(crop(lr, merc(-90, 52, 256e4)), band = 1:3)) } ## End(Not run)
merc() ## a parochial default library(lazyraster) vearth <- '<GDAL_WMS> <Service name="VirtualEarth"> <ServerUrl>http://a${server_num}.ortho.tiles.virtualearth.net/tiles/a${quadkey}.jpeg?g=90</ServerUrl></Service> <MaxConnections>4</MaxConnections> <Cache/> </GDAL_WMS>' lr <- lazyraster(vearth) ## Not run: \donttest{ raster::plotRGB(as_raster(crop(lr, merc(-90, 52, 256e4)), band = 1:3)) } ## End(Not run)
Provides a re-exported generic quadmesh and a method for lazyraster.
## S3 method for class 'lazyraster' quadmesh(x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL)
## S3 method for class 'lazyraster' quadmesh(x, z = x, na.rm = FALSE, ..., texture = NULL, texture_filename = NULL)
x |
raster object for mesh structure |
z |
raster object for height values |
na.rm |
remove quads where missing values? |
... |
arguments passed to as_raster, for both |
texture |
optional input RGB raster, 3-layers |
texture_filename |
optional input file path for PNG texture |
A quadmesh is a 'rgl::mesh3d' extension, and can be plotted in 3D with 'rgl::shade3d'.
a quadmesh, derived from 'rgl::mesh3d'