How to efficiently generate data of neighboring points
I tried looking at rtree package and even run the example at https://github.com/hunzikp/rtree but it gives me the same error message Error in UseMethod("withinDistance", rTree) : no applicable method for 'withinDistance' applied to an object of class "c('list', 'RTree')" That is strange given the page shows it was successful. Regarding the library(spdep) and using dnearneigh(), I read through the examples here https://r-spatial.github.io/spdep/reference/dnearneigh.html but I seem to have a challenge as to how to get the output from wd1,wd2, wd3, wd4 to my output object as in dataout. For example when I call wd1, I get :
wd1
Neighbour list object: Number of regions: 101 Number of nonzero links: 38 Percentage nonzero weights: 0.3725125 Average number of links: 0.3762376 67 regions with no links: How do I get the original point IDs and their respective neighbors IDs? Lom
On Tue, Jun 2, 2020 at 11:29 AM Roger Bivand <Roger.Bivand at nhh.no> wrote:
On Tue, 2 Jun 2020, Kent Johnson wrote:
rtree uses Euclidean distance so the points should be in a coordinate system where this makes sense at least as a reasonable approximation.
I tried the original example:
remotes::install_github("hunzikp/rtree")
library(spData)
library(sf)
projdata<-st_transform(nz_height, 32759)
library(rtree)
pts <- st_coordinates(projdata)
rt <- RTree(st_coordinates(projdata))
bufferR <- c(402.336, 1609.34, 3218.69, 4828.03, 6437.38)
wd1 <- withinDistance(rt, pts, bufferR[1])
but unfortunately failed (maybe newer Boost headers than yours?):
Error in UseMethod("withinDistance", rTree) :
no applicable method for 'withinDistance' applied to an object of class
"c('list', 'RTree')"
Going back to the last century:
library(spdep)
bds <- c(0, bufferR)
wd1 <- dnearneigh(pts, bds[1], bds[2])
wd2 <- dnearneigh(pts, bds[2], bds[3])
wd3 <- dnearneigh(pts, bds[3], bds[4])
wd4 <- dnearneigh(pts, bds[4], bds[5])
gives four neighbour objects. A neighbour object is an n-list of integer
vectors (0 encodes no neighbours), which you can use to find the rows to
copy out to your output object.
Does this get you started?
Roger
Kent On Tue, Jun 2, 2020 at 9:59 AM Roger Bivand <Roger.Bivand at nhh.no> wrote:
On Tue, 2 Jun 2020, Kent Johnson wrote:
Date: Tue, 2 Jun 2020 02:44:17 -0500
From: Lom Navanyo <lomnavasia at gmail.com>
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] How to efficiently generate data of neighboring
points within specified radii (distances) for each point in a
given
points data set.
Hello, I have data set of about 3400 location points with which I am trying
to
generate data of each point and their neighbors within defined radii
(eg,
0.25, 1, and 3 miles).
The rtree package is very fast and memory-efficient for within-distance calculations. https://github.com/hunzikp/rtree
Thanks! Does this also apply when the input points are in geographical coordinates? Roger
Kent Johnson
Cambridge, MA
[[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, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no https://orcid.org/0000-0003-2392-6140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
-- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no https://orcid.org/0000-0003-2392-6140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en