rgeoda icon indicating copy to clipboard operation
rgeoda copied to clipboard

Weight creation from polygons wrong

Open rsbivand opened this issue 3 years ago • 2 comments

It seems that queen_weights() is wrong (unzip attached file) in CRAN version 0.0.8.3: chk.zip

library(sf)
chk <- st_read("chk.gpgk")
library(rgeoda)
get_neighbors(rook_weights(chk, precision_threshold=sqrt(.Machine$double.eps)), 1)
get_neighbors(queen_weights(chk, precision_threshold=sqrt(.Machine$double.eps)), 1)
library(spdep)
poly2nb(chk, queen=FALSE)[[1]]
poly2nb(chk, queen=TRUE)[[1]]

From examining the geometries, the single coordinate on the borders of 1 and 6 is ignored:

plot(st_geometry(chk))
text(st_coordinates(st_centroid(st_geometry(chk))))

rsbivand avatar Aug 03 '21 12:08 rsbivand

Thank you, @rsbivand I can replicate it on my side. I was able to locate the issue in the libgeoda code: it is a bug that the double-precision epsilon was not handled in the weights creation code. I will commit a fix and create a new build.

lixun910 avatar Aug 03 '21 17:08 lixun910

Thanks, I can confirm that this works now as expected!

rsbivand avatar Aug 03 '21 18:08 rsbivand