[R-sig-Geo] point.in.polygon() or over() help?

Roger Bivand Roger.Bivand at nhh.no
Thu May 23 17:17:39 CEST 2013


On Thu, 23 May 2013, Zack Holden wrote:

> Karen,
> you could try converting your polygons to raster using rasterize() in the
> raster library, and then use the extract() function to retrieve the cell
> values corresponding to your XY locations. I've used this workaround for
> similar problems in the past.

No, not a good idea. The error message from over() was given for a reason, 
that if the points and the polygon are not known to be in the same 
projection, then the outcome may be misleading. So my guess would be that 
the GPS are geographical coordinates and the coastal basins in State Plane 
appropriate for the location. Look at proj4string() of each object, and if 
they differ in predictable ways, use spTransform() to convert points to 
the polygons' projection, or vice-versa. over() does know what it is 
doing.

Hope this clarifies,

Roger

>
> Zack
>
>
>
> On Thu, May 23, 2013 at 9:00 AM, karengrace84 <kgfisher at alumni.unc.edu>wrote:
>
>> I am new to mapping with R and having some trouble. Here is what I am
>> trying
>> to accomplish. I am looking at fish tagging data. I have gps coordinates of
>> where each fish was tagged and released, and I have a map of 10 coastal
>> basins of the state of Louisiana. I am trying to determine which basin each
>> fish was tagged in, so that I can perform further analysis from there.
>>
>> I've used the sp and rgdal packages to input my shp files of the coastal
>> basins, and I have my list of gps coordinates where the fish were tagged.
>> I've tried using the point.in.polygon() function and the over() function
>> from the sp package unsuccessfully. Can someone please tell me how to use
>> one of these functions correctly, or if there is a better way to reach my
>> goal?
>>
>> For the point.in.polygon() function, I am unsure of how to get my data in
>> the correct format for the function. The generic form of the function is as
>> follows:
>>
>> point.in.polygon(point.x, point.y, pol.x, pol.y, mode.checked=FALSE)
>>
>> I have no problem with the point.x and point.y inputs. My problem is with
>> the pol.x and pol.y input. My polygon is currently in the form of a
>> SpatialPolygonsDataFrame. How do I get a numerical array of the x- and
>> y-coordinates from my polygon that will go into the point.in.polygon
>> function?
>>
>> Or for the over() function (x %over% y), with x as my SpatialPoints (the
>> gps
>> coordinates) and y as my SpatialPolygonsDataFrame (the basin), I receive
>> the
>> following error message, Error: identicalCRS(x, y) is not TRUE.
>>
>> Thanks for any suggestions.
>>
>>
>>
>> --
>> View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/point-in-polygon-or-over-help-tp7583635.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> 	[[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
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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