View source: R/extractRaster.R
extractRaster | R Documentation |
extractRaster
extracts pixel values from MAP rasters at user-specified point locations (without downloading the entire raster).
extractRaster(
df,
csv_path = NULL,
surface = NULL,
year = NULL,
dataset_id = NULL
)
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. |
surface |
deprecated argument. Please remove it from your code. |
year |
for time-varying rasters: if downloading a single surface for one or more years, |
dataset_id |
A character string specifying the dataset ID(s) of one or more rasters. These dataset ids can be found in the data.frame returned by listRaster, in the dataset_id column e.g. c('Malaria__202206_Global_Pf_Mortality_Count', 'Malaria__202206_Global_Pf_Parasite_Rate') |
extractRaster
returns the input dataframe (df
), with the following columns appended, providing values for each raster, location and year.
layerName
dataset id corresponding to extracted raster values for a given row, check listRaster
for raster metadata.
year
the year for which raster values were extracted (time-varying rasters only; static rasters do not have this column).
value
the raster value for the pixel in which a given point location falls.
autoplot
method for quick mapping of PR point locations (autoplot.pr.points
).
#Download PfPR data for Nigeria and Cameroon and map the locations of these points using autoplot
## Not run:
# 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(df = NGA_CMR_PR[, c('latitude', 'longitude')],
dataset_id = 'Malaria__202206_Global_Pf_Parasite_Rate',
year=2020)
# 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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.