extractNightLights: Extract Night Lights data from regions in a shapefile

Description Usage Arguments Value Examples

View source: R/extractNightLights.R

Description

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.

Usage

1
extractNightLights(directory = ".", shp, stats = c("sum"), years = NULL)

Arguments

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 nl.dir is the current directory.

shp

The SpatialPolygons or SpatialPolygonsDataFrame to extract data from.

stats

A vector of functions to apply to the data within each region, for example c("sum", "mean", "sd"). The default is "sum".

years

If provided, will only extract night lights data for those years. By default it will extract all years in the directory.

Value

Returns a data.frame with [email protected] combined with the extracted night lights data for each year provided.

Examples

 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"))

walshc/nightlights documentation built on May 3, 2019, 11:51 p.m.