Learn R Programming

Rnightlights (version 0.1.5)

fnAggRadGdal: Calculate zonal statistics using GDAL. Faster than fnAggRadRast for large polygons.

Description

Calculate zonal statistics. Alternative to fnAggRadRast using GDAL. Faster for large polygons. Modified from http://www.guru-gis.net/efficient-zonal-statistics-using-r-and-gdal/

Usage

fnAggRadGdal(ctryCode, ctryPoly, nlType, nlPeriod,
  nlStats = pkgOptions("nlStats"))

Arguments

ctryCode

character string the ISO3 country code to be processed

ctryPoly

Polygon the loaded country polygon layer

nlType

the nlType of interest

nlPeriod

character string the nlPeriod to be processed

nlStats

character vector The stats to calculate

Value

data.frame of polygon attributes and the calculated stats, one column per stat

Examples

Run this code
# NOT RUN {
#read the Kenya polygon downloaded from GADM and load the lowest admin level (ward)
# }
# NOT RUN {
ctryPoly <- rgdal::readOGR(Rnightlights:::getPolyFnamePath(ctryCode="KEN"), 
    Rnightlights:::getCtryShpLowestLyrName(ctryCode="KEN"))
    
#calculate the sum of radiances for the wards in Kenya
sumAvgRadRast <- Rnightlights:::fnAggRadGdal(ctryCode="KEN", ctryPoly=ctryPoly,
    nlType="VIIRS", nlPeriod="201401", nlStats=c("sum","mean"))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab