I've been testing the waters and doing some basic overview on the statspat package. This is a complex package and would likely require some serious effort to jump in and then get familiar with the package.

This package seems to have some great features - including drawing a radial line from a given point at some defined angle. This feature saves the effort from doing the math to accomplish the same task. And it accomplishes the task with a simple line of code that is intuitive and very readable.

plot(0, xlim=c(0,5), ylim=c(0,5), main=" radial & sp ", xlab="", ylab="", type="n") 
    draw.radial.line(0, 2, center=c(3,3), angle=90)         # create spatstat object

# create spatial linestring object and combine with the plot:

    p1 <- c(3,2)
    p2 <- c(3,4)
    mypt <- matrix(data = c(p1, p2), nrow = 2, ncol = 2, byrow = T)
    mypt.sf <- st_linestring(mypt, dim = "XY")
    plot(mypt.sf, add = TRUE)

The spatial linesting object and the radial line object both plot nicely together.

But since these two lines are different types of objects, the st_intersects() and other similar functions don't recognize the radial line. Even though these object plot together, it looks like these objects won't play together well.

The spatstat package has many features that convert spatial objects to spatstat objects, but there doesn't seem to be any similar features for converting spatstat objects back to sp objects. I looked around and haven't found any way to convert spatstat objects to sp objects.

So this question boils down to asking whether there is a way to convert a spatstat objects to spatial or simple feature object? Or is there another package that provides some simple functions similar to the spatstat, draw.radial.line() function ? And if so, do these objects convert back and forth and play well with sp or sf objects?

Link to plot link

  • If you add the map tools package there are some functions for coercing from spatstat to sp as well as, in certain cases, support for as coersion. – Jeffrey Evans Aug 30 '20 at 14:26
  • spatstat <--> sf conversions have been added last march to package sf; see github.com/r-spatial/sf/issues/1233 ; they do not cover all spatstat classes, but ppp, psp and owin. – Edzer Pebesma Aug 30 '20 at 17:32
  • 1
    Your code btw does not contain any spatstat commands; the draw.radial.line comes from package plotrix (and takes angle in radians). – Edzer Pebesma Aug 30 '20 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.