Hello all potential helpers,
I have a SpatialPolygonDataFrame
object obtained from the tigris
package and I would like to use it as a polyg
just want to note here that coercion methods for sf classes are now registered (if that's the right word) by the sf package. I don't fully understand the R magic that finds methods, but it does work.
library(sf)
library(spatstat)
> methods(as.owin)
[1] as.owin.boxx as.owin.data.frame as.owin.default as.owin.distfun
[5] as.owin.dppm as.owin.funxy as.owin.im as.owin.influence.ppm
[9] as.owin.kppm as.owin.layered as.owin.leverage.ppm as.owin.linfun
[13] as.owin.linnet as.owin.lintess as.owin.lpp as.owin.lppm
[17] as.owin.msr as.owin.MULTIPOLYGON* as.owin.nnfun as.owin.owin
[21] as.owin.POLYGON* as.owin.ppm as.owin.ppp as.owin.psp
[25] as.owin.quad as.owin.quadratcount as.owin.quadrattest as.owin.rmhmodel
[29] as.owin.sf* as.owin.sfc* as.owin.sfc_MULTIPOLYGON* as.owin.sfc_POLYGON*
[33] as.owin.SpatialGridDataFrame* as.owin.SpatialPixelsDataFrame* as.owin.SpatialPolygons* as.owin.tess
see '?methods' for accessing help and source code
So, assuming you have properly projected your data (as noted by @Ege Rubak), calling as.owin
directly should work:
library(tigris)
county <- county_subdivisions(state = "Alabama",
county = "Lee",
class = "sf",
progress_bar = FALSE)
county <- st_union(county)
county <- st_transform(county, crs = 6345)
window <- as.owin(county)
plot(window)