On Mon, 24 Jun 2019, Rolando Valdez wrote:
Dear Andres,
I could follow an example provided with the package, it was a little bit
simple, however, I got this message:
dists <- osrmTable(loc = muns13, measure = "duration")
The OSRM server returned an error:
Error: The public OSRM API does not allow results with a number of
durations
higher than 10000. Ask for fewer durations or use your own server and set
its
--max-table-size option.
My sample size is 2,457
Were you asking for the whole nx(n-1)/2 set of durations in one run? You
see that the API limits the number of interactions (possibly by time and
by unique IP number). So you need to reduce the number of queries. If you
are going to impose a distance threshold anyway, you can do that using the
Great Circle (not Euclidean) distances between your geographical
coordinates and dnearneigh(), and step through the nb list object with
src= being the data frame of the observation coordinates, and dest= the
data frame of the neighbours' coordinates.
library(sf)
nc <- st_read(system.file("shapes/sids.shp", package="spData")[1],
quiet=TRUE)
st_crs(nc) <- "+proj=longlat +datum=NAD27"
nc1 <- st_transform(nc, 32019)
nc2 <- st_centroid(nc1, of_largest_polygon=TRUE)
nc3 <- st_transform(nc2, 4326)
crds <- st_coordinates(st_geometry(nc3))
df <- data.frame(id=nc3$FIPSNO, long=crds[,1], lat=crds[,2])
library(spdep)
nb <- dnearneigh(crds, 0, 50, longlat=TRUE)
library(osrm)
res <- vector(mode="list", length=nrow(df))
for (i in seq(along=res)) res[[i]] <- osrmTable(src=df[i,],
dst=df[nb[[i]],], measure = "duration")
res1 <- lapply(res, function(x) 10/x$duration)
lw <- nb2listw(nb, glist=res1, style="B")
gives general spatial weights based on 10/# minutes travel time between
county centroids (centroids calculated from projected coordinates), for
county centroids closer than 50 km measured by Great Circle.
In your case, you may need to split the for() loop into portions of
cumsum(card(nb)) of less than the limit. If durations are symmetric,
you could also halve the query count by taking only neighbour ids > i,
but you'd have to fold them back afterwards. You also wanted to categorise
the durations into 0,1, which you could do with lapply() instead of using
inverse durations.
Hope this helps,
Roger
El vie., 21 de jun. de 2019 a la(s) 02:53, Andres Diaz Loaiza (
madiazl at gmail.com) escribi?:
Dear Rolando,
The advantage of using Open Street Maps engine is that you can give the
travel option. This means you can select whether are you traveling by
car or walking. The previous approach didn't consider this topic. For
you should have added a vector layer depending on your position of the
street you can take (or not). Open Street Maps project allow you two
options: a service in which you give your current position, the position
you want to reach and your transport method (giving you back the fastest
route). Or the option to download the engine/algorithm compile by
(if I am not wrong is made in C or python) and then you can make your
calculation at your own computer. For the first option, the package
an interface in which send a request to the OSM web page and wait for an
answer. With this method, you can send a couple of request at the same
but no to many (you should read the manual for this). Of course, also
depend on whether the OSM server is down or not (or busy).
I have to say that I used some years ago this app and nowadays I know
for some cities OSM has more streets reported than the same google maps.
Also is an open project and they let you download their data for free,
contrary to what google maps do.
All the best,
Andres
El vie., 21 jun. 2019 a las 4:30, Adrian Baddeley (<
adrian.baddeley at curtin.edu.au>) escribi?:
Rather than converting an object of class 'SpatialLines' or
'SpatialLinesDataFrame' to the spatstat class 'psp' and then
to the spatstat class 'linnet', it is safer and more efficient to
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