question about rgeos "gDistance" parameters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

question about rgeos "gDistance" parameters

R-sig-geo mailing list
Can someone better explain what the byid parameter does in the gDistance command? The help for the command states:
"Logical vector determining if the function should be applied across ids (TRUE) or the entire object (FALSE) for spgeom1 and spgeom2"

If spgeom1 is a spatial points objects and spgeom2 is a shapefile with multiple polygons, will byid=FALSE return a single value and byid=TRUE return a matrix of the distances between every point and every polygon? If I'm correct, what does that single value represent (e.g. which distance) when byid=TRUE?
Thanks
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: question about rgeos "gDistance" parameters

Roger Bivand
Administrator
Please post plain text only - since you didn't provide an example, your
code wasn't deformed by HTML formatting, but had you provided an example
it would have been. Did you look at the examples on the help page?

library(rgeos)
pt1 = readWKT("POINT(0.5 0.5)")
pt2 = readWKT("POINT(2 2)")

p1 = readWKT("POLYGON((0 0,1 0,1 1,0 1,0 0))")
p2 = readWKT("POLYGON((2 0,3 1,4 0,2 0))")

gDistance(pt1,pt2)
gDistance(p1,pt1)
gDistance(p1,pt2)
gDistance(p1,p2)

Modifying this:

pt3 <- rbind(pt1, pt2)
row.names(p2) <- "2"
p3 <- rbind(p1, p2)
gDistance(pt3, p3)
gDistance(pt3, p3, byid=c(TRUE, TRUE))
gDistance(pt3, p3, byid=c(TRUE, FALSE))
gDistance(pt3, p3, byid=c(FALSE, TRUE))

Hope this clarifies,

Roger

On Fri, 10 Nov 2017, Julie Lee-Yaw via R-sig-Geo wrote:

> Can someone better explain what the byid parameter does in the gDistance
> command? The help for the command states: "Logical vector determining if
> the function should be applied across ids (TRUE) or the entire object
> (FALSE) for spgeom1 and spgeom2"
>
> If spgeom1 is a spatial points objects and spgeom2 is a shapefile with
> multiple polygons, will byid=FALSE return a single value and byid=TRUE
> return a matrix of the distances between every point and every polygon?
> If I'm correct, what does that single value represent (e.g. which
> distance) when byid=TRUE? Thanks
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway