Description Usage Arguments Value Examples
View source: R/extractNightLights.R
Extract NOAA night lights data for regions in a SpatialPolygons or SpatialPolygonsDataFrame. For years with two different satellite readings, it first takes the average between the two years.
1 | extractNightLights(directory = ".", shp, stats = c("sum"), years = NULL)
|
directory |
The directory the night lights data is stored in. The files
must be extracted to TIFF format and the filenames must not have been
changed. Other TIFF files in the same directory will probably cause
problems. The default value for |
shp |
The |
stats |
A vector of functions to apply to the data within each region, for
example |
years |
If provided, will only extract night lights data for those years. By default it will extract all years in the directory. |
Returns a data.frame
with shp@data
combined with the extracted
night lights data for each year provided.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | q <- readline(prompt="Download shapefile and night lights data for example (about 500MB)? (Y/n)")
if (q != "Y") {
stop("Aborted.")
}
# Get an example shapefile to work with:
download.file("ftp://ftp2.census.gov/geo/tiger/TIGER2015/COUSUB/tl_2015_25_cousub.zip",
destfile = "tl_2015_25_cousub.zip")
unzip("tl_2015_25_cousub.zip")
shp <- rgdal::readOGR(".", "tl_2015_25_cousub")
# Download and extract some night lights data to a directory "night-lights":
downloadNightLights(years = 1999:2000, directory = "night-lights")
# By default, the function gets the sum of night lights within the regions:
nl.sums <- extractNightLights(directory = "night-lights", shp)
# You can specificy other statistics to get, e.g. the mean & standard deviation:
nl.mean.sd <- extractNightLights(directory = "night-lights", shp,
stats = c("mean", "sd"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.