Learn R Programming

Rnightlights (version 0.1.2)

masqVIIRS: extract data from a raster using one polygon in a multipolygon

Description

extract data from a raster using one polygon in a multipolygon. Modified from https://commercedataservice.github.io/tutorial_viirs_part1/

Usage

masqVIIRS(ctryPoly, ctryRast, idx)

Arguments

ctryPoly

the country Polygon layer as SpatialPolygon

ctryRast

the clipped country raster

idx

the index of the polygon in the country polygon layer (shp)

Value

numeric vector of radiances

Examples

Run this code
# NOT RUN {
ctryPoly <- rgdal::readOGR('path/to/polygon.shp')

ctryRaster <- raster::raster('path/to/raster.tif')

#get the sum of nightlight pixels in the first polygon in a multipolygon
sumPolygon1 <- sum(masqVIIRS(ctryPoly, ctryRaster, 1), na.rm=T)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab