[R-sig-Geo] identying shapefile polygons containing long-lat points

Rick Reeves reeves at nceas.ucsb.edu
Wed Jul 23 02:03:56 CEST 2008


Hi:

Check out the FindPolys method in the PBSMapping package. here is a code 
snippet from a larger example:
(I will be extracting a simpler use case for distribution soon, but this 
will give you the general idea....

HucPolys = readShapePoly("AllHucsMerged")
DamPoints = readShapePoints("Part1Dams")
#
NumHucs = length(HucPolys at data[,1])
NumDams = length(DamPoints at data[,1])
#
# promote points to EventData for compatability with FindPolys
#
DamEvents <- as.EventData(data.frame(EID=1:NumDams ,X=DamPoints at coords[,1],
Y=DamPoints at coords[,2]),projection = "LL")
#
ValidHucsSP = SpatialPolygons2PolySet(HucPolys)
#
# Prepend (add to front) column to DamPoints data frame for HUC assignment
#
Huc8ID = as.numeric(c(1:NumDams))
dim(Huc8ID) = c(NumDams,1)
DamPoints at data = cbind(Huc8ID,DamPoints at data)
#
# convert factors to strings in Data Frames and Lists.
#
print(sprintf("about to assign.."))
browser()
#
# note: it is possible for a PointPolyFlags entry to be NA, if
# no polygon was found for a specific point.
#
PointPolyFlags = findPolys(DamEvents,ValidHucsSP)

OR, check out this example, which is more compete:

http://nceas.ucsb.edu/scicomp/GISSeminar/UseCases/PointInPolygonAnalysis/point_in_poly.html

Hope this helps!


jatwood at montana.edu wrote:
> Good Afternoon
> I searched the archives but could not find the answer to my question.
> I have shapefiles for various geographic regions such as states, counties,
> zipcode areas, townships, etc.  I also have long-lat coordinates for 12000
> plus weather stations.  I am able to use maptools to plot the maps and am
> able to plot the points on the polygon maps with appropriate text. However,
> I also need to be able to identify which shapefile polygon each weather
> station (or pobbibly other long-lat points) lies within.
>
> Does any package have a function similar to the "maps" packages'
> "map.where" function that would work with more general shapefile polygons?
>
> I am new to this list so please excuse me if this question has been
> previously addressed.  I will appreciate any help or suggestions.
>
>    
>
> --------------------------------------------------------------------
> mail2web.com – Enhanced email for the mobile individual based on Microsoft®
> Exchange - http://link.mail2web.com/Personal/EnhancedEmail
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reeves.vcf
Type: text/x-vcard
Size: 339 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20080722/265cb973/attachment.vcf>


More information about the R-sig-Geo mailing list