[R-sig-Geo] Assign a point to its nearest polygon

Paul Hiemstra paul.hiemstra at knmi.nl
Thu Jun 16 11:48:35 CEST 2011


 Hi Mathieu,

You could take a look at the overlay() command from the sp-package. You
could use this function to find out which  points are in which polygons.
This should allow you assign the point label to a polygon, especially if
one polygon is associated with just one point.

cheers,
Paul

On 06/16/2011 09:33 AM, Mathieu Rajerison wrote:
> HI,
>
>
> I've got a SpatialPointsDataFrame with labels of polygons but the polygon
> objects do not contain these labels.
>
> I want to find a way to assign the labels to their nearest polygons.
>
> I tried spatstat:nncros but my SpatialPolygonsDataFrame, when coerced to a
> psp object, is split up in many many lines. I couldn't find a way, with
> spatstat to accomplish this operation. But there may be one (?)
>
> I found out the geosphere package with function dist2Line. It seems nice
> because it works with both SpatialPointsData and SpatialPolygons.
>
> But when launching the command, I get:
>
> Erreur dans geosphere:::.pointsToMatrix(p) :
>   Points are projected. They should be in degrees (longitude/latitude)
>
> So my questions are:
> -is there a way to make this assignment easily with spatstat::nncross
> -is geosphere::dist2Line preferrable and if so, how can I convert my
> projected coordinates into lon/lat: any package existent? or necessary
> to type in the formula
> <http://www.ehow.co.uk/how_8449009_convert-xy-coordinates-longitude-latitude.html>?
>
>
> Thanks in advance, any help would be appreciated
>
> Mathieu
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-sig-Geo mailing list