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

Fernando Gimeno fe.gimeno at gmail.com
Mon Jul 11 23:48:12 CEST 2016


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)

-- 
*Fernando J. Gimeno Molina*
*Licenciado en Geografía, Universidad de Chile*
*Geógrafo, Universidad de Chile*
*Mc(c) Gestión y Planificación Ambiental, Universidad de Chile*
*Diploma en Geomática Aplicada, Universidad de Chile*

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list