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

"José M. Blanco Moreno" jmblanco at ub.edu
Sat May 2 13:37:09 CEST 2015


You can try fiddling a bit with:

pol2 <- rasterToPolygons(r, fun=function(x){x>6}, dissolve = TRUE)

pol3 <- gBuffer(pol2,width=1e-5, byid=FALSE)

Where the width is sufficiently small as to not affect the general shape. However, it yields very jagged polygons, which I do not know if it is what you intend.

Best wishes,

José M. Blanco

El 02/05/2015 a las 12:00, r-sig-geo-request at r-project.org<mailto:r-sig-geo-request at r-project.org> escribió:

Subject: Re: [R-sig-Geo] Delimit a polygon for the region which is>
        1000 m from my raster altitude
Message-ID: <1430485336885-7588149.post at n2.nabble.com><mailto:1430485336885-7588149.post at n2.nabble.com>
Content-Type: text/plain; charset=us-ascii

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






--
---------------------------------------
José M. Blanco-Moreno
Dept. de Biologia Vegetal (Botànica)
Facultat de Biologia
Universitat de Barcelona
Av. Diagonal 643
08028 Barcelona
SPAIN
---------------------------------------
phone: (+34) 934 039 871
fax: (+34) 934 112 842
---------------------------------------


L'amistat és com una novel·la, són
paraules ben dites. -Montserrat Roig
(Barcelona 1946-1991)



Aquest correu electrònic i els annexos poden contenir informació confidencial o protegida legalment i està adreçat exclusivament a la persona o entitat destinatària. Si no sou el destinatari final o la persona encarregada de rebre’l, no esteu autoritzat a llegir-lo, retenir-lo, modificar-lo, distribuir-lo, copiar-lo ni a revelar-ne el contingut. Si heu rebut aquest correu electrònic per error, us preguem que n’informeu al remitent i que elimineu del sistema el missatge i el material annex que pugui contenir. Gràcies per la vostra col·laboració.

Este correo electrónico y sus anexos pueden contener información confidencial o legalmente protegida y está exclusivamente dirigido a la persona o entidad destinataria. Si usted no es el destinatario final o la persona encargada de recibirlo, no está autorizado a leerlo, retenerlo, modificarlo, distribuirlo, copiarlo ni a revelar su contenido. Si ha recibido este mensaje electrónico por error, le rogamos que informe al remitente y elimine del sistema el mensaje y el material anexo que pueda contener. Gracias por su colaboración.

This email message and any documents attached to it may contain confidential or legally protected material and are intended solely for the use of the individual or organization to whom they are addressed. We remind you that if you are not the intended recipient of this email message or the person responsible for processing it, then you are not authorized to read, save, modify, send, copy or disclose any of its contents. If you have received this email message by mistake, we kindly ask you to inform the sender of this and to eliminate both the message and any attachments it carries from your account. Thank you for your collaboration.

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list