Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in st_sample() with type = "hexagonal" #1945

Closed
wiesehahn opened this issue May 24, 2022 · 2 comments
Closed

Error in st_sample() with type = "hexagonal" #1945

wiesehahn opened this issue May 24, 2022 · 2 comments

Comments

@wiesehahn
Copy link

Trying to run sample <- st_sample(dataset, dataset$samples, type = "hexagonal") returns

Error in seq_len(nrow(xy)) : 
  argument must be coercible to non-negative integer
In addition: Warning message:
In seq_len(nrow(xy)) : first element used of 'length.out' argument

However, it runs fine for parts of the dataset (e.g. sample <- st_sample(head(dataset), head(dataset$samples), type = "hexagonal")

I guess it has to do with parts of my dataset (dataset.zip) but I cant figure out how

There was a similar issue in #1220 but in my case it is projected

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
[1] dplyr_1.0.8 sf_1.0-7    here_1.0.1 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3            lattice_0.20-45         leaflet.providers_1.9.0 png_0.1-7              
 [5] class_7.3-20            rprojroot_2.0.2         digest_0.6.29           utf8_1.2.2             
 [9] V8_4.1.0                R6_2.5.1                stats4_4.1.2            e1071_1.7-9            
[13] geojson_0.3.4           pillar_1.7.0            rlang_1.0.2             lazyeval_0.2.2         
[17] curl_4.3.2              geojsonlint_0.4.0       rstudioapi_0.13         raster_3.5-15          
[21] geojsonio_0.9.4         webshot_0.5.2           jqr_1.2.3               foreign_0.8-82         
[25] htmlwidgets_1.5.4       munsell_0.5.0           proxy_0.4-26            compiler_4.1.2         
[29] rmapshaper_0.4.5        pkgconfig_2.0.3         base64enc_0.1-3         rgeos_0.5-9            
[33] htmltools_0.5.2         tidyselect_1.1.2        tibble_3.1.6            httpcode_0.3.0         
[37] codetools_0.2-18        mapview_2.10.0          jsonvalidate_1.3.2      fansi_1.0.3            
[41] crayon_1.5.1            wk_0.6.0                crul_1.2.0              grid_4.1.2             
[45] jsonlite_1.8.0          satellite_1.0.4         lifecycle_1.0.1         DBI_1.1.2              
[49] magrittr_2.0.2          units_0.8-0             scales_1.1.1            KernSmooth_2.23-20     
[53] cli_3.2.0               renv_0.15.4             leaflet_2.1.1           sp_1.4-6               
[57] ellipsis_0.3.2          generics_0.1.2          vctrs_0.3.8             RColorBrewer_1.1-2     
[61] geojsonsf_2.0.2         s2_1.0.7                tools_4.1.2             leafem_0.1.6           
[65] glue_1.6.2              purrr_0.3.4             crosstalk_1.2.0         yaml_2.3.5             
[69] fastmap_1.1.0           colorspace_2.0-3        terra_1.5-21            maptools_1.1-3         
[73] classInt_0.4-3    
> sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
       "3.9.1"        "3.2.1"        "7.2.1"         "true"         "true"        "7.2.1" 
@edzer edzer closed this as completed in 6d3e931 Jun 14, 2022
@edzer
Copy link
Member

edzer commented Jun 14, 2022

Thanks, this works now. Motivated by the long runtime of your example I added a progress bar:

> set.seed(1)

> library(sf)
Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE

> dataset = read_sf("dataset.gpkg")

> sample <- st_sample(dataset, dataset$samples, type = "hexagonal", progress = TRUE)
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01h 32m 10s
> sample
Geometry set for 230749 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 343957.3 ymin: 5682934 xmax: 667764.7 ymax: 5967101
Projected CRS: ETRS89 / UTM zone 32N
First 5 geometries:
POINT (344125.9 5823650)
POINT (344163.2 5823650)
POINT (344144.5 5823682)
POINT (344008.3 5823861)
POINT (344042.2 5823861)
> sum(dataset$samples)
[1] 229931

@wiesehahn
Copy link
Author

Indeed, now it's working, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants