[R-sig-Geo] Delimit a polygon for the region which is> 1000 m from my raster altitude

sadaoui sadaouimahrez at outlook.com
Fri May 1 15:02:16 CEST 2015


Thank you very much "MacQueen, Don"  for your answer.

I have followed your instructions from this script :

library(raster)
library(sp)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)

# add contour

x <- rasterToContour(r,levels=500)
class(x)
plot(r)
plot(x, add=TRUE)

#export contour to shapefile

library(rgdal)

writeOGR(x, ".", "contour", driver="ESRI Shapefile")


but when I open the shapefile, is a  lines not a polygons? My goal is to
have the polygon areas for altitude> 500m.

I thought to "rasterToPolygons"

library(raster)
library(sp)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)

# add polygon

library(rgeos)

pol <- rasterToPolygons(r, fun=function(x){x>500})

plot(pol, add=T, col='red')

#export polygon to shapefile

library(rgdal)

writeOGR(pol, ".", "polygon", driver="ESRI Shapefile")



but the result, it displays a shapefile with polygons for each pixel

I just want  a polygons to areas where are> 500m, not for each pixel.

Thank you again 







--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Delimit-a-polygon-for-the-region-which-is-1000-m-from-my-raster-altitude-tp7588147p7588149.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list