[R] extracting coordinates from SpatialPolygonsDataFrame using slot functions
Paul Hiemstra
p.hiemstra at geo.uu.nl
Thu May 6 11:40:30 CEST 2010
Jeff Hamann wrote:
> In converting some older code:
>
> ## builds an OWIN to generate a set of points on a grid within the OWIN object:
> bdry <- read.shape( "../../data/boundary.shp" )
> outline.verts <- bdry$Shapes[[2]]$verts[1:bdry$Shapes[[2]]$Pstart[2],]
> outline.order <- nrow( outline.verts ) : 2
> bdry.poly <- vector( 2, mode="list" )
> bdry.poly[[1]] <- list( x=outline.verts[outline.order,1],
> y=outline.verts[outline.order,2] )
> bdry.poly[[2]] <- list( x=bdry$Shapes[[1]]$verts[1:(nrow(bdry$Shapes[[1]]$verts)-1),1],
> y=bdry$Shapes[[1]]$verts[1:(nrow(bdry$Shapes[[1]]$verts)-1),2] )
> bdry.owin <- owin( poly=bdry.poly )
> grid <- gridcentres( bdry.owin, 200, 200 )
>
> I've run across the following problem where I now need to use the readShapePoly function in the sp package:
>
> bdry2 <- readShapePoly( "../../data/boundary.shp" )
>
> which requires the elements be accessed using the slot function?
>
> My question, after trying to find the answer on-line and in some docs, is how?
>
> Help?
>
> Also, I'm not sure I get the r-help digests, so if someone can shed light on the subject, can you please respond directly?
>
> ______________________________________________
> 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.
>
Hi,
A good way to get coordinates of a SPDF is to use the fortify function
from ggplot2. It is mainly used to be able to plot the polygons in
ggplot, but it also serves to get the coodinates into a data.frame very
nicely. See:
http://www.mail-archive.com/r-sig-geo@stat.math.ethz.ch/msg07522.html
For more details.
cheers,
Paul
ps The r-sig-geo list migh get you more response than R-help.
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 274 3113 Mon-Tue
Phone: +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
More information about the R-help
mailing list