Skip to content

Commit

Permalink
Merge branch 'release/0.70beta1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Stepner committed Feb 3, 2014
2 parents 88e77df + f79dce1 commit abe06a7
Show file tree
Hide file tree
Showing 19 changed files with 1,356 additions and 412 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
map_shapefiles/
map_shapefiles_creation_code/
raw_data/
map_shapefiles/*.dta
raw_data/
tests/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
maptile: simple mapping in Stata
--------------------------------

[See the project webpage for more information.](http://michaelstepner.com/maptile "maptile: a Stata program that makes mapping easy")
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
56 changes: 56 additions & 0 deletions map_shapefiles/county1990_maptile.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com

program define _maptile_county1990
syntax , [ geofolder(string) ///
mergedatabase ///
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
stateoutline ///
]

if ("`mergedatabase'"!="") {
merge 1:m county using `"`geofolder'/county1990_database_clean"', nogen update replace
exit
}

if ("`map'"!="") {

if ("`stateoutline'"!="") {
cap confirm file `"`geofolder'/state_coords_clean.dta"'
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
else if (_rc==601) {
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
exit 198
}
else {
error _rc
exit _rc
}
}

spmap `var' using `"`geofolder'/county1990_coords_clean"' `map_restriction', id(id) ///
`legopt' legend(pos(5) size(*1.8)) ///
clmethod(custom) ///
clbreaks(`min' `clbreaks' `max') ///
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
oc(black ...) ndo(black) ///
os(vvthin ...) nds(vvthin) ///
`polygon' ///
`spopt'

* Save graph
if `"`savegraph'"'!="" {
* check file extension using a regular expression
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)

* deal with different filetypes appropriately
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
else graph export `"`savegraph'"', `replace'
}

}

end
56 changes: 56 additions & 0 deletions map_shapefiles/cz_maptile.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com

program define _maptile_cz
syntax , [ geofolder(string) ///
mergedatabase ///
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
stateoutline ///
]

if ("`mergedatabase'"!="") {
merge 1:m cz using `"`geofolder'/cz_database_clean"', nogen
exit
}

if ("`map'"!="") {

if ("`stateoutline'"!="") {
cap confirm file `"`geofolder'/state_coords_clean.dta"'
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
else if (_rc==601) {
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
exit 198
}
else {
error _rc
exit _rc
}
}

spmap `var' using `"`geofolder'/cz_coords_clean"' `map_restriction', id(id) ///
`legopt' legend(pos(5) size(*1.8)) ///
clmethod(custom) ///
clbreaks(`min' `clbreaks' `max') ///
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
oc(black ...) ndo(black) ///
os(vvthin ...) nds(vvthin) ///
`polygon' ///
`spopt'

* Save graph
if `"`savegraph'"'!="" {
* check file extension using a regular expression
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)

* deal with different filetypes appropriately
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
else graph export `"`savegraph'"', `replace'
}

}

end
48 changes: 48 additions & 0 deletions map_shapefiles/state_maptile.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com

program define _maptile_state
syntax , [ geofolder(string) ///
mergedatabase ///
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
geoid(varname) ///
]

if ("`mergedatabase'"!="") {
if ("`geoid'"=="state" | "`geoid'"=="") merge 1:1 state using `"`geofolder'/state_database_clean"', nogen keepusing(state id)
else if ("`geoid'"=="statefips") merge 1:1 statefips using `"`geofolder'/state_database_clean"', nogen update replace
else if ("`geoid'"=="statename") merge 1:1 statename using `"`geofolder'/state_database_clean"', nogen update replace
else {
di as error "with geography(state), geoid() must be 'state', 'statefips', 'statename', or blank"
exit 198
}
exit
}

if ("`map'"!="") {

spmap `var' using `"`geofolder'/state_coords_clean"' `map_restriction', id(id) ///
`legopt' legend(pos(5) size(*1.8)) ///
clmethod(custom) ///
clbreaks(`min' `clbreaks' `max') ///
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
oc(black ...) ndo(black) ///
os(vthin ...) nds(vthin) ///
`spopt'

* Save graph
if `"`savegraph'"'!="" {
* check file extension using a regular expression
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)

* deal with different filetypes appropriately
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
else graph export `"`savegraph'"', `replace'
}

}

end
56 changes: 56 additions & 0 deletions map_shapefiles/zip3_maptile.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com

program define _maptile_zip3
syntax , [ geofolder(string) ///
mergedatabase ///
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
stateoutline ///
]

if ("`mergedatabase'"!="") {
merge 1:m zip3 using `"`geofolder'/zip3_database_clean"', nogen
exit
}

if ("`map'"!="") {

if ("`stateoutline'"!="") {
cap confirm file `"`geofolder'/state_coords_clean.dta"'
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
else if (_rc==601) {
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
exit 198
}
else {
error _rc
exit _rc
}
}

spmap `var' using `"`geofolder'/zip3_coords_clean"' `map_restriction', id(id) ///
`legopt' legend(pos(5) size(*1.8)) ///
clmethod(custom) ///
clbreaks(`min' `clbreaks' `max') ///
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
oc(black ...) ndo(black) ///
os(vvthin ...) nds(vvthin) ///
`polygon' ///
`spopt'

* Save graph
if `"`savegraph'"'!="" {
* check file extension using a regular expression
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)

* deal with different filetypes appropriately
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
else graph export `"`savegraph'"', `replace'
}

}

end
56 changes: 56 additions & 0 deletions map_shapefiles/zip5_maptile.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com

program define _maptile_zip5
syntax , [ geofolder(string) ///
mergedatabase ///
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
stateoutline ///
]

if ("`mergedatabase'"!="") {
merge 1:m zip5 using `"`geofolder'/zip5_database_clean"', nogen update replace
exit
}

if ("`map'"!="") {

if ("`stateoutline'"!="") {
cap confirm file `"`geofolder'/state_coords_clean.dta"'
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
else if (_rc==601) {
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
exit 198
}
else {
error _rc
exit _rc
}
}

spmap `var' using `"`geofolder'/zip5_coords_clean"' `map_restriction', id(id) ///
`legopt' legend(pos(5) size(*1.8)) ///
clmethod(custom) ///
clbreaks(`min' `clbreaks' `max') ///
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
oc(black ...) ndo(black) ///
os(vvthin ...) nds(vvthin) ///
`polygon' ///
`spopt'

* Save graph
if `"`savegraph'"'!="" {
* check file extension using a regular expression
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)

* deal with different filetypes appropriately
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
else graph export `"`savegraph'"', `replace'
}

}

end
40 changes: 40 additions & 0 deletions map_shapefiles_creation_code/generate_cz_shapefile.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
* generate_cz_shapefile.do: Merges 1990 County shapefile into a 1990 CZ shapefile

*** Version history:
* 2014-01-31, Michael Stepner
* 2013-07-14, Michael Stepner
* 2013-07-05, Michael Stepner* 2013-04-15, Shelby Lin/*******************************
** DEPENDENCIES **
- mergepoly.ado, installed from SSC by running: ssc install mergepoly
** INPUT FILES **
- cw_cty_czone.dta
Provided by David Dorn at http://www.cemfi.es/~dorn/data.htm -- file [E6]
- county1990_database_clean.dta & county1990_coords_clean.dta
Based on source file "co99_d90_shp.zip", provided by U.S. Census Bureau at http://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html
Generated by "import_county1990_shapefile.do"
** OUTPUT FILES **- cz_database_clean.dta- cz_coords_clean.dta*******************************/
global root "/Users/michael/Documents/git_repos/maptile"
global raw "$root/raw_data"
global out "$root/map_shapefiles"
global code "$root/map_shapefiles_creation_code"
set more off


*** Step 1: Use Dorn County -> CZ crosswalk to merge CZ variable onto county database
use "$raw/cw_cty_czone.dta", clear
rename cty_fips county
rename czone cz
keep county cz

merge 1:m county using "$out/county1990_database_clean", assert(3) nogen
compress


*** Step 2: Merge county polygons into CZs

mergepoly id using "$out/county1990_coords_clean", ///
coordinates("$out/cz_coords_clean.dta") ///
by(cz) replace
save "$out/cz_database_clean.dta", replace
Expand Down

0 comments on commit abe06a7

Please sign in to comment.