Learn R Programming

Rnightlights (version 0.2.3)

fnAggRadGdal: Calculate zonal statistics using GDAL

Description

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

Usage

fnAggRadGdal(ctryCode, admLevel, ctryPoly, nlType, nlPeriod,
  nlStats = pkgOptions("nlStats"), gadmVersion = pkgOptions("gadmVersion"),
  custPolyPath = NULL)

Arguments

ctryCode

character string the ISO3 country code to be processed

admLevel

character string The admin level to process. Should match the ctryPoly given but no checks are made currently.

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

gadmVersion

The GADM version to use

custPolyPath

Alternative to GADM. A path to a custom shapefile zip

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 <- readCtryPolyAdmLayer(ctryCode="KEN", 
    Rnightlights:::getCtryShpLowestLyrNames(ctryCodes="KEN"))
    
#calculate the sum of radiances for the wards in Kenya
sumAvgRadRast <- Rnightlights:::fnAggRadGdal(ctryCode="KEN", ctryPoly=ctryPoly,
    nlType="VIIRS.M", nlPeriod="201401", nlStats=c("sum","mean"))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab