[R-sig-Geo] Delimit a polygon for the region which is>, 1000 m from my raster altitude
Robert J. Hijmans
r.hijmans at gmail.com
Sat May 2 21:35:51 CEST 2015
" it has not recognized as a polygon!!! I don't know why? "
That is not true:
> class(pol3)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"
It is not a 'SpatialPolygonsDataFrame'
You can write it with:
shapefile(pol3, "polygon3.shp")
or use the SpatialPolygons object to create a SpatialPolygonsDataFrame
and then use writeOGR (that is what the shapefile function does for
you).
Robert
On Sat, May 2, 2015 at 12:16 PM, sadaoui <sadaouimahrez at outlook.com> wrote:
> Thank you very much "José M. Blanco Moreno" 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 polygon
>
> library(rgeos)
> pol2 <- rasterToPolygons(r, fun=function(x){x>500}, dissolve = TRUE)
> pol3 <- gBuffer(pol2,width=0, byid=FALSE)
> plot(r)
>
> plot(pol3,add=TRUE,border='blue',lwd=2,col="red",axes=TRUE)
> title("area > 500m")
>
>
> I have had the result as I want a polygon for the area> 500m.
>
> But,
> I found a problem to export this polygon (pol3)
>
> #export polygon to shapefile
>
> library(rgdal)
> writeOGR(pol3, ".", "polygon3", driver="ESRI Shapefile")
>
> Error in writeOGR(pol3, ".", "polygon3", driver = "ESRI Shapefile") :
> obj must be a SpatialPointsDataFrame, SpatialLinesDataFrame or
> SpatialPolygonsDataFrame
>
> it has not recognized as a polygon!!! I don't know why?
>
> thank you for helping me to the last key
>
>
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Re-Delimit-a-polygon-for-the-region-which-is-1000-m-from-my-raster-altitude-tp7588152p7588153.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list