On 07/10/2008 6:08 PM, claudia tebaldi wrote:
Dear R-helpers,
I have lat/lon coordinates of regularly spaced grid points, about 4Km
apart, covering the entire US continental region.
I would like to mask this rectangular grid in order to extract all and
only the grid points within a specific region. Today I want to
extract Montana, say, from this grid, and I am hoping to somehow use
the returned value of the function map("state",region="montana").
I'm not espoused to using the "maps" library database, it's just the
way I thought one could go about it (one smarter than I am...) and it
would certainly be useful to exploit the many political boundaries
provided by that library, when I move on from Montana to something
else...
Any suggestion for an algorithm to do this?
Of course if someone out there has a high-res mask for the US states
I'll happily forget about using map(): I'll take it and interpolate
(or knn1) away to my grid!
I believe this should work:
montana <- map("state", "montana", fill=TRUE, plot=FALSE)
inmontana <- !is.na(map.where(montana, x, y))
(where x and y are the longitude and latitude coordinates of your points).
Duncan Murdoch
______________________________________________
R-help@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.