Showing posts with label Fusion Tables. Show all posts
Showing posts with label Fusion Tables. Show all posts

Wednesday, March 11, 2015

Google Fusion Tables choropleth map

Data Visualization, Spring 2015
(A bit of a work in progress …)


Our goal is to make a choropleth map much like this one below, based on U.S. Census Bureau data, which you can then embed in a blog post or web page.


gft-finishedmap.png


First, you need your Census Table data source. The spreadsheet needs to be well formatted with a single header row and no extra cruft at the bottom of the file. For this example, we’ll use some Percent Civilian Unemployed XLS from the 2013 1-Year ACS, table DP03. Download that Excel spreadsheet to your computer.


You will need a Google Drive account that is NOT connected to UT-Austin. They don't allow use of the Fusion Tables app.

Upload your data

  • In drive, click on New, go down to More and then choose Google Fusion Tables. If you’ve never done this before, you will first have to click the “Connect more apps” link there, search for “Fusion Tables” and connect before trying again.


newgft.png


  • Next, you will browse to the file you are uploading. You can use an Excel spreadsheet, delimited text file, or even a Google Spreadsheet link. For this example, we’ll click Choose File and find our file ACS_13_1YR_DP03.xlsx, and then click next.
gft-choosefile.png


  • Next, you will get a little preview of your data. Click Next.


gft-inserttable.png


  • Your file should now be uploaded and your should see your data like below:


gft-thedata.png


Finding your data again

That will take you to a list of all your tables and allow you to search for public tables. It is not an easy place to find by searching and clicking around.


Find your geography

When you upload data, GFT will sometimes sniff out that one of your columns is a city, country or other geography and highlight it in yellow. It might even create a map on another tab. For this lesson, however, we want to merge our data to a specific shapefile of all the counties in Texas, and it is already available as a public file in Fusion Tables.


There are many public shapefiles saved into Fusion Tables, and you can search for them. The one we want for this exercise is named Texas County Shapefile (utdataviz). Click on that link to open it. (To save a new shapefile to GFT, see “Uploading shapefiles” below.)

The merge overview

Before go further, let’s outline all the steps to merge files, then we’ll go over them in detail:
  • Have both your data file and your shapefile open in Fusion Tables
  • Decide if you want all your date, or all your shapes, and then start with that file.
  • Merge in your new file, creating the new combined file.
  • Style your features and info windows.
  • Publish and then share or embed as necessary.

Choosing the correct file to start with

Sometimes you don’t have data for every feature in your shapefile. In our example, we have a table of 53 counties of data, but there are 254 counties in the state. In other words, we don’t have every county. (This is a common occurrence when using ACS data. The other counties apparently didn’t have a sample size large enough to be viable for inclusion.) So we have to decide: Do we want to start with all our data and then combine the just to the shapes that have a match? Or do we want to start with all our counties, and pull in just the data that have matches.


What’s the difference? If we start with our data, the missing counties will be absent. If we start with our counties, we’ll have the shape for every county, but the those missing data will show in the default red color. The answer depends on your goal.


For this lesson, we’ll start with the data of the ACS_13_1YR_DP03 table.


Merging

Go ahead and open both your ACS_13_1YR_DP03 data file (Here is my copy) and your Texas County Shapefile in seperate tabs. Compare the two and find the key that is common to both. The column Id2 in the data file matches with column GEOID10 in the shapefile. Connect these fields, and you have a merge.


From your data file, go under File to Merge and you’ll get this window:


gtf-mergeprompt.png


You can search for the table you need, or since you followed the directions above, you already have it open so you can copy and paste the url in the web address field at the bottom.


gft-matchcolumns.png


You’ll notice the numbers themselves don’t actually match across the files in this window … it is just showing you a preview of what some of those cells look like so you can see if they are similar. The will match once you hit Next … which you should do now.


gtf-savemergedcols.png


Here have a chance to include or not include particular columns that may not be of interest in this merge. Click Merge to complete it.


gft-newmergedfile.png


This is a good time to note that you will be creating a NEW file based on these other two, and that they are all linked together. Changes made to the original data or shape files will be transferred/reflected in this merged combination. (I need to check on this behavior.)

The new merged table

Now you have a new Google Fusion table, and there has been a tab added called Map of Geometry. It shows only the counties that you have in your data. Now we’ll get to color the shading of the shapes, and choose what is in the pop-up.


gft-newmergedmap.png


Change feature styles

Click on the “Change feature styles” button and you’ll get a window like this:


gft-changestyles.png


We are filling the polygons based from a “bucket” of the data, in our case using the percent unemployed in the civilian labor force.
  • Choose how many buckets you want.
  • Choose the field to pull from
  • Change the values and colors to make sense.
    • Usually I can click on “use this range” to split the buckets evenly, but in this case GFT wouldn’t do it. One of the reasons I’ve quit using it much.


Also note in the window Legend > Automatic legend. You can go there and choose to “Show polygon fill legend.” There isn’t any customization beyond the name, unfortunately.

Adjust your info windows

Click on the “Change infor window” and you’ll have the option of choosing which fields to show in the window:
gft-changeinfowindow.png


But if you then click on the Custom link, you can use some basic HTML to change this info window around. (I’ve put in images, tables and Google Charts into these windows.) In this case, we’ll just clean up the field names:


gft-changeinfocustom.png

Publish your mapgft-publish.png

  • Go to the share button at top right and change the visibility to either “Public on the web” or “Anyone with the link” can View the worksheet.
  • I renamed my “Map of geography” field to “Unemployment” by clicking on the menu and choosing rename. Then to publish your map, but under that same dropdown to Publish.
  • You then get a screen where you can get a link to share your project, or embed code put your blog on a website or blog.


gft-embed.png
There are many options there to use, but here are some hints:
  • If you send someone a link to you map, use this link on this Publish page from the map, not the url to the table. The public presentation is nicer than looking at the table view.
  • If you are going to embed, look at the width and height. iframe should work on most sites.


Some hints about saving data from American Factfinder

Google Fusion Tables can be picky about non-numbers being in number fields, so you might follow these steps when downloading Census data.
  • Find the table you want click on it so you are at the Table View and can see examples of your data.
  • Click on the download button. When you get the pop-up, choose to save a CSV file, with “Data and annotations in separate files.”
  • You’ll use the file that ends in “.csv” that does NOT have “_ann” in the name.
  • Clean up your data so you have one header row that you can read and understand. Make sure you keep the id numbers so you can match to a shapefile later.
  • If you end up saving the data as a spreadsheet, and adding more sheets to it, just make sure that the data you want to load is on the first sheet in the Workbook.


Uploading shapefiles

Google Fusion Tables does not take the most common .shp file format that you get from ArcGIS. It instead uses the .kml files (Keyhole Markup Files). More and more sites supply a .kml, too, but you might have to convert many of your .shp file to.kml. There are several ways:
  • We’ll learn to do this with free QGIS later in the semester.
  • You can upload to shpescape.com, which is also free, but often backed up.
  • There are some command-line tools ogr2ogr, but you have to know what your are doing both with shapefiles and the command-line.


Other useful Google Fusion Table shapefiles already uploaded:

Wednesday, January 29, 2014

How to build a Google Fusion Tables map

These are the basic steps we talked about in class today for building a Google Fusion Tables map. There are lots of nuances and such, but this is just the basic stuff. There are four steps: Upload, set features styles, set info window and publish.

  • Start with a good data set (we plotted points using this Dangerous Dogs list). While you could start with data that has a standard address, Google may or may not do a good jog geocoding that data. It's best if you have good Latitude and Longitude for each record. You can have a separate column each for Latitude and Longitude, or put them in the same column with a comma between them.
    • Texas A&M has a free Geocoding service that is wonderful. Once it codes everything, it also tells you how close it got on the address. Watch out for anything that used ZIP code, as that wasn't good and you'll need to manually fix them.
    • The Classic Google Maps makes geocoding a single address easy. Just find the place on the map, then right-click at that place and choose What's here, and it will put the Lat,Long in the search bar.
  • Log into Fusion Tables. You have to have a regular free Google account (in other words, not your UTMail account.)
    • Fusion Tables is connected to Google Drive. Go under Create and see if Fusion Tables is listed. If not, go to "Get more apps" and find it and add it.
    • That said, I suggest you bookmark this link that shows only FT tables. It's hard to find otherwise, and is useful in searching for public tables.
  • In Drive, go File > Create > Fusion Table (or choose New Table in the showtables list), which will take you to a window where you can upload your .xls file, or find one of your existing Google Spreadsheets.
  • Let the wizard guide you through the upload until you see the rows of data.
    • Note which columns are colored yellow, as FT thinks those are Locations. Sometimes you have to go under Edit > Change Columns and find the right Lat/Long column and change the type to "Location"
  • Most times, FT will recognize the location columns (Lat/Long) and create a tab called "Map of [whatever]". If you don't have Lat/Long or shapes (covered later), then it might try to geocode based on an address field it finds. It might also ask for help to make it better, like adding a city or state, etc.
  • Once you have the map and your points are plotted it's time to work on the feature styles and info window.
    • While looking at the map tab, look left for Feature Styles. This is where you can pick what kind of marker you want to use for points. You can use a single style, or use different markers based on a column that has numeric values. You can also set the marker by name using a column.
    • Click on Set Info Window to change what shows up in the pop-up window when you click on features in map. The Automatic sides lets you check on and off fields in the window. But if you want to edit what the label says, or add some simple HTML, then go to Custom and change the info window there.
  • Once all that is set, there are two steps to publish.
    • Click on the Share button at top right and set it to "View" for "Anyone with link can view" or for "Public. But DON'T USE THE URL THEY GIVE YOU THERE.
    • Instead, now choose the menu under the Map tab and go to Publish. There you can get a link, iframe or javascript embed. to use in your blog.

Using shapefiles for data

Later in class, we published using shapes. I'll go over how to get your own shape files in a future class, but in this case we merged some Census data with an existing shapefile that was already public in Fusion Tables. This is a real abbreviated version:
  • Upload your data file to Fusion Tables. Note the GEOID field, which as field unique to each county.
  • Go either to the advanced search in Drive or the Showtables page and search for Texas County Shapefile. If it doesn't come up, make sure you are searching for "public tables." Once you open that file, copy the URL into your clipboard.
  • Go back into your census data file, and go under File > Merge, and the put in the URL of the county shapefile and hit next.
  • Match up GEOID column in your data file to the GEOID10 file in the shapefile and merge them. You can keep all the columns for this demonstration.
  • A map tab was created for you upon the merge because you have a "geometry" column with all the shape information.
  • Now you can use the Set Feature Style, and set the ploygon fills to color by a bucket on the Median Age field. You can also set up an Automatic Legend there.
  • Set up your Info Window with the important information, publish your map like you did above and BAM!, you are done.
Easy sneazy.

Now, here is the dirty little secret. The Fusion Table part is the easy part. It's getting the data formatted the way you want it before you import it that is the trick. You have to watch things like:

  • ID numbers that start with 0. Those fields have to be set as text fields in Excel, or you'll drop the leading zeros. Zip codes on the East Coast are bad. So are school codes.
  • Fields you have to merge on need to be identical. If you are merging by county name, you can't have La Salle County in one file and LaSalle County in another.
  • Fusion tables takes .kml for shapefiles (keyhole markup language), but most government supply in the multi-file .shp format. You can convert them at shpescape.com, or with QGIS, which will learn later in the course.

Saturday, March 30, 2013

Automatic legends in Google Fusion Tables

Jean Yoo found a hidden gem in Google Fusion Tables that I wasn't aware of ... an Automatic Legend.  This will add a legend showing readers how your polygon fills (and I assume points) are styled.

I KNOW it was not there when I started using Fusion Tables. I wonder how long I've been staring at it.

To use it, go to your Change Map Styles window (the same place you define your buckets for the fill) and look at the bottom of the list. There is the Automatic Legend. You can set a title and you can decide in which corner you want the legend. Very handy.

Saturday, March 9, 2013

Publishing a Google Fusion Table Map


The assignment in class was to create a map using the Restaurant score data attached and the publish a blog post about your map.

Here are the very basic steps we talked about in class:

  • Start with a data set with addresses or better yet latitude and longitude.
  • Upload as Fusion Table to Google Drive (under Create > More > Fusion Table)
  • Fill out metadata (or do it later)
  • Check column information (Edit > Change columns)
  • Edit Info Window (Under Map tab)
  • Edit Map Styles (Under Map tab)
  • Share and embed or link to from your personal blog or portfolio. (If you don't have one, it's time to create one!
We've found that Wordpress doesn't take the iframe embed code. Students have taken screenshots of their maps and used that in their posts, and then linked to the published map.

Assets: