0

I'm attempting to discern whether a given lat/long coordinate falls within a particular US state. I have used the maps package to obtain lat/long coordinates for state borders. I suspect there is a way to ask whether the coordinate falls within the range of lat and long values encompassed by each state, but I have not figured out an elegant solution.

Basically, this is a way to identify whether a point falls within a region without having to know the region's name (since the maps package is pretty idiosyncratic in terms of naming regions, e.g., USSR), but still having the ability to extract the region name at a later point (for shading, etc.).

#Example coordinates
points=data.frame(lat=42,long=-100)
#Load US map
library(maps)
states=map_data("state")
#Summarize value of lat and long values for each region
library(plyr)
ddply(states,c("region"),function(x) return(c( range(x$long), range(x$lat) )) )

In the end, I want the data.frame states to have a final column giving true/false as to whether the points occur in that region. So, in the above example, all entries where region=="nebraska" would have true.

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
jslefche
  • 4,379
  • 7
  • 39
  • 50
  • [Here's a link to my answer](http://stackoverflow.com/questions/8751497/latitude-longitude-coordinates-to-state-code-in-r/8751965#8751965) to a very similar question. – Josh O'Brien Feb 12 '13 at 16:40
  • 1
    Indeed, that helped a lot. Sorry for opening a duplicate topic, but I can't appear to delete it. Voted to close – jslefche Feb 12 '13 at 20:35

0 Answers0