[R-sig-Geo] extract value of raster attribute with polygon
Bacou, Melanie
mel at mbacou.com
Tue Jul 12 03:38:10 CEST 2016
Simply refer to the documentation for `raster::extract(..., factors=TRUE)`.
http://www.inside-r.org/packages/cran/raster/docs/extract
--Mel.
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