Giter VIP home page Giter VIP logo

roadcolors's Introduction

RoadColors

United States: Plot roads in a US city, coloring each by its designation (e.g. Street, Road, Avenue)

Before you get started, you’ll need to get a few things prepared:

  1. Find the lat/long point you’d like to be at the center of your map
  2. Identify the GEOIDs of counties that are within 15 miles of this point. This site is very helpful: https://census.missouri.edu/geocodes/
  3. Download roads shapefiles for the counties in step 2: ftp://ftp2.census.gov/geo/tiger/TIGER2018/ROADS/
  4. Download feature names shapefiles for the counties in step 2: https://www2.census.gov/geo/tiger/TIGER2018/FEATNAMES/

This code isn't as well commented as Canada or Worldwide, so you might want to start with either of those first.

Canada: Plot roads in a Canadian city, coloring each by its designation

Worldwide: Plot roads in any worldwide city using OpenStreetMap data. It derives road designations from the road name. I only wrote this to work for countries that use English or Romance languages--it doesn't work for languages like German (which mashes the road designation into the road name with no spaces) or languages that don't use the Latin alphabet.

roadcolors's People

Contributors

erdavis1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

roadcolors's Issues

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

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.

Error with read_sf(".",filename)

Hi,
I tried following your code but am getting the following issue when i try to read_sf(".",filename):

Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : 
  zero-length inputs cannot be mixed with those of non-zero length

I have the following filed downloaded in the wd:

gis_osm_roads_free_1.cpg
gis_osm_roads_free_1.dbf
gis_osm_roads_free_1.prj
gis_osm_roads_free_1.shp
gis_osm_roads_free_1.shx

Obviously, filname is set to "gis_osm_roads_free_1"
Any idea why I'm getting that error?
Thanks in advance!

Easy to use web application?

I haven't looked into specifically how this is working but I absolutely love it.

I am wondering if it is possible to create an easy to use web application for those that aren't developers to select a city and generate the image for them? I'm not sure how much of this is purely manual and can't be automated though.

I am happy to tackle this in the future (maybe a port to JavaScript or use of web assembly) but just opening to share/discuss ideas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.