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.

Friday, December 16, 2011

12/16/2011 Using Orthophotos

I recently purchased a data set of parcels, streets, elevation contours, and building footprints (shapefiles) for Manchester-by-the-Sea, Mass. The 2,366 parcels look GREAT!

I want them to be transparent, with a nice basemap showing through. When I started with Esri’s “Bing Maps Hybrid”, however, the features were not good enough – their Eaglehead Rd (light gray) does not really line up with the parcels/streets:

The map made with the Terrain basemap looks fun:

I was hoping for some type of satellite view. The type of photo is called an orthophoto. Any (initial) photo is taken through a single lens, and therefore what you see is an image coming together at a single focal point. In an orthophoto, the image has been corrected (“orthorectified”) so that each point on the photo appears as if you were directly above it (“ortho-“ is a word element meaning “straight”). Orthophotos are available from MassGIS (the Office of Geographic Information) http://www.mass.gov/mgis/colororthos2005.htm

By consulting their index, I downloaded the appropriate 6 zip files in Mr Sid format (“Contrast Stretched” looks best). After unzipping them, I opened them in ArcMap – it looks great!

The size of the orthophotos (1 file = 9.76 megs and covers an area 2.5 miles x 2.5 miles) make this impracticable for areas larger than a town or two, but for that level of analysis/display, they are a very nice layer. And you can’t beat the cost.

Thursday, December 15, 2011

12/15/2011 Solutions – not Problems – With Projections

I felt that the maps in yesterday’s blog looked “squashed” and unrealistic (which, of course, is silly because only a handful of people have been far enough out in space to realistically see the Continental United States!).

“Projection” refers to how the three-dimensional data (our real-world coordinate system on our real-world globe) gets “projected” onto a flat piece of paper (or, in this case, a flat computer screen). I only worry about projections in two circumstances: 1) when the map “doesn’t look right” and 2) when historical boundary files do not line up with current boundary files.

First things first – the top map was created straight from the TIGER 2010 boundary files downloaded from the U.S. Census Bureau, and those files use GCS_North_American_1983 for their Geographic Coordinate System. The nice map below, however, was started by using a basemap from ArcGIS Online – the Light Gray Canvas, which has GCS_WGS_1984 for their Geographic Coordinate System.

By starting with a layer that has a nice projection (GCS_WGS_1984, in this case), ArcMap will overlay any additional geographic data files (after giving you an appropriate Warning):

The second case of projection problems happens when your data suppliers change their data-delivery projection. This happened to me in the mid-1990’s – prior to 1995, TIGER files used the North American Datum of 1927 (NAD27). Beginning in 1995 (and continuing through today), the TIGER files are referenced to the North American Datum of 1983 (NAD83); as a result, historical boundaries no longer lined up, and an entire set of Mapping Data had to be created anew (streets, Census Tract boundaries, Block Groups, Counties, Water, etc.).

In summary, if it looks good, you are fine. But if it looks bad, investigate your projection(s).

Wednesday, December 14, 2011

12/14/2011 NTSB recommended cell phone ban – How Safe is Your State?

Press Release: The NTSB voted unanimously today [December 13, 2011] for a nationwide ban on the nonemergency use of portable electronic devices (other than those designed to support the driving task) for all drivers.

This is certainly in response to the December 8, 2011 Press Release from the National Highway Traffic Safety Administration [NHTSA] stating that although highway deaths fell to 32,885 in 2010 (from 33,883 in 2009), 3,092 were in “distraction-affected crashes”.

The National Traffic Safety Board is an Independent United States Federal Government Agency charged with determining the probable cause of transportation accidents and promoting transportation safety.

I am wondering “how safe is Massachusetts” in regard to other states, at least as far as traffic accidents are concerned?

The NHTSA December 2011 issue of Traffic Safety Facts
link to the issue
lists Total Fatalities, 2009 and 2010, by State in Table 8.

The NHTSA works with the Fatality Analysis Reporting System (FARS) which provides yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.

The Research and Innovative Technology Administration (RITA) coordinates the U.S. Department of Transportation’s research programs, and has a division called the Bureau of Transportation Statistics (BTS) which publishes Number of U.S. Vehicles – total Highway registered vehicles were 254,212,610 in 2009.

The Federal Highway Administration (another part of the U.S. Department of Transportation) issues Table MV-1 each year (data for 2009 was issued January 2011), which lists, by State, Motor Vehicle Registrations – this means that instead of saying, in 2009, “the whole US had 33,883 highway deaths, distributed over 254,212,610 registered vehicles”, we can show the distribution spatially, state by state:


This first map shows count of deaths in each state – California, Texas, and Florida have the highest counts, followed by Georgia, New York, North Carolina, and Pennsylvania.

But I am not really a fan of “raw count” data – how does it relate to the number of vehicles registered in each state? The ratio2009 numbers are deaths per state/registrations per state, multiplied by 10,000, and they show California, Texas, and Florida as “not that dangerous”:


But now stay away from Arkansas, Colorado, and Mississippi!

One wonderful aspect of GIS/Computer Cartography is that you can display two (or more) sets of data at once. Working from the ratio2009 map, I added the raw count of highway deaths (as a graduated circle):

Is Massachusetts safe? With 340 highway deaths, 17 other states have fewer fatalities. But, with 5,420,020 vehicles registered, and 340 highway deaths, Massachusetts actually has the lowest deaths-per-registered-vehicle number in the United States!

Friday, December 9, 2011

12/9/2011 Traffic Cams, part 2

A quick follow-up on yesterday’s “Traffic Cams” post. I am trying to keep my code-writing “skills” buried, so I like clicking/double-clicking/cut-and-paste. I made a spreadsheet of the four traffic cams, but I needed their Latitude/Longitude coordinates (or so I thought).

To get the Latitude/Longitude, I open ArcGIS Online
ArcGIS Online
(note: you do not need to Sign In for this feature)

Click Map, then change the BasemapBasemap to Bing Maps Road. Zoom-in on the area north of Washington, DC. Click the Measure button, then click the Location tool.

Position your cursor over the intersection of I-495 and River Rd and Latitude/Longitude appear on the fly (work off the Camera Locations map identified in yesterday’s blog):

Fill in the spreadsheet for the four cameras, and copy-and-paste their urls:

Highlight the 20 cells and Save As TrafficCams.csv
In ArcGIS Online, close the Measure box. Click the Add button, then click Add Layer from File:

Go choose the csv file, then click the Import Layer button. The file is uploaded, and the program determines the locations from the Latitude/Longitude fields, and zooms appropriately:

Change the symbols by clicking the little arrow in the Contents and going down and selecting Change Symbols:

Then click the Change Symbol button. In the Change Symbol popup window, I like the camera in the People Places font:

Select it, click Apply, click Done, and click the X to close the Change Symbols section:

When you click on a camera, you get its info window:


The program is smart enough to include the url field – click on More info and the traffic cam appears in a new tab (if you right-click on More info, you can select Open link in new window, allowing you to have multiple windows open at the same time).

To Share this map, you must Save this map. To Save this map, you must Login/Sign In to your account. After Signing In, I can Share this map with Everyone:

Here is the url link to map
Additionally, I can Embed in Website or Make a Web Application – sounds like tomorrow’s blog!

Thursday, December 8, 2011

12/8/2011 Traffic Cams, part 1 (too much NCIS?)

Maybe I’ve been watching too much NCIS, but when I was looking at the Maryland Department of Transportation website for Coordinated Highways Action Response Team (their Interactive Mapping page)
link to Interactive Mapping page

I was fascinated to see a link to Live Traffic Cameras (what is the traffic – out there/rightnow!)

Ouch – what a boring list, and totally unhelpful for someone not familiar with the area. It says “To view cameras from a map interface please use Interactive Mapping.”

So I went back to the Interactive Mapping page, and clicked the Video/Camera tab:

Living in the Boston area, I have a natural desire to look at, but not be involved in, traffic. Zoom-in on the area north of Washington, DC, and select the Video Camera at I-495 & River Rd (MD 190)

Up pops a web-window with a live feed:

And, yes, that is a url
http://www.chart.state.md.us/video/video.asp?feed=c600bd2b00070075004d823633235daa
Click on it, and you get your own live-link to "I-495 - RIVER N"!
If you work off the Interactive Map, the single pop-up window gets replaced for each camera you click on. But if you grab each url, you can have multiple windows open!
I-495 W OF MD-97
I-495 AT BRADLEY BLVD
MD-185 - MD-410 N

At the Northeast Arc Users Group Conference in Saratoga Springs, NY a few weeks ago, I saw a presentation populating the info boxes on Google Maps with pictures and urls. Which means that I should be able to have these video feeds just appear on the maps! Sounds like a great project for tomorrow’s blog.