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

G. Allegri giohappy at gmail.com
Wed Jul 23 02:25:22 CEST 2008


Maybe this could help?
http://sekhon.berkeley.edu/library/sp/html/overlay-methods.html

2008/7/23 Rick Reeves <reeves at nceas.ucsb.edu>:
> 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(R)
>> 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
>>
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>




More information about the R-sig-Geo mailing list