1

My goal is to create an im object from terrain elevation data (pp3's z-axis), similar to bei.extra ($elev and $grad). I started by creating a pp3 object from my data set:

x <- elev_test$x
y <- elev_test$y
z <- elev_test$z
X <- pp3(x, y, z, c(0, 102), c(0, 152), c(90, 102))
plot(X)

enter image description here

Then I tried to coerce the pp3 object to class im, but as.im threw an error:

> Elev_im <- as.im(X)
Error in as.im.default(X) : Can't convert X to a pixel image

How can I obtain the desired im object?

Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
Tieygons
  • 43
  • 5

2 Answers2

2

Conversion functions like as.im are designed to convert data from one format to another format that represents the same information.

You are trying to infer the spatial height of a surface from a sample of (x,y,z) sample points. That's not a conversion between formats; that is some kind of interpolation.

I suggest you create a two-dimensional point pattern using the (x,y) coordinates for the locations, and use the z coordinates as marks of this pattern. Then smooth the marks to obtain a surface.

Something like:

X <- ppp(elev_test$x, elev_test$y, c(0, 102), c(0, 152), marks=elev_test$z)
Z <- Smooth(X)

Then you can try different arguments to Smooth.ppp to get the best interpolant.

Another possibility would be to use nnmark instead of Smooth.ppp to obtain a surface consisting of small flat pieces (this would be better if your points come from a rice paddy field). You'll have to make these decisions yourself as the computer is not wise enough.

Adrian Baddeley
  • 2,534
  • 1
  • 5
  • 8
  • Great, I got it. Thanks a lot for the help. I have just one more question, if I also want to calculate the slope (equal to bei.extra$grad), is it possible to do this only in spatstat? I tried for a few hours in different ways via raster, but I can't convert back to some kind of spatstat object. – Tieygons Mar 25 '23 at 18:17
0

About creating an object similar to bei.extra$grad, with an area slope map, I think I found a solution, via raster:

  1. add my data with x, y and z coordinates in ArcGis software;
  2. I created the 2D Elevation of the terrain;
  3. I calculated the terrain slope [slope] and exported the tif [raster] map.

Finally, in R:

#import raster (tif)
r<-raster("Slope_raster12.tif")
#convet raster in im class 
sppp<-as.im(r)
plot(sppp, axes=T)

slope in %.

Note: slope in %.

Tieygons
  • 43
  • 5