Skip to content

Instantly share code, notes, and snippets.

@ajdamico
Created January 20, 2013 03:28
Show Gist options
  • Save ajdamico/4576508 to your computer and use it in GitHub Desktop.
Save ajdamico/4576508 to your computer and use it in GitHub Desktop.
the puma of my childhood
# install mapping packages
install.packages( c( 'sp' , 'rgdal' ) )
# load necessary libraries
require(sp)
require(rgdal)
# create a temporary file and directory
tf <- tempfile() ; td <- tempdir()
# download the census state shape files
download.file(
"http://www.census.gov/geo/cob/bdy/st/st00shp/st24_d00_shp.zip" ,
tf ,
mode = 'wb'
)
# extract all files to the temporary directory
files <- unzip( tf , exdir = td )
# find the shape file
sf <- files[ grepl( 'shp' , files ) ]
# read the shape file
state <- readOGR( sf , "st24_d00" )
# download the maryland public use microdata area (puma) shape file
download.file(
"http://www.census.gov/geo/cob/bdy/pu/p500shp/p524_d00_shp.zip" ,
tf ,
mode = 'wb'
)
# extract all files to the temporary directory
files <- unzip( tf , exdir = td )
# find the shape file
sf <- files[ grepl( 'shp' , files ) ]
# read both shape files
puma <- readOGR( sf , "p524_d00" )
# plot the state boundary
plot( state )
# plot just one puma
plot( puma[ puma$PUMA5 == '01004' , ] , col = 'blue' , add = TRUE )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment