[R-sig-Geo] Spatial join of a point and polygon shapefile

Johan Van de Wauw johan.vandewauw at gmail.com
Fri Nov 2 22:21:45 CET 2007


This is what I usually do:
(points is a dataframe with x and y columns)

library("sp")
coordinates(points)=~x+y
polygon<-readShapePoly("shapefile.shp")
a<-overlay(points,polygon)
# a will contain the id's of the polygons per point
# . to get the attributes for every point I use:
polygon[a,]@data

--
Johan


On Nov 2, 2007 7:25 PM, Honey Giroday <honey_giroday at hotmail.com> wrote:
>
> Hi everyone
> I am a new useR running R on a Windows platform with Emacs.  I have been searching package manuals and email archives trying to solve this problem but have been unable to find a solution.  Your help with this is appreciated.
>
> I have generated random points within a polygon shapefile (with 1 polygon) using dotsInPolys.  I now want to sample a field (attribute data) of another polygon shapefile (with >>> 1 polygon) to add data to the points dataframe based on the point's spatial location (known by ArcView user's as a spatial join).  Is there a command in one of the spatial packages that would allow me to do this (I have found join.asc; however, I am looking for a command that will allow me to join vector data).  As I am new to posting, suggestions for clarifying my question or additional details I should provide would be appreciated.  Thank you for your time.
>
> Sincerely,
>
>
>
>
>
>
> Honey-Marie Giroday, M.Sc. Candidate, A.Ag., B.I.T. University of Northern British Columbia Prince George, BC, Canada
>
> _________________________________________________________________
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> 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