Sf: st_sample with regular sample

Created on 14 Jun 2018  路  11Comments  路  Source: r-spatial/sf

So far st_sample makes only random samples. Will there soon be a way as to not go via the as(sf,"Spatial") ? Would be really helpful as I think calculation and memory could be well reduced like this.

sample <- spsample(x = as(sf,"Spatial"), type = "regular", cellsize = cellsize, bb= bbox(as(sf,"Spatial")), offset=c(0.5,0.5))
samplesf <- st_as_sf(sample)

All 11 comments

Now available (for testing!) in branch hex.

Thanks!
I obtained an error message:

Error in UseMethod("units") :
no applicable method for 'units' applied to an object of class "c('double', 'numeric')"

Traceback:

  1. st_poly_sample(x = shape, size = 1000, type = "regular")
  2. Ops.units((offset[1] - bb["xmin"]), dx)
  3. units(e1)

If I change dx to as.numeric it works fine.

Maybe update pkg units first? What is your sessionInfo()?

Updating units is sadly not the solution.

My Session-Info:
```
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

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

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

other attached packages:
[1] gdalUtils_2.0.1.14 rgdal_1.3-2 sp_1.3-1 sf_0.6-3 units_0.6-0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 codetools_0.2-15 lattice_0.20-35 class_7.3-14 foreach_1.4.4 R.methodsS3_1.7.1
[7] grid_3.5.0 spData_0.2.9.0 DBI_1.0.0 magrittr_1.5 e1071_1.6-8 raster_2.6-7
[13] R.oo_1.22.0 R.utils_2.6.0 iterators_1.0.9 tools_3.5.0 compiler_3.5.0 classInt_0.2-3
```

Your sf is still on 0.6-3, so it seems you didn't install the changes I made.

Now merged into master.

Unfortunately I still get the same error.
My Session-info:

R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

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 utils     datasets  methods   base     

other attached packages:
[1] sp_1.2-7 sf_0.6-4

loaded via a namespace (and not attached):
 [1] compiler_3.4.0  magrittr_1.5    class_7.3-14    DBI_1.0.0       tools_3.4.0     units_0.6-0    
 [7] Rcpp_0.12.17    grid_3.4.0      e1071_1.6-8     classInt_0.2-3  spData_0.2.8.3  lattice_0.20-35

My Test-Polygon:
Simple feature collection with 1 feature and 1 field geometry type: POLYGON dimension: XY bbox: xmin: -8663534 ymin: -2583322 xmax: 1309049 ymax: 13816680 epsg (SRID): NA proj4string: +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs Id geometry 1 0 POLYGON ((-3792533 7879244,...

The Error:
Error in UseMethod("units") : no applicable method for 'units' applied to an object of class "c('double', 'numeric')"

Could you please provide a reproducible example, either here or if must off-github (by email)?

test_polygon.zip

My Code:

test <- st_read("E:/Ariane/test_sample.shp")
st_sample(x = test,size = 1000,type = "regular" )

That's my Test-Data Set I was trying it with and got the error.

Thanks, should work now!

Works fine now, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmsigner picture jmsigner  路  4Comments

kendonB picture kendonB  路  3Comments

happyshows picture happyshows  路  3Comments

kendonB picture kendonB  路  4Comments

faridcher picture faridcher  路  4Comments