[R] how to create a shape file from a polygone

Bastien Ferland-Raymond bastien.ferland-raymond.1 at ulaval.ca
Tue Jun 29 19:36:39 CEST 2010


Dear R-users,

I have created a map with plot location using longitude/latitude coordinates
with the PlotOnStaticMap() function of the RgoogleMaps package.  Everything
works fine until I try to put a polygon on the map.  The polygon() function
doesn’t work and I need to use the special function PlotPolysOnStaticMap()
however this requires a shapefile (which I'm not sure what it is) and not XY
coordinates.

So my question is quite simple:  How do I transform XY (lon/lat) coordinates
into a shape file.

My polygon:
x.pol.mat<-c(-66.67,-66.46,-66.54,-66.82,-67.06,-66.97)
y.pol.mat<-c(48.87,48.89,48.745,48.62,48.55,48.75)
pol.mat<-matrix(c(x.pol.mat,y.pol.mat),6,2)
polygon(pol.mat)

The writePolyShape() function from the maptools package seems to be what I'm
looking for but I can't figure how to create the SpatialPolygonsDataFrame
object that is required.

I'm using WinXP pro 32bit and R 2.11.0

Thanks for your help, 

Bastien Ferland-Raymond, 
M.Sc. candidate
Université Laval
Québec, Canada
 
 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5235 (20100628) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 



More information about the R-help mailing list