You are on page 1of 1

library(raster)

library(rgdal)
library(sp)

#selecionar os shapes
buffer <- "D:\\Estagio\\Shapes\\REC_Uso_do_solo\\buffer_certo.shp"
sp_buffer <- shapefile(buffer)

solo <- "D:\\Estagio\\Shapes\\REC_Uso_do_solo\\REC_Uso_do_Solo.shp"


sp_solo <- shapefile (solo)

municipio <- "D:\\Estagio\\Shapes\\REC_Contornos_mun\\REC_Contornos_mun_proj.shp"


sp_municipio <- shapefile(municipio)
sp_municipio <- spTransform(sp_municipio, crs(sp_buffer))

$fazer o clip
clip1 <- raster::intersect(sp_buffer,sp_solo)
clip2 <- raster::intersect(clip1, sp_municipio)
clip3 <- raster::intersect(clip2, sp_mini_bacias)

#pegar as colunas de interesse


takes <- c("NOME.2", "GEOCODIGO", "GIDCODE")
spdf <- clip3[,names(clip3) %in% takes]

#retirar somente agropecuaria


drops <- c("Agropecuária")
spdf_2 <- spdf[spdf@data$Classe_Fim %in% drops,]

#escrever o shape
writeOGR(spdf_2, getwd(), "buffer_agri", driver = "ESRI Shapefile")

You might also like