[R-sig-Geo] st_sample with raster

Tyler Frazier ty|er@j@|r@z|er @end|ng |rom |c|oud@com
Sat Oct 10 07:32:02 CEST 2020


Hi Edzer,

Thank you for your answer (although sorry for my slow reply).  I was reading the help doc for st_sample() and noticed the type = argument.  Is it possible to do something like the following.

new_sf_points <- st_sample(sf_polygons, table(df$vector_of_values), type = as.im(raster_of_gridcell_densities))

Running just:

st_sample(sf_polygons, table(df$vector_of_values)) 

where the vector of values is equal in length to the number of polygons in the sf works fine, but I can’t seem to apply gridcell values/densities as weights.  I thought it might be possible to replicate the syntax from spatstat::rpoint() but it didn’t work.

Thanks so much for any additional insight you may have to offer!

Best wishes,
Tyler

Tyler J. Frazier, Ph.D.
Lecturer of Data Science
William & Mary
Webpage: https://tyler-frazier.github.io <https://tyler-frazier.github.io/>

> On Aug 10, 2019, at 4:38 AM, Edzer Pebesma <edzer.pebesma using uni-muenster.de> wrote:
> 
> sf::st_sample has a size argument, which can be specified as a vector to
> operate per feature. If you give that a value equal to
> 
> st_area(obj) * obj$required_density
> 
> and maybe set exact = FALSE, you should get the densities you want.
> 
> On 7/30/19 12:25 AM, Tyler Frazier via R-sig-Geo wrote:
>> Hi All,
>> 
>> Spatstat::rpoint has an argument f that accepts a pixel image object (class .im) to generate points based on the proportionate probability density of that raster.  Just wondering, does sf::st_sample or perhaps another function have a similar available method?
>> 
>> Thanks so much!
>> Ty
>> 
>> Tyler Frazier, Ph.D.
>> Lecturer of Interdisciplinary Studies
>> Data Science Program
>> College of William and Mary
>> Webpage: http://tjfrazier.people.wm.edu
>> Phone: +01 (757) 386-1269
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
> 
> -- 
> Edzer Pebesma
> Institute for Geoinformatics
> Heisenbergstrasse 2, 48151 Muenster, Germany
> Phone: +49 251 8333081
> <pEpkey.asc>_______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list