[R-sig-eco] spatial/mapping question
Marcelino de la Cruz
marcelino.delacruz at upm.es
Wed May 29 20:28:14 CEST 2013
Hi Matt
You can play with spatstat.
You only need to convert your polygon into a "owin" object (see the
vignette about importing shapefiles in spatstat if necessary) and then
use functions gridcenters and inside.owin
For example
library(spatstat)
# this is an irregular "window" (aka owin object)
plot(letterR)
# make your regular grid
mygrid<-gridcenters(letterR, nx=10, ny=10)
# plot it
points(mygrid)
# which ones are inside the polygon?
points(as.data.frame(mygrid)[inside.owin(mygrid, w=letterR),], pch=19)
as.data.frame(mygrid)[inside.owin(mygrid, w=letterR),]
HTH,
Marcelino
El 29/05/2013 18:44, Matthew Forister escribió:
> Hi folks,
>
> I need to perform a certain map-based task in R, and I'm hoping that
> someone can point me towards the right package or approach:
>
> I have lat/long coordinates that specify the corners of a polygon, and I
> need to be able to draw a grid within that polygon where the points of the
> grid are regularly spaced at intervals I determine. Then I want to extract
> that list of points from the grid (so that I can send people out to take
> samples at those grid points).
>
> I've been looking around, and the closet thing I've seen is map.grid
> {mapproj}, which seems to be restricted to a shape defined by 4 points
> rather than a many-sided polygon which is what I need....
>
> Any pointers would be very welcome!
> thanks
> Matt
>
>
More information about the R-sig-ecology
mailing list