Re: [R] point.in.polygon help

2013-05-23 Thread Daisy Englert Duursma
It would be useful to know what your ultimate goal is.

On Wed, May 22, 2013 at 6:29 AM, karengrace84 kgfis...@alumni.unc.edu wrote:
 I am new to mapping with R, and I would like to use the point.in.polygon
 function from the sp package, but 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. I have a list of gps
 longitudes and latitudes that will go in fine. My problem is with the pol.x
 and pol.y input. My polygon is currently in the form of a
 SpatialPolygonsDataFrame created by inputting shp files with the rgdal
 package.

 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?



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 9256

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] point.in.polygon help

2013-05-23 Thread karengrace84
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. 



--
View this message in context: 
http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645p4667808.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] point.in.polygon help

2013-05-23 Thread MacQueen, Don
In that case I'd definitely look more at the over() function than that
ugly bit I suggested before.

Get your fish info into a SpatialPointsDataFrame

Since your polygons are in a SpatialPolygonsDataFrame, I would expect the
data frame part has one row per basin, and it contains the basin names or
other unique identifier. Loop through the basin names, subsetting the
SpatialPolygonsDataFrame for each each basin, then use the over() function
the with the fish SpatialPointsDataFrame to tell you which fish are in the
current basin.

That's an outline; there are obviously lots of details that would be
needed.

This should work even if, for example, a single basin consists of more
than one polygon (presumably non-overlapping).

There may be a more efficient way, but I don't know it off the top of my
head.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 5/23/13 6:03 AM, karengrace84 kgfis...@alumni.unc.edu wrote:

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. 



--
View this message in context:
http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645p4667808.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] point.in.polygon help

2013-05-22 Thread MacQueen, Don
First suggestion is to ask the question on r-sig-geo.

There is the  over()
function in the sp package, though it may require you to put your points
in a spatial class object.


For a crude brute-force approach that does not easily generalize, but
might be the quickest short-term solution for you right now, and assuming
your object has just a single polygon, try this:

  your.spdf@polygons[[1]]@Polygons[[1]]@coords


That should give you a two column matrix representing your polygon.

You may need to remove the last row for pol.x and pol.y, since in this
implementation the last row = the first row.


-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 5/21/13 1:29 PM, karengrace84 kgfis...@alumni.unc.edu wrote:

I am new to mapping with R, and I would like to use the point.in.polygon
function from the sp package, but 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. I have a list of
gps
longitudes and latitudes that will go in fine. My problem is with the
pol.x
and pol.y input. My polygon is currently in the form of a
SpatialPolygonsDataFrame created by inputting shp files with the rgdal
package.

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?



--
View this message in context:
http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] point.in.polygon help

2013-05-21 Thread karengrace84
I am new to mapping with R, and I would like to use the point.in.polygon
function from the sp package, but 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. I have a list of gps
longitudes and latitudes that will go in fine. My problem is with the pol.x
and pol.y input. My polygon is currently in the form of a
SpatialPolygonsDataFrame created by inputting shp files with the rgdal
package.

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?



--
View this message in context: 
http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] point.in.polygon help

2012-01-13 Thread Hasan Diwan
  x - sapply(c(1:max(greens[,1])), function() {
poly.x - greens[greens[,1] == hole, 2]
poly.y - greens[greens[,1] == hole, 3]
p.x - gps[,3]
p.y - gps[,4]
require(sp)
gps[which(point.in.polygon(p.x,p.y,poly.x,poly.y) != 0),ncol(gps)]
- gps[which(point.in.polygon(p.x,p.y,poly.x,poly.y) != 0),ncol(gps)]
+ 0.2
}
gps is a set of GPS readings from a golf course and greens is a
data.frame consisting of coordinates for the 18 holes. The code above
is supposed to show which (gps[,3], gps[,4]) lie within a polygon with
edges p.x, and p.y. It's not quite working, samples from gps and
greens follow:
 head(greens)
  holeno   latitude   longitude
1  1 37.55451273121 -122.3801181128
2  1 37.55446160943 -122.3801234772
3  1 37.55443003419 -122.3801140894
4  1 37.55440898403 -122.3800966551
5  1 37.55440296970 -122.3800778796
6  1 37.55438342311 -122.3800644686
 head(gps)
  logged_on   longitude   latitude speed tag_id track score
1 132173859 -122.3811569214 37.55739593506  0.14   NA 95.84   0.2
2 1321738591000 -122.3812255859 37.55743408203  0.15   NA 95.84   0.2
3 1321738592000 -122.3812179565 37.55741882324  0.27   NA 95.84   0.2
4 1321738593000 -122.3812789917 37.55744934082  0.53   NA 95.84   0.2
5 1321738594000 -122.3812789917 37.55744552612  0.11   NA 95.84   0.2
6 1321738595000 -122.3812637329 37.55744171143  0.06   NA 95.84   0.2

There should be about 36 points in the polygon outlined and the code
is outputting no points.  Many thanks and do be in touch if you desire
further information...
-- 
Sent from my mobile device
Envoyait de mon portable

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.