title: From a shapefile with polygons/areas, and points (lat,lon), figure out which polygon/area each point belongs to? In R
body: <p>I am trying to identify which polygon (ZCTA... aka Zip Code analogue) a given point belongs in, given a set of points and a shapefile. While there are several questions of this type out there, nearly all seem to refer me toward QGIS. While I'll go and learn another tool if needed, is there a simple way to do this in R? I'm experienced in the R environment... not so much in the GIS space.</p>
  
  <p>The shapefile I am using is located here:
  <a href="ftp://ftp.gisdata.mn.gov/pub/gdrs/data/pub/us_mn_state_mngeo/bdry_zip_code_tabulation_areas/shp_bdry_zip_code_tabulation_areas.zip" rel="nofollow">ftp://ftp.gisdata.mn.gov/pub/gdrs/data/pub/us_mn_state_mngeo/bdry_zip_code_tabulation_areas/shp_bdry_zip_code_tabulation_areas.zip</a></p>
  
  <p>My first attempt was to load the shapefile as a SpatialPolygonsDataFrame, the points as a SpatialPointsDataFrame, then use "over()" to get the indicies of the polygons that match:</p>
  
  <pre><code>library(maptools)
  library(maps)
  library(sp)
  
  mn.zip.map &lt;- readShapePoly("zip_code_tabulation_areas.shp")
  # The shapefile is the one referenced in the link above
  
  latlon &lt;- data.frame(matrix(0,nrow=2,ncol=1))
  latlon$lat &lt;- c(44.730178, 44.784711)
  latlon$lon &lt;- c(-93.235381, -93.476415)
  latlon[1] &lt;- NULL
  coordinates(latlon) = ~lon+lat
  indices &lt;- over(latlon, mn.zip.map)
  </code></pre>
  
  <p>With results:</p>
  
  <pre><code>&gt; indices
  ZCTA5CE10 GEOID10 CLASSFP10 MTFCC10 FUNCSTAT10 ALAND10 AWATER10 INTPTLAT10 INTPTLON10
  1      &lt;NA&gt;    &lt;NA&gt;      &lt;NA&gt;    &lt;NA&gt;       &lt;NA&gt;      NA       NA       &lt;NA&gt;       &lt;NA&gt;
  2      &lt;NA&gt;    &lt;NA&gt;      &lt;NA&gt;    &lt;NA&gt;       &lt;NA&gt;      NA       NA       &lt;NA&gt;       &lt;NA&gt;
        Shape_Leng Shape_Area
  1         NA         NA
  2         NA         NA
  </code></pre>
  
  <p>I was hoping to have the first line output ZCTA5CE10 == 55124 and the second line output ZCTA5CE10 == 55379. However, clearly this isn't happening.</p>
  
  <p>It <em>seems</em> like the coordinate systems are not aligned... but they should both be Lat / Lon, right?</p>
  
  <p>What am I missing here? Thanks in advance.</p>