[R-sig-Geo] Determining in which polygon points lie

Lionel Hertzog s6lihert at uni-bonn.de
Fri Jun 14 18:05:38 CEST 2013


Dear Dieter,

You can download gadm files as R SpatialPolygonsDataFrame. Then using 
load you can load them in your session.
You should keep only the column of interest for you (the N-region 
identifiers) in the SpatialPolygons, you can then use the 'over' 
function in the sp package to get for each polygons (region) the points 
ID (usually their row number, but if you have a SpatialPointsDataFrame 
the first column values).

Sincerely yours,
Lionel

On 14/06/2013 17:51, Dieter Vanderelst wrote:
> Dear List,
>
> I'm reading in a shapefile of a country with different subregions in 
> the shapefile (the shapefile was downloaded from the GADM database of 
> Global Administrative Areas). I also have a number of points. 
> Therefore, my code looks like this (using the maptools package):
>
> country<-readShapePoly(file)
> points<-readShapePoints(file)
>
> Now, I want to know in which of the N regions of the country each of 
> the spatial points lies? Is there an easy way to do this? I know there 
> is a function points.in.poly in sp. But this functions seems 
> incompatible with the objects created by the maptools functions. Also, 
> this function requires looping over the regions in a set.
>
> Regards,
> Dieter
>
> ---
> Behavioural, Acoustic and Sensory Ecology Lab
> University Bristol, UK
>
> http://bitsofbats.weebly.com/
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list