Skip to content

Instantly share code, notes, and snippets.

@tomschenkjr
Created January 10, 2016 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomschenkjr/4ee0f3d2d0558a9a4eb0 to your computer and use it in GitHub Desktop.
Save tomschenkjr/4ee0f3d2d0558a9a4eb0 to your computer and use it in GitHub Desktop.
A note on how to geocode using R, since I always forget
# A note on how to geocode using R, since I always forget
library(tigris) # also loads 'sp'
library(RSocrata)
# Obtain data
d <- read.socrata("https://data.cityofchicago.org/Education/Connect-Chicago-Locations/bmus-hp7e")
ccgeo <- tracts(state = '17', county = c('031'), cb = T) ## cb=T means smaller file
# Data organization
d$longitude <- as.numeric(d$longitude)
d$latitude <- as.numeric(d$latitude)
sp::coordinates(d) <- c("longitude","latitude")
d@proj4string <- ccgeo@proj4string
# Geocode
geo <- sp::over(d, ccgeo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment