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

Roger Bivand Roger.Bivand at nhh.no
Fri Nov 2 21:29:36 CET 2007


On Fri, 2 Nov 2007, Honey Giroday 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.

Welcome!

If you can make (or import) your points and polygons into SpatialPoints 
and SpatialPolygons, as defined in the sp package, the overlay methods 
there will do this for you. Overlaying the points on the polygons will 
yield a vector as long as the number of points with NA where they miss the 
polygons, and numbers between 1 and n (# polygons) saying which polygon 
the point falls in.

You could also have used the spsample methods there too for generating the 
points. If your polygons are coming from shapefiles, then readShapePoly() 
in the maptools package will make them into SpatialPolygonsDataFrame 
objects (or readOGR() in rgdal, which also reads other vector file 
formats). There was a thread on sampling on this list last month which you 
might find entertaining, you have found yet another way:

https://stat.ethz.ch/pipermail/r-sig-geo/2007-October/002625.html

Roger

>
> 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
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list