-
Notifications
You must be signed in to change notification settings - Fork 297
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
spatstat <--> sf conversions #1233
Comments
Note that this is done in a branch called "ppp". |
* remove maptools dependency * namespace issues * test results
This looks great @edzer! I will try to have a closer look this coming week. |
EDIT: I installed the development version of the {stars} package and it worked end EDIT. I am not able to replicate this code chunk:
I get this error when I run |
I installed the ppp branch of the {sf} package; however, I am not able to run this code:
|
@gueyenono for the stars problem, you need to install the github version of stars, branch master; for the |
Removing |
I merged this branch now into |
I have only started looking, but I have an example where a suppressPackageStartupMessages(library(spatstat))
suppressPackageStartupMessages(library(sf)) W <- Window(gordon)
plot(W) A point in a polygonal hole is correctly classified as “outside” by inside.owin(4, -27, W)
#> [1] FALSE Converting the owin directly to W_sf <- st_as_sf(W)
W_sf
#> Simple feature collection with 1 feature and 0 fields
#> geometry type: POLYGON
#> dimension: XY
#> bbox: xmin: -26.40848 ymin: -36.32095 xmax: 26.40848 ymax: 36.32095
#> epsg (SRID): NA
#> proj4string: NA
#> geom
#> 1 POLYGON ((22.0448 -14.20711...
p_sf <- st_point(matrix(c(4,-27),ncol=2))
st_contains(W_sf, p_sf) # Point not contained in polygon (correct)
#> Sparse geometry binary predicate list of length 1, where the predicate was `contains'
#> 1: (empty) However if X <- ppp(numeric(0), numeric(0), window = W)
W_sf2 <- st_as_sf(X)
W_sf2
#> Simple feature collection with 1 feature and 1 field
#> geometry type: MULTIPOLYGON
#> dimension: XY
#> bbox: xmin: -26.40848 ymin: -36.32095 xmax: 26.40848 ymax: 36.32095
#> epsg (SRID): NA
#> proj4string: NA
#> label geom
#> 1 window MULTIPOLYGON (((22.49851 -1...
st_contains(W_sf2, p_sf) # Point allegedly in polygon (wrong)
#> Sparse geometry binary predicate list of length 1, where the predicate was `contains'
#> 1: 1 Probably, the problem is due to the conversion of the polygon through edges here: Lines 1 to 9 in 1e095d4
I assume the same problem is present when converting |
Just checked that the problem is the same for Now that I looked further into the code I see that the I also noticed there are some issues with multiple columns of marks (at least for |
Thanks! I think |
Should nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
spatstat::as.owin(nc$geometry[[1]])
#> Error in spatstat::owin(bb[c("xmin", "xmax")], bb[c("ymin", "ymax")], :
#> Area of window is negative;
#> check that all polygons were traversed in the right direction |
Yes, that makes sense! |
I tried to implement a number of sf -> spatstat conversions, and vice versa. A review by the spatstat team e.g. @rubak would be appreciated. I'm in particular not sure whether the observation windows for the psp objects make sense.
Here is a demo:
plot(as.psp(st_sfc(ls)))
plot(as.psp(st_sfc(mls)))
The text was updated successfully, but these errors were encountered: