Extract raster data from a Shape in R

Asked

Viewed 461 times

0

How to extract raster data from a Shape? */

printf("%d\n", 42);  /* Como fazer para extrair dados de raster a partir de um shape
  • 1

    Your question is not clear. Please set what type of Shape, raster etc. Put some example of the data you want to do the transformation.

  • I have a tif file and I have a polygono inside the raster.

  • really, can’t understand your question at all, man, try sending a Toy version of your code to agnt give you a help

1 answer

0

Hello, probably what you want is a Mask

library(raster)
#raster exemplo
r<-raster(ncol=10,nrow=10)
r[]<-1:ncell(r)
plot(r)
#poligono exemplo
pol<-raster(ncol=2,nrow=2)
pol[]<-1:ncell(pol)
pol<-as(pol,"SpatialPolygons")[1]
plot(r);plot(pol,add=T)
#crop ou mask para cortar
c1<-crop(r,pol)
m1<-mask(r,pol)
#mask nao altera o extent, o crop sim

#retornar valores do raster cortado
v1<-values(c1) #valores sem NA 
v2<-values(m1) #valores com NA

Browser other questions tagged

You are not signed in. Login or sign up in order to post.