[R-sig-Geo] create a polygon shape file from a points shape file

Robert J. Hijmans r.hijmans at gmail.com
Thu Feb 11 19:21:52 CET 2010


Gianni,

If you read a points shpfile to get a SpatialPointsDataFrame object
(via maptools or readOGR) then, if your object is called 'x'

pts = coordinates(x)

# this will return something like:
pts <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))

# you need to make sure that the last point and first coincide, so perhaps do
pts = rbind(pts, pts[1,])

# and then something like this
sp = SpatialPolygons( list(  Polygons(list(Polygon(pts)), 1)))

plot(sp)
points(pts, col='red', pch=as.character(0:9), cex=2)

And you can use writeOGR to save 'sp' as a shapefile.
Of course this assumes that the points are in the right order. Also,
you might prefer to read in the points from a text file rather then
going through a shapefile.

Robert

On Wed, Feb 10, 2010 at 6:24 PM, gianni lavaredo
<gianni.lavaredo at gmail.com> wrote:
> dear R users,
>
> there is same possibility to convert a points shape file in a polygon shape
> file? where the corner are the last points
>
> thanks
> gianni
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list