joelgombin / concaveman

A very fast 2D concave hull algorithm
https://joelgombin.github.io/concaveman/
66 stars 7 forks source link

function doesn't return original coordinates #13

Open toobiwankenobi opened 4 years ago

toobiwankenobi commented 4 years ago

First, thank you for creating this nice wrapper function! As the title already indicates, the function does not return the original coordinates. It seems that this is a rounding issue. Please see my example code which should illustrate the problem.

# create dummy data.frame with X/Y coordinates and ID column
cur_df = 1:500
cur_df = as.data.frame(cbind(cur_df, matrix(rexp(1000, rate=.1), ncol=2)))
colnames(cur_df)<- c("id", "X", "Y")

# compute concave hull
coords <- as.matrix(cbind(cur_df$X, cur_df$Y))
hull = as.data.table(concaveman(coords, concavity = 1))  
colnames(hull) <- c("X", "Y")

# how many data points make up the hull?
nrow(hull)
[1] 212

# return common rows between input and the hull
common <- inner_join(cur_df, hull)  
> Joining, by = c("X", "Y")

# number of common rows
nrow(common)
[1] 0

My input consists of coordinates that have 8 digits but the output coordinates from the concave function have only 4 digits. Therefore, it is not possible to find the common rows (by the inner_join function) between input and output.

I don't know if this behavior is intended but I think it should not be the default.

Thank you!

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.8.5       data.table_1.12.8 sf_0.9-3          concaveman_1.1.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6       rstudioapi_0.11    magrittr_1.5       units_0.6-6        tidyselect_1.1.0   R6_2.4.1          
 [7] rlang_0.4.6        tools_4.0.0        grid_4.0.0         KernSmooth_2.23-17 e1071_1.7-3        DBI_1.1.0         
[13] ellipsis_0.3.1     class_7.3-17       assertthat_0.2.1   tibble_3.0.1       lifecycle_0.2.0    crayon_1.3.4      
[19] purrr_0.3.4        vctrs_0.3.0        curl_4.3           glue_1.4.1         V8_3.0.2           compiler_4.0.0    
[25] pillar_1.4.4       classInt_0.4-3     jsonlite_1.6.1     pkgconfig_2.0.3