Wednesday, February 29, 2012

2/29/2012 Locations on Google Maps, Part 1

Ever since Google Maps started in 2005, users have wanted to display data on the maps. This data ranges from single points (locations of addresses or buildings that they want to visit), to multiple points (restaurants in an area, bank branches nearby), to polygons (color towns by recycling rate, shade census tracts by income level). I want to learn as much as I can along these areas – it looks like the Google Maps/Google Earth platforms are going to be with us for quite some time. Although there are a number of web sites that allow the display of various types of information, I want to “do it myself” and program my own maps. Google Maps makes this possible with free use of their Google Maps API (API stands for application programming interface, and allows a user to write their own code to generate Google Maps). As you can imagine, the code that was useful a few years ago is no longer valid (it has been “deprecated”, to user programmer-speak). The latest version is Google Maps JavaScript API V3 – and that is about as technical as I will get in this blog.

Five years ago I programmed Google Maps to display multiple points – I think these are branch locations for Bank of America from 2008

I had geocoded the addresses, and been able to include the longitude/latitude coordinates in a list:
function onLoad() {
if (GBrowserIsCompatible()) {
map = new GMap(document.getElementById("map"));
map.centerAndZoom(new GPoint(-71.0725,42.3308), 5);
addmarker(-71.13642,42.36013);
addmarker(-71.05263,42.35275);
addmarker(-71.03902,42.37128);
addmarker(-71.05625,42.35898);
addmarker(-71.14736,42.33747); …

Starting with a new account, and new code, I coded in 3 of the old points to see if it works – success!


I then coded in all 169 branches.


Unfortunately, I think these markers are unattractive. It used to be relatively easy to select another icon, but those days are gone. I created a smallreddot icon (in Paint Shop Pro) with a transparent background, and saved it to the Icons folder on my website. The Google Maps code to access that icon is
var image = 'http://dixonspatialconsulting.com/icons/smallreddot.png';
and then I have to specify
icon: image
for each position (I’m sure there are easier ways, but it is pretty brute force for now).

and then this is what it looks like when I use Bank of America’s logo:


Next Steps include
- get “real” Google Maps in this blog – the images above are only pictures
- generating smaller logos at larger geographies (I would like to see more differentiation between the logos above)
- work with Google Fusion Tables (as a database), allowing me to display FusionTablesLayer on a map. Queries can be made of the data, and rendering is performed on Google servers rather than within my user’ browsers, thereby increasing performance dramatically.

Friday, February 17, 2012

2/17/2012 Telephone Area Codes

I recently found myself dealing with Telephone Area Codes. “Area Codes” are levels of geography that have been defined by the telephone industry over the years, with new area codes being added (and old ones being adjusted) as a result of population and commercial growth. There are currently 281 Area Codes in the United States. They range from single-Area Code states [Alaska (907), District of Columbia (202), Delaware (302), Hawaii (808), Idaho (208), Maine (207), Montana (406), North Dakota (701), New Hampshire (603), Rhode Island (401), South Dakota (605), Vermont (802), and Wyoming (307)] to multiple-Area Code states [the largest being California (29), Florida (17), New York (14), and Texas (23)].

The purpose of dealing with Area Codes is that you would like to get insight into a customer (the demographics of the area associated with the customer), but the only data point you have is a telephone number. Although they began with a simple definition covering specific areas (New York City = 212, Chicago = 312, etc.) and evolved to nationwide seamless coverage, they have now become, in some regions, overlaid on top of each other (although Area Code 657 covers 10 cities in California, Area Code 714 also covers those 10 cities, plus an additional 64 cities). For those interested, Wikipedia has an excellent article on the North American Numbering Plan
http://en.wikipedia.org/wiki/North_American_Numbering_Plan

Note: although the Wikipedia article lists 323 Area Codes, it includes proposed Area Codes and overlays; I am using the USA Telephone Area Codes boundary file available from Esri (281 Area Codes):


And don’t get me started on Area Codes for cell phones! My understanding is that the area code is assigned at the location where the cell phone is purchased; but by their very nature, these are mobile devices. My only hope for “data integrity” (that the cell phone Area Code actually means a location) is that, in these economic times, less people are moving. It was reported in November 2011 that only 11.6% — 35 million people — changed residence from 2010 to 2011, the lowest rate since the Census Bureau began collecting the statistics in 1948. In the mid-1980s, more than 20% were moving each year.

Analysis

Analysis is relatively straightforward – identify the area you are interested in, and grab (if at the state-level), or roll-up, the demographic variables you want. Originally, I wanted to do something complicated, like California. But after getting my hands (very) dirty, I will focus instead on the 12 Area Codes in Connecticut, Massachusetts, and Rhode Island:


By definition, Area Codes 339, 351, 774, and 857 are overlays of 781, 978, 508, and 617, respectively, so demographics need to be calculated for 8 Area Codes. 401 is all of Rhode Island, so that is an “easy grab”.

Examining Boundary files, it is apparent that Area Codes in Connecticut and Massachusetts are defined by Census Subdivision (“Cities and Towns”), and not Counties. The County Subdivision files for TIGER2010 can be downloaded from the Census Bureau’s ftp site:
ftp://ftp2.census.gov/geo/tiger/TIGER2010/COUSUB/2010/

From the Census Bureau web site, download Report DP03 – Selected Economic Characteristics [2006-2010 American Community Survey 5-Year Estimates] for the County Subdivisions in Connecticut and Massachusetts. Of the 173 Census Subdivisions in Connecticut, 51 are in Area Code 203 (and the rest are in 860) (for the record, the 351 Massachusetts Subdivisions are distributed: 98 in Area Code 413, 112 in 508, 12 in 617, 50 in 781, and 79 in 978). There are dozens of variables that can be rolled-up, but the ones I like are

VC74
VC85
VC101
VC112
VC156
.
Count of Total Households
Median Household Income
Count of Total Families
Median Family Income
Percentage of Families and People whose Income in the past 12 months is Below the Poverty Level



State/
Area_Code
CT/203
CT/860
MA/413
MA/508
MA/617
MA/781
MA/978
RI/401

Total
Households
666,967
692,251
320,464
767,523
485,987
465,413
473,165
410,305
Median
Household
Income
$76,757
$67,850
$51,767
$67,416
$61,649
$79,943
$73,820
$54,902

Total
Families
450,477
461,176
200,102
518,507
245,397
311,787
324,795
285,572
Median
Family
Income
$95,507
$82,703
$66,018
$82,875
$77,900
$99,032
$90,383
$70,663
Percent
Below
Poverty
6.7%
6.2%
10.6%
6.4%
11.5%
5.1%
6.3%
8.4%


These numbers illustrate that there are very wide ranges in income levels and poverty levels between Area Codes, even here in relatively-homogeneous Southern New England. I look forward to completing this analysis for the rest of the United States.