Rather than converting an object of class 'SpatialLines' or 
'SpatialLinesDataFrame' to the spatstat class 'psp' and then converting it to 
the spatstat class 'linnet', it is safer and more efficient to convert the 
SpatialLines* object directly to class linnet using 
as.linnet.SpatialLinesDataFrame() from the package 'maptools'.


Prof Adrian Baddeley DSc FAA

John Curtin Distinguished Professor

Department of Mathematics and Statistics

Curtin University, Perth, Western Australia


________________________________
From: Rolf Turner <r.tur...@auckland.ac.nz>
Sent: Friday, 21 June 2019 10:08 AM
To: Rolando Valdez
Cc: r-sig-geo@r-project.org; Adrian Baddeley; Ege Rubak
Subject: Re: [FORGED] [R-sig-Geo] Create a Spatial Weight Matrix based on road 
distance


On 21/06/19 12:26 PM, Rolando Valdez wrote:

> Dear community,
>
> Is there any way to create a spatial weight matrix based on road distance?
> I am trying to use the road distance between two points instead of
> euclidean distance.
>
> I've seen that there is a package named osrm. Can anyone give some advice?

I don't know anything about "osrm".  Calculating "road distances" can be
done in the spatstat package reasonably easily, if you take the trouble
to represent your collection of roads as a "linnet" object.

Given that you have done so, suppose that your linnet object is "L" and
that you have vectors "x" and "y" specifying the points on L (i.e. on
your roads) between which you want to know the distances.

Do:

     X    <- lpp(data.frame(x=x,y=y),L)
     dMat <- pairdist(X)

The object "dMat" is a (symmetric) square matrix; dMat[i,j] is the
distance between point i and point j.  (Of course the diagonal entries
are all 0.)

If your collection of roads is specified by means of a shapefile,
vignette("shapefiles") will tell you how to turn this collection into a
"psp" ("planar segment pattern") object; the function (method)
as.linnet.psp() can then be used to turn the "psp" object into a
"linnet" object.

HTH

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to