Learn R Programming

Rnightlights (version 0.1.2)

fnAggRadRast: Calculate statistics on a nightlight raster that fall within a polygon

Description

Calculate stats on the radiance of the pixels in a nightlight raster that fall within a polygon and its subpolygons using the raster package. Given a country polygon with subpolygons representing lower admin levels, it will crop and mask the raster to each subpolygon and calculate the total radiance for the polygon and return a vector of total radiances that matches the subpolygons

Usage

fnAggRadRast(ctryPoly, ctryRastCropped, stats, nlType)

Arguments

ctryPoly

The polygon of the admin level/region of interest. In general is a country polygon with sub-regions usually the lowest known admin level as given by the GADM polygons.

ctryRastCropped

The raster containing nightlight radiances to sum. Usually will have already be cropped to the country outline

stats

The statistics to calculate

nlType

Character vector The nlType to process

Value

Integer Sum of radiances of all pixels in a raster that fall within a polygon region

Examples

Run this code
# NOT RUN {
#read the Kenya polygon downloaded from GADM and load the lowest admin level (ward)
# }
# NOT RUN {
ctryPoly <- readOGR(getPolyFnamePath("KEN"), getCtryShpLowestLyrName("KEN"))
    
# the VIIRS nightlight raster cropped earlier to the country outline
ctryRastCropped <- getCtryRasterOutputFname("KEN","VIIRS","201401")

#calculate the sum of radiances for the wards in Kenya
sumAvgRadRast <- fnAggRadRast(ctryPoly, ctryRastCropped)
# }

Run the code above in your browser using DataLab