Skip to content

Commit 9219db3

Browse files
author
Michael Stepner
committed
Merge branch 'release/v0.70beta3'
2 parents 200ccbe + 2f52ef7 commit 9219db3

13 files changed

Lines changed: 393 additions & 87 deletions
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
*! 6feb2014, Michael Stepner, michaelstepner@gmail.com
1+
*! 26jul2014, Michael Stepner, stepner@mit.edu
22

33
program define _maptile_county1990
44
syntax , [ geofolder(string) ///
55
mergedatabase ///
66
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
77
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
8-
stateoutline(string) ///
8+
/* Geography-specific options */ ///
9+
stateoutline(string) ///
910
]
1011

1112
if ("`mergedatabase'"!="") {
@@ -19,7 +20,8 @@ program define _maptile_county1990
1920
cap confirm file `"`geofolder'/state_coords_clean.dta"'
2021
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(`stateoutline' ...))
2122
else if (_rc==601) {
22-
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
di as error `"stateoutline() requires the {it:state} geography to be installed"'
24+
di as error `"--> state_coords_clean.dta must be present in the geofolder"'
2325
exit 198
2426
}
2527
else {
@@ -29,7 +31,8 @@ program define _maptile_county1990
2931
}
3032

3133
spmap `var' using `"`geofolder'/county1990_coords_clean"' `map_restriction', id(id) ///
32-
`legopt' legend(pos(5) size(*1.8)) ///
34+
`legopt' ///
35+
legend(pos(5) size(*1.8)) ///
3336
clmethod(custom) ///
3437
clbreaks(`min' `clbreaks' `max') ///
3538
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
@@ -39,18 +42,27 @@ program define _maptile_county1990
3942
`spopt'
4043

4144
* Save graph
42-
if `"`savegraph'"'!="" {
43-
* check file extension using a regular expression
44-
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45-
46-
* deal with different filetypes appropriately
47-
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48-
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49-
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50-
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51-
else graph export `"`savegraph'"', `replace'
52-
}
45+
if (`"`savegraph'"'!="") __savegraph_maptile, savegraph(`savegraph') resolution(`resolution') `replace'
5346

5447
}
5548

5649
end
50+
51+
* Save map to file
52+
cap program drop __savegraph_maptile
53+
program define __savegraph_maptile
54+
55+
syntax, savegraph(string) resolution(string) [replace]
56+
57+
* check file extension using a regular expression
58+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
59+
60+
* deal with different filetypes appropriately
61+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
62+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
63+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
64+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
65+
else graph export `"`savegraph'"', `replace'
66+
67+
end
68+

map_shapefiles/cz_maptile.ado

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
*! 6feb2014, Michael Stepner, michaelstepner@gmail.com
1+
*! 26jul2014, Michael Stepner, stepner@mit.edu
22

33
program define _maptile_cz
44
syntax , [ geofolder(string) ///
55
mergedatabase ///
66
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
77
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
8-
stateoutline(string) ///
8+
/* Geography-specific options */ ///
9+
stateoutline(string) ///
910
]
1011

1112
if ("`mergedatabase'"!="") {
@@ -19,7 +20,8 @@ program define _maptile_cz
1920
cap confirm file `"`geofolder'/state_coords_clean.dta"'
2021
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(`stateoutline' ...))
2122
else if (_rc==601) {
22-
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
di as error `"stateoutline() requires the {it:state} geography to be installed"'
24+
di as error `"--> state_coords_clean.dta must be present in the geofolder"'
2325
exit 198
2426
}
2527
else {
@@ -29,7 +31,8 @@ program define _maptile_cz
2931
}
3032

3133
spmap `var' using `"`geofolder'/cz_coords_clean"' `map_restriction', id(id) ///
32-
`legopt' legend(pos(5) size(*1.8)) ///
34+
`legopt' ///
35+
legend(pos(5) size(*1.8)) ///
3336
clmethod(custom) ///
3437
clbreaks(`min' `clbreaks' `max') ///
3538
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
@@ -39,18 +42,27 @@ program define _maptile_cz
3942
`spopt'
4043

4144
* Save graph
42-
if `"`savegraph'"'!="" {
43-
* check file extension using a regular expression
44-
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45-
46-
* deal with different filetypes appropriately
47-
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48-
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49-
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50-
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51-
else graph export `"`savegraph'"', `replace'
52-
}
45+
if (`"`savegraph'"'!="") __savegraph_maptile, savegraph(`savegraph') resolution(`resolution') `replace'
5346

5447
}
5548

5649
end
50+
51+
* Save map to file
52+
cap program drop __savegraph_maptile
53+
program define __savegraph_maptile
54+
55+
syntax, savegraph(string) resolution(string) [replace]
56+
57+
* check file extension using a regular expression
58+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
59+
60+
* deal with different filetypes appropriately
61+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
62+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
63+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
64+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
65+
else graph export `"`savegraph'"', `replace'
66+
67+
end
68+

map_shapefiles/demo_maptile.ado

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
*! 26jul2014, Michael Stepner, stepner@mit.edu
2+
3+
/*XX update the date above. change the author and e-mail address to be your own. */
4+
/*XX choose a name for your new geography and change the name of this ado-file to be: geoname_maptile.ado */
5+
6+
program define _maptile_demo /*XX change "demo" to your chosen geoname */
7+
syntax , [ geofolder(string) ///
8+
mergedatabase ///
9+
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
10+
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
11+
/* Geography-specific options */ ///
12+
/*XX you can add new options specific to your geography here (or delete XXexampleoption).
13+
when a user includes options in their maptile command that aren't mentioned
14+
in the maptile help file, they are passed to this program. */ ///
15+
XXexampleoption(string) ///
16+
]
17+
18+
if ("`mergedatabase'"!="") {
19+
merge 1:m geoid /*XX change geoid to the geographic ID variable, ex: province*/ using `"`geofolder'/geoname_database.dta"', nogen /*XX change "geoname_database.dta" to the name of your shapefile database file*/
20+
exit
21+
}
22+
23+
if ("`map'"!="") {
24+
25+
spmap `var' using `"`geofolder'/geoname_coords.dta"' `map_restriction', id(id) /// /*XX change "geoname_coords.dta" to the name of your shapefile coordinates file*/
26+
`legopt' ///
27+
legend(pos(5) size(*1.8)) /// /*XX change the default placement and size of the legend as appropriate for your map*/
28+
clmethod(custom) ///
29+
clbreaks(`min' `clbreaks' `max') ///
30+
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
31+
oc(black ...) ndo(black) ///
32+
os(vthin ...) nds(vthin) ///
33+
`spopt'
34+
35+
* Save graph
36+
if (`"`savegraph'"'!="") __savegraph_maptile, savegraph(`savegraph') resolution(`resolution') `replace'
37+
38+
}
39+
40+
end
41+
42+
* Save map to file
43+
cap program drop __savegraph_maptile
44+
program define __savegraph_maptile
45+
46+
syntax, savegraph(string) resolution(string) [replace]
47+
48+
* check file extension using a regular expression
49+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
50+
51+
* deal with different filetypes appropriately
52+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
53+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
54+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
55+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
56+
else graph export `"`savegraph'"', `replace'
57+
58+
end
59+

map_shapefiles/demo_maptile.smcl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{smcl}
2+
3+
{pstd}
4+
{hi:maptile {hline 2} Geography: county1990}
5+
6+
7+
{marker description}{...}
8+
{title:Description}
9+
10+
{pstd}
11+
{hi:county1990} generates a map of United States counties using 1990 boundaries.
12+
13+
{pstd}It displays Alaska and Hawaii rescaled and moved to the bottom left of the map, below the continental US, for ease of viewing.
14+
15+
16+
{marker idvar}{...}
17+
{title:Geographic ID variable}
18+
19+
{pstd}
20+
{hi:county} {hline 2} FIPS county codes
21+
22+
23+
{marker geooptions}{...}
24+
{title:Geography-Specific Options}
25+
26+
{synoptset 32 tabbed}{...}
27+
{synopt :{opth stateoutline(linewidthstyle)}}overlays the map with a (potentially thicker) line on state boundaries{p_end}
28+
29+
30+
{marker author}{...}
31+
{title:Author}
32+
33+
{pstd}Michael Stepner{p_end}
34+
{pstd}stepner@mit.edu{p_end}

map_shapefiles/state_maptile.ado

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
*! 6feb2014, Michael Stepner, michaelstepner@gmail.com
1+
*! 26jul2014, Michael Stepner, stepner@mit.edu
22

33
program define _maptile_state
44
syntax , [ geofolder(string) ///
55
mergedatabase ///
66
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
77
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
8+
/* Geography-specific options */ ///
89
geoid(varname) ///
910
]
1011

@@ -22,7 +23,8 @@ program define _maptile_state
2223
if ("`map'"!="") {
2324

2425
spmap `var' using `"`geofolder'/state_coords_clean"' `map_restriction', id(id) ///
25-
`legopt' legend(pos(5) size(*1.8)) ///
26+
`legopt' ///
27+
legend(pos(5) size(*1.8)) ///
2628
clmethod(custom) ///
2729
clbreaks(`min' `clbreaks' `max') ///
2830
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
@@ -31,18 +33,27 @@ program define _maptile_state
3133
`spopt'
3234

3335
* Save graph
34-
if `"`savegraph'"'!="" {
35-
* check file extension using a regular expression
36-
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
37-
38-
* deal with different filetypes appropriately
39-
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
40-
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
41-
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
42-
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
43-
else graph export `"`savegraph'"', `replace'
44-
}
36+
if (`"`savegraph'"'!="") __savegraph_maptile, savegraph(`savegraph') resolution(`resolution') `replace'
4537

4638
}
4739

4840
end
41+
42+
* Save map to file
43+
cap program drop __savegraph_maptile
44+
program define __savegraph_maptile
45+
46+
syntax, savegraph(string) resolution(string) [replace]
47+
48+
* check file extension using a regular expression
49+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
50+
51+
* deal with different filetypes appropriately
52+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
53+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
54+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
55+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
56+
else graph export `"`savegraph'"', `replace'
57+
58+
end
59+

map_shapefiles/zip3_maptile.ado

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
*! 6feb2014, Michael Stepner, michaelstepner@gmail.com
1+
*! 26jul2014, Michael Stepner, stepner@mit.edu
22

33
program define _maptile_zip3
44
syntax , [ geofolder(string) ///
55
mergedatabase ///
66
map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) ///
77
savegraph(string) replace resolution(string) map_restriction(string) spopt(string) ///
8-
stateoutline(string) ///
8+
/* Geography-specific options */ ///
9+
stateoutline(string) ///
910
]
1011

1112
if ("`mergedatabase'"!="") {
@@ -19,7 +20,8 @@ program define _maptile_zip3
1920
cap confirm file `"`geofolder'/state_coords_clean.dta"'
2021
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(`stateoutline' ...))
2122
else if (_rc==601) {
22-
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
di as error `"stateoutline() requires the {it:state} geography to be installed"'
24+
di as error `"--> state_coords_clean.dta must be present in the geofolder"'
2325
exit 198
2426
}
2527
else {
@@ -29,7 +31,8 @@ program define _maptile_zip3
2931
}
3032

3133
spmap `var' using `"`geofolder'/zip3_coords_clean"' `map_restriction', id(id) ///
32-
`legopt' legend(pos(5) size(*1.8)) ///
34+
`legopt' ///
35+
legend(pos(5) size(*1.8)) ///
3336
clmethod(custom) ///
3437
clbreaks(`min' `clbreaks' `max') ///
3538
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
@@ -39,18 +42,27 @@ program define _maptile_zip3
3942
`spopt'
4043

4144
* Save graph
42-
if `"`savegraph'"'!="" {
43-
* check file extension using a regular expression
44-
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45-
46-
* deal with different filetypes appropriately
47-
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48-
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49-
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50-
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51-
else graph export `"`savegraph'"', `replace'
52-
}
45+
if (`"`savegraph'"'!="") __savegraph_maptile, savegraph(`savegraph') resolution(`resolution') `replace'
5346

5447
}
5548

5649
end
50+
51+
* Save map to file
52+
cap program drop __savegraph_maptile
53+
program define __savegraph_maptile
54+
55+
syntax, savegraph(string) resolution(string) [replace]
56+
57+
* check file extension using a regular expression
58+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
59+
60+
* deal with different filetypes appropriately
61+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
62+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
63+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
64+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
65+
else graph export `"`savegraph'"', `replace'
66+
67+
end
68+

0 commit comments

Comments
 (0)