Reputation: 828
I always get error to this
# polygon that to be window
neighborhoods <- st_read("neighborhoods/neighborhoods.shp")
# convert CRS to planar projection as recommended by (https://stackoverflow.com/questions/59597078/use-sf-polygon-object-as-window-in-spatstat)
neighborhoods_3857 <- st_transform(neighborhoods, crs = 3857)
# point that to be PPP spatstat
trees <- st_read("trees/trees.shp")
# convert to planar projection
trees_3857 <- st_transform(trees, crs = 3857)
The problems, the "trees_3857" doesn't have dataframe columns that represent in EPSG3857 coordinates, so Feature column of "trees_3857" doesn't have x and y columns that respect to EPSG 3857
q <- ppp(x=?, y=?, win=neighborhoods_3857)
what I have done but error
z <- as.ppp(trees_3857, win=neighborhoods_3857)
Error in as.ppp.sf(trees_3857, win = neighborhoods_3857): unused argument (win = neighborhoods_3857)
Traceback:
You can get the data freely from datacamp.
https://assets.datacamp.com/production/repositories/738/datasets/96a72364e69d872645038b3a6dc7c0dbcb1114d6/neighborhoods.zip
https://assets.datacamp.com/production/repositories/738/datasets/08a3684dc4d538d59ba051a64a834166883ab5d1/trees.zip
Upvotes: 0
Views: 282
Reputation: 1984
Although you're wanting to transform your data into an object of class "ppp"
from the spatstat
package, the error message indicates that the problem originated in the function as.ppp.sf
which is part of the sf
package.
The error message says unused argument: win
which means that the function did not recognise or accept the argument win
.
Just to make it more challenging, the function as.ppp.sf
is not documented and is not visible... By typing sf:::as.ppp.sf
we can see the function body and figure out that the function has only one argument, so it does not accept any window information.
This is not the way the generic function as.ppp
is designed to work in the spatstat
package, so if you looked for help(as.ppp)
in spatstat
, it's not surprising that you got confused.
The best solution is (as Ege Rubak suggests) to convert the point coordinates and then add the window information:
z <- as.ppp(trees_3857)
Window(z) <- as.owin(neighborhoods_3857)
The conversions as.ppp
and as.owin
will be executed using code in sf
so I can't guarantee they will work. The assignment Window(z) <-
will be executed in spatstat
code, see help("Window<-.ppp")
.
Upvotes: 2