extractRaster: Extract pixel values from MAP rasters using point...

Description Usage Arguments Value See Also Examples

View source: R/extractRaster.R

Description

extractRaster extracts pixel values from MAP rasters at user-specified point locations (without downloading the entire raster).

Usage

1
2
3
4
5
6
extractRaster(
  df = NULL,
  csv_path = NULL,
  surface = "PfPR2-10",
  year = rep(NA, length(surface))
)

Arguments

df

data.frame containing coordinates of input point locations, must contain columns named 'latitude'/'lat'/'x' AND 'longitude'/'long'/'y')

csv_path

(optional) user-specified path to which extractRaster coordinates and results are stored. If not specified, tempdir() is used instead.

surface

string containing 'title' of desired raster(s), e.g. c("raster1", "raster2"). Defaults to "PfPR2-10" - the most recent global raster of PfPR 2-10. Check listRaster to find titles of available rasters.

year

default = rep(NA, length(surface)); for time-varying rasters: if downloading a single surface for one or more years, year should be a vector specifying the desired year(s). if downloading more than one surface, use a list the same length as surface, providing the desired year-range for each time-varying surface in surface or NA for static rasters.

Value

getPR returns the input dataframe (df), with the following columns apprended, providing raster values for each surface, location and year.

  1. layer raster code corresponding to extracted raster values for a given row, check listRaster for raster metadata.

  2. year the year for which raster values were extraced (time-varying rasters only; static rasters do not have this column).

  3. value the raster value for the pixel in which a given point location falls.

See Also

autoplot method for quick mapping of PR point locations (autoplot.pr.points).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#Download PfPR data for Nigeria and Cameroon and map the locations of these points using autoplot

# Get some data and remove rows with NAs in location or examined or positive columns.
NGA_CMR_PR <- getPR(country = c("Nigeria", "Cameroon"), species = "Pf")
complete <- complete.cases(NGA_CMR_PR[, c(4, 5, 16, 17)])
NGA_CMR_PR <- NGA_CMR_PR[complete, ]

# Extract PfPR data at those locations.
data <- extractRaster(NGA_CMR_PR[, c('latitude', 'longitude')],
                      surface = 'Plasmodium falciparum PR2-10',
                      year = 2015)

# Data are returned in the same order.
all(data$longitude == NGA_CMR_PR$longitude)

# Some rasters are stored with NA encoded as -9999
data$value[data$value == -9999] <- NA

# We can quickly plot a summary
plot((NGA_CMR_PR$positive / NGA_CMR_PR$examined) ~ data$value)

malariaAtlas documentation built on July 8, 2020, 5:46 p.m.