Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: by can't contain join column LINEARID which is missing from LHS #3

Open
egoens opened this issue Oct 3, 2019 · 1 comment
Open

Comments

@egoens
Copy link

egoens commented Oct 3, 2019

I was able to run the Worldwide version, which is very cool, but the only road detection I am seeing on the map is the interstates:
image

So, I am attempting to run the UnitedStates version (after downloading all the necessary feature names and road files) and I am running into the following error:

➜  RoadColors git:(master) ✗ R -f UnitedStates.R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin18.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(sf)
Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 6.2.0
> library(foreign)
> library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.2.1     ✔ purrr   0.3.2
✔ tibble  2.1.3     ✔ dplyr   0.8.3
✔ tidyr   1.0.0     ✔ stringr 1.4.0
✔ readr   1.3.1     ✔ forcats 0.4.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
> library(lwgeom)
Linking to liblwgeom 2.5.0dev r16016, GEOS 3.7.2, PROJ 6.2.0
> 
> 
> options(stringsAsFactors = FALSE)
> 
> #pt <- data.frame(lat = YOURLATHERE, long = YOURLONHERE)
> #city <- 'CITYNAMEHERE'
> #geoid <-  c('GEOID1', 'GEOID2', 'GEOIDN')
> 
> pt <- data.frame(lat =  39.7794476, long = -86.412935)
> city <- 'Indianapolis'
> geoid <-  c('18097','18063','18011','18057','18059','18145','18081','18109')
> 
> #-------import road files.----------
> files <- list.files(path="./FeatNames", pattern="*.dbf", full.names=TRUE, recursive=FALSE) %>% as.data.frame
> names(files) <- c("path")
> files$GEOID <- substr(files$path, 21, 25)
> files <- subset(files, GEOID %in% geoid)
> 
> allroads <-NULL
> 
> #----------combine em all and add suffixes--------------
> for (i in 1:nrow(files)) {
+   #read in the feature names file, which has road suffixes in it
+   featname <- read.dbf(files$path[i],  as.is = TRUE)
+   featname$SUFTYPABRV[is.na(featname$SUFTYPABRV)] <- featname$PRETYPABRV[is.na(featname$SUFTYPABRV)]
+   featname <- featname %>% dplyr::select(LINEARID, SUFTYPABRV) %>% unique
+   
+   #read in the roads shapefile as a simple features dataframe
+   roads <- read_sf("./Roads", paste0("tl_2018_", files$GEOID[i], "_roads"))
+   roads$len <- st_length(roads)
+   
+   #join the two 
+   temp <- inner_join(roads, featname, by = "LINEARID") 
+   
+   #merge em all
+   if (i==1) {
+     allroads <- temp
+   }else {
+     allroads <- do.call(rbind, list(temp, allroads))
+   }
+ }
Error: `by` can't contain join column `LINEARID` which is missing from LHS
Backtrace:
     █
  1. ├─dplyr::inner_join(roads, featname, by = "LINEARID")
  2. ├─sf:::inner_join.sf(roads, featname, by = "LINEARID")
  3. │ └─sf:::sf_join(NextMethod(), attr(x, "sf_column"), suffix[1])
  4. │   └─sf_column %in% names(g)
  5. ├─base::NextMethod()
  6. └─dplyr:::inner_join.tbl_df(roads, featname, by = "LINEARID")
  7.   ├─dplyr::common_by(by, x, y)
  8.   └─dplyr:::common_by.character(by, x, y)
  9.     └─dplyr:::common_by.list(by, x, y)
 10.       └─dplyr:::bad_args(...)
 11.         └─dplyr:::glubort(fmt_args(args), ..., .envir = .envir)

I have the FeatNames and Roads folder in the same path as the UnitedStates file:

➜  RoadColors git:(master) ✗ lsa
total 64
drwxr-xr-x  13 egoens  staff   416B Oct  2 16:40 .
drwxr-xr-x@  6 egoens  staff   192B Oct  2 15:10 ..
-rw-r--r--@  1 egoens  staff   6.0K Oct  2 15:46 .DS_Store
drwxr-xr-x  12 egoens  staff   384B Oct  3 08:53 .git
-rw-r--r--   1 egoens  staff   3.2K Oct  2 14:14 Canada.R
drwxr-xr-x  42 egoens  staff   1.3K Oct  2 15:17 FeatNames
drwxr-xr-x   4 egoens  staff   128B Oct  2 15:11 Indianapolis
-rw-r--r--   1 egoens  staff   1.1K Oct  2 14:14 README.md
drwxr-xr-x  51 egoens  staff   1.6K Oct  2 15:17 Roads
-rw-r--r--   1 egoens  staff   5.1K Oct  2 15:37 UnitedStates.R
-rw-r--r--   1 egoens  staff   4.2K Oct  3 06:51 Worldwide.R

This is an amazing project and thanks for sharing. Any help would be appreciated and thanks again.

@erdavis1
Copy link
Owner

erdavis1 commented Oct 5, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants