[R-sig-Geo] extract value of raster attribute with polygon

Bacou, Melanie mel at mbacou.com
Tue Jul 12 04:07:13 CEST 2016


Also when summarizing classified rasters, it is usual to use the `mode` 
function (instead of `sum`) since you're typically interested in the 
dominant class.


On 7/11/2016 5:48 PM, Fernando Gimeno wrote:
> i have a raster with attribute table and i need extract values with a
> polygon. Help me please.
>
> COMUNAS<-shapefile("COMUNAS.shp")
> RAST<-raster("raster_23052016/for_GDB/comb_viii.tif")
>
> COMUNAS<-spTransform(COMUNAS,CRS("+proj=utm +zone=18 +south +ellps=WGS84
> +datum=WGS84 +units=m +no_defs"))
>
> dbf<-read.dbf("raster_23052016/for_GDB/comb_viii.tif.vat.dbf")
>
> r <- ratify(RAST)
> rat <- levels(r)[[1]]
> rat<-c(rat,dbf)
> rat<-as.data.frame(rat)
> levels(r) <- rat
>
> COMUNAS$BAL_CO2_CO <- extract(r, COMUNAS, fun = sum, na.rm = TRUE)
>



More information about the R-sig-Geo mailing list