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

From: Bastien Ferland-Raymond <bastien.ferland-raymond.1_at_ulaval.ca>
Date: Tue, 29 Jun 2010 13:36:39 -0400

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.


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 29 Jun 2010 - 17:38:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jun 2010 - 17:40:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive