[R-sig-Geo] [FORGED] Create a Spatial Weight Matrix based on road distance
Rolando Valdez
rv@|dezr @end|ng |rom gm@||@com
Mon Jun 24 01:48:42 CEST 2019
I mean the distance between centroids of polygons that represent counties.
Thank you for your time.
El dom., 23 de jun. de 2019 a la(s) 01:17, Rolf Turner (
r.turner using auckland.ac.nz) escribió:
>
> On 23/06/19 6:01 PM, Rolando Valdez wrote:
>
> > I apologize for the lack of clarity.
> >
> > Let me try again:
> >
> > The SWM captures the spatial structure among territories. In the case of
> > a matrix based on distance, you define a distance-threshold, say 50 km,
> > and every territory under that distance is considered as neighbor, in
> > the matrix, those territories considered neighbors take the value 1, and
> > 0 otherwise (territories beyond 50 km). This is what 'dnearneigh'
> > function does.
> >
> > Then, I want to define a distance-threshold, say 50 km by road (not
> > euclidean) and every territory under that distance (by road) be
> > considered as neighbor.
>
> You still have not defined what you mean by *distance* between
> territories (regions, counties). Distance between *points* is well
> defined; distance between territories is not. You have to specify what
> you mean by such a distance. This could be the minimum distance between
> points in the regions (which is not of course a metric), distance
> between centroids of the territories, Hausdorff distance, or something
> else. This applies whether you are talking about the distance between
> points being Euclidean distance or road distance or some other metric.
> Thresholding that distance (e.g. at 50 km.) is then a trivial matter.
>
> I have tried my best to get you to clarify what you mean, and my efforts
> seem to be in vain. Since Juan Pablo thinks that I am "bullying you"
> (which mystifies me completely) I guess I'll give up. And to respond to
> Juan Pablo's hope, nothing whatever is "bothering" me.
>
> cheers,
>
> Rolf
>
> >
> > El sáb., 22 de jun. de 2019 a la(s) 21:15, Rolf Turner
> > (r.turner using auckland.ac.nz <mailto:r.turner using auckland.ac.nz>) escribió:
> >
> > On 23/06/19 3:30 PM, Rolando Valdez wrote:
> > > Sorry again.
> > >
> > > A Spatial Weight Matrix (swm) is an object used in spatial
> > econometrics
> > > to characterize the spatial structure among territories. It is an
> > > element nxn where n is the number of territorial units (counties,
> > > districts, states, cities, regions) in the sample and it could be
> > based
> > > on contiguity or distance. Usually, you can create a swm based on
> > > distance using 'dnearneigh' from spdep and then convert to a listw
> > > through 'nb2listw'. The problem is that the matrix that you
> generate
> > > trough 'dnearneigh'computes the euclidean distance among
> > centroids of
> > > polygons. This is where I spot my issue, I need to compute the
> > swm using
> > > the road distance instead of euclidean distance computed through
> > > 'dnearneigh'. I do have a shapefile with poligons (counties) and
> > another
> > > shapefile with lines (roads).
> >
> > OK. It's getting a *bit* clearer .... You are interested in "road
> > distances" between counties. I'm still not entirely sure what this
> > means. Is it the *minimum* distance by road from one county to
> > another?
> > In which case, if two counties are contiguous (adjacent) and there
> is a
> > road crossing the border between the two, is the distance between the
> > counties equal to zero? (This doesn't seem like it would be
> > satisfactory ....)
> >
> > Yes, actually it is possible that two counties were connected by more
> > than one road, however it's not a big deal. If I define a distance of 50
> > km, it doesn't matter how many times two counties are connected, I just
> > need that they are at 50 km trough, at least, one road.
> >
> > If this is not the case, then what *is* the case? Perhaps you want
> > distances between the *centroids* of the counties. What then do you
> > mean by road distance when the centroids do not lie on a road?
> >
> >
> > This is a big challenge, I'm still working on it.
> >
> >
> > You apparently need to deal with counties in which there are no
> > roads at
> > all. To handle this you have to define what *you* mean by the
> distance
> > by road from county A to county B when there are no roads at all in
> > county B. Perhaps infinity would be the appropriate distance, but
> *I*
> > don't know; you have to make the call.
> >
> >
> > If two counties are not connected through a road, they could not be
> > neighbors. In this case, it would correspond to a value 0 in the matrix.
> >
> >
> > Previously you indicated that you needed to know (pairwise) road
> > distances between specified points in a given set, and I showed you
> how
> > to obtain those using pairdist(), from spatstat. Now it seems that
> you
> > want something rather different, and it's still not clear what.
> >
> > In a sense is the same, but you said so properly, We have different
> > research fields.
> >
> > You need to get *your* thoughts clear; make some definitions and
> > specifications, and decide what you really want or need.
> >
> >
> > I got it.
> >
> >
> > It seems that you are expecting R to magically do your thinking for
> > you;
> > it won't!
> >
> > No, I'm not expecting that.
> >
> > cheers,
> >
> > Rolf
> >
> > > El sáb., 22 de jun. de 2019 a la(s) 20:00, Rolf Turner
> > > (r.turner using auckland.ac.nz <mailto:r.turner using auckland.ac.nz>
> > <mailto:r.turner using auckland.ac.nz <mailto:r.turner using auckland.ac.nz>>)
> > escribió:
> > >
> > >
> > > On 23/06/19 2:38 PM, Rolando Valdez wrote:
> > >
> > > > I am sorry, I was not clear enough. My goal is to
> calculate a
> > > spatial
> > > > weight matrix (nxn) across counties but, instead of
> euclidean
> > > distance,
> > > > to use road distance.
> > >
> > > I'm afraid I still don't understand. To put it mildly. You
> > presumably
> > > have a clear idea of what you are trying to, but those of us
> > who are
> > > not
> > > involved in your research have no such idea. We (or at least
> I)
> > > haven't
> > > a clue as to what you are talking about.
> > >
> > > What do you mean by "spatial weight"? What are these weights
> > used for?
> > > What is n? How are the counties involved? Is n the number of
> > > counties?
> > > Are you interested in the road distance (minimum road
> distance?)
> > > between
> > > pairs of counties?
> > >
> > > Please explain *clearly* and do not expect those who are
> > trying to help
> > > you to be mind-readers!!!
> > >
> > > cheers,
> > >
> > > Rolf
> > >
> > > >
> > > > El sáb., 22 de jun. de 2019 a la(s) 19:28, Rolf Turner
> > > > (r.turner using auckland.ac.nz <mailto:r.turner using auckland.ac.nz>
> > <mailto:r.turner using auckland.ac.nz <mailto:r.turner using auckland.ac.nz>>
> > > <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz> <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>>>)
> > > escribió:
> > > >
> > > >
> > > > On 23/06/19 1:17 PM, Rolando Valdez wrote:
> > > >
> > > > > Thank you for your answer.
> > > > >
> > > > > I have a shapefile with, say, counties, and I got
> > another
> > > > shapefile with
> > > > > the roads. ¿What if a county does not intersect any
> > road?
> > > >
> > > > I am sorry, but it is not at all clear to me just what
> the
> > > problem is.
> > > > How do the counties come into the picture? You said
> you
> > > wanted to get
> > > > the road distance between points on the roads. What
> > have the
> > > counties
> > > > got to do with this?
> > > >
> > > > Can you perhaps provide a reproducible example?
> > > >
> > > > cheers,
> > > >
> > > > Rolf
> > > >
> > > > >
> > > > > El jue., 20 de jun. de 2019 a la(s) 19:08, Rolf
> Turner
> > > > > (r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz> <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>>
> > > <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz> <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>>>
> > > > <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>
> > > <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>> <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>
> > > <mailto:r.turner using auckland.ac.nz
> > <mailto:r.turner using auckland.ac.nz>>>>)
> > > > escribió:
> > > > >
> > > > >
> > > > > 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
>
--
Rol~
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list