walkerke / census-with-r-book

Source for Analyzing US Census Data: Methods, Maps, and Models in R by Kyle Walker, published with CRC Press
https://walker-data.com/census-r
Other
78 stars 27 forks source link

mb_matrix function not working #14

Open Luis-2030 opened 1 year ago

Luis-2030 commented 1 year ago

Hello

I am working with Ch. 7 in your book and I wanted to run the distance and proximity analysis you have in chapter 7.4. Specifically travel time.

I am bringing and csv file (destinations) and US Census block groups (centroids). When I run the mb_matrix function I get the following error:

image

Attached is the csv file for destinations.

I wonder if in the problem is in the geocoding process.

FamilyChildCareAndCentersAndPreschools.csv

I used tidygeocoder to geocode the destinations


childcare <- read.csv("D:/Googledrive/COE/FamilyChildCareAndCentersAndPreschools.csv") 

childcare$fulladdr <- paste(as.character(childcare$Street),
                            as.character(childcare$City),
                            as.character(childcare$State),
                            as.character(childcare$Zipcode))

geoCodechildcare <- geocode(childcare, address = 'fulladdr',
                            lat = latitude, long = longitude, method = "arcgis")

childcareSF <- st_as_sf(geoCodechildcare,
                        coords = c("longitude", "latitude"), na.fail = TRUE,
                        crs = 4326)

childcareSF <- st_transform(childcareSF, crs = 6501)

stearns_distances <- block_groups("MN", "Stearns", cb = TRUE)

st_crs(stearns_distances)

CRS.new <- st_crs("EPSG:6501")

stearns_6501 <- st_transform(stearns_distances, CRS.new)

library(mapboxapi)

# mb_access_token("pk............, install = TRUE)

# readRenviron("~/.Renviron")

times <- mb_matrix(stearns_6501, childcareSF)`
walkerke commented 1 year ago

You are running into this error, which is an open issue in the mapboxapi repo: https://github.com/walkerke/mapboxapi/issues/34. mapboxapi doesn't support many-to-many matrices of that size at the moment, so you'd need to split your childcare facilities into smaller chunks and iterate over the chunks. I have longer-term plans to fix this in the package.

Luis-2030 commented 1 year ago

Thank you for the explanation!