Building News Applications
COMM 177T/277T (2019)

D3 Mapping and Final Project Check-In

Day 18 ~ May 30, 2019

Overview

Today, we'll explore some key elements in mapping with D3. We'll touch on the foundational skills of acquiring and converting geospatial files to different formats, and then focus on the elements of building a choropleth map in D3.

In class today, we'll dissect a choropleth map of U.S. unemployment rates from the D3.js Cookbook.

us unemployment choropleth

For our class review of map code, please clone the repo and fire up a test server to display the map:

git clone [email protected]:NickQiZhu/d3-cookbook-v2.git
cd d3-cookbook-v2/
python -m http.server
# Or if above doesn't work, try
# python3 -m http.server

Next, go to http://localhost:8000/src/chapter12/choropleth.html

This map illustrates some basic techniques for building a choropleth map. Mapping (in D3 or otherwise) is a big topic, so we've included links below to resources that can help you keep learning.

We'll devote any remaining class time to hands-on work for the final project.

Acquiring geospatial data

Acquiring and converting geospatial data to a suitable format for use in D3 (or other mapping tools) is a critical skill.

There are many sources for geospatial files. Here's a list to get you started:

Check out the the Stanford Geospatial Center's Spatial Data Resources for more links.

Converting geospatial data

Once you've acquired data for a map, it's often necessary to convert the data to geojson or, better yet, topojson for use in a D3 map. The latter is a light-weight geospatial format that will improve the performance of the map visualization.

A popular command-line tool for converting geospatial data between formats is ogr2ogr, part of the gdal library.

For Mac users, here are the steps for installing gdal and converting a Census shapefile to geojson:

ogr2ogr -f GeoJSON -t_srs crs:84 sfblockgroups.geojson tl_2010_06075_bg10.shp

Mapping in D3

D3 shines in the area of mapping due to its use of underlying web technologies such as SVG. Mapping in D3 requires a grasp of SVG Path elements and transformations using Groups, as well as familiarity with general mapping concepts such as projections.

Below are some resources for D3 mapping: