0
votes

I am trying to learn to use spatstat package in R from the book of Baddeley et al. I have converted my shapefile to a psp object (here it said 6 columns of data discarded) then I used as.linnet to convert this to linear network suitable for spatstat. (here it said network not connected)

Then I wanted to create a point pattern on this network using the rpoislpp and I used poisson intensity of 2.

> abc<-rpoislpp(2,final_roads)
> head(abc)
Point pattern on linear network
3 points
Linear network with 4296 vertices and 4475 lines
Enclosing window: rectangle = [30093.5, 278045.11] x [308520.5, 606556.7] units
> abc
Point pattern on linear network
10190733 points
Linear network with 4296 vertices and 4475 lines
Enclosing window: rectangle = [30093.5, 278045.11] x [308520.5, 606556.7] units

This created an enormous 1GB file. I dont understand how. My understanding from the book is the poisson intensity is number of points per total length of linear network. My network is about 5000 km (road network of a province), so I was just requesting 2 points in the whole network.

My questions are

  1. I do not understand how could it be 10 million points. I just wanted to create 2 points in the whole network and plot them.
  2. how to plot these points and get their x,y

Am I doing something wrong? Any advice would be great. Thanks

2
I realized the mistake for question 1. But I still look for answer on question 2. - BKS

2 Answers

0
votes

I don't have access to your data, so I will use the built-in dataset chicago as an example:

abc <- unmark(chicago)
plot(abc) # Plot the network and the points on the network
X <- as.ppp(abc) # Convert to planar point pattern without network
plot(X) # Plot the points in the plane
co <- coords(X) # Extract the Cartesian coordinates

Is this what you are looking for? You can also use coords(abc) directly then you get both the Cartesian coordinates and the local coordinates in the network.

0
votes

Q1: In a Poisson process, the intensity lambda is the expected number of points per unit length. If the total length of the network is L, then a Poisson process with intensity lambda will contain about L * lambda points. In your example, the printout suggests that the coordinates are in metres, so you have L = 5 000 000 metres, and if lambda = 2, you get about 10 million points.

To get a fixed number of random points, use runiflpp instead of rpoislpp. So runiflpp(2, final_roads) would put 2 random points on your road network.

Best practice: specify the unit of length using unitname, and consider rescaling the coordinates from metres to kilometres using rescale.

Q2: If X is a point pattern on a linear network, then to plot the points on the lines, just use plot(X). To extract just the point locations, use Y <- as.ppp(X), then to plot just the point locations, plot(Y). To extract the x,y coordinates, use xy <- coords(Y) or xy <- coords(X, local=FALSE).

For further details see Chapter 17 of the spatstat book.