Learn R Programming

Rnightlights (version 0.2.4)

masqOLS: Extract raster pixel values within the boundaries of a polygon

Description

Extract raster pixel values within the boundaries of a polygon

Usage

masqOLS(shp, rast, i, retVal = "colrowval", configName)

Arguments

shp

the country Polygon layer as SpatialPolygon

rast

the clipped country raster

i

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

retVal

Whether to return the raster data as a vector, or data.frame with spatial context NULL returns a vector of all values, colrowval returns a data.frame with row, col and raster value while lonlatval returns a data.frame with lon,lat and val.

configName

character the type of raster being processed

Value

numeric vector of radiances

Examples

Run this code
# NOT RUN {
ctryPoly <- rgdal::readOGR(getPolyFnamePath("KEN"), getCtryShpLyrNames("KEN", 1))
ctryRaster <- raster::raster(getCtryRasterOutputFnamePath("KEN", "OLS", "1999"))
temp <- NULL
KenAdm1Sum <- NULL
for (i in 1:length(ctryPoly@polygons))
{
 temp$name <- as.character(ctryPoly@data$NAME_1[i])
 temp$sum <- sum(masqOLS(ctryPoly, ctryRaster, i), na.rm=T)

 KenAdm1Sum <- rbind(KenAdm1Sum)
}
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab