Skip to content

Instantly share code, notes, and snippets.

@auremoser
Last active May 15, 2021 04:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auremoser/cedbafd367aabf8fe188 to your computer and use it in GitHub Desktop.
Save auremoser/cedbafd367aabf8fe188 to your computer and use it in GitHub Desktop.
Yale Workshop: Humanitarian Data

CartoDB Workshop -- Humanitarian Haiti Maps

Aurelia Moser, Map Scientist, CartoDB Workshop - Yale February 4, 2015

Find this document here: http://bit.ly/1At1cQQ | Gist Haiti Flag from wikipedia

Outline

  1. Introduction to CartoDB
    • Intro to the interface
    • Examples
    • Tour of the interface
  2. Mapping Workshop
    • Setting up accounts!
    • Data import
    • Choropleth, Category, Intensity Maps
    • Basic map styling
    • Column data types
    • Torque -- temporal maps
    • Sharing visualizations
  3. Dealing with Data
    • Getting Data
    • What is geospatial data?
    • Data representation in CartoDB (SQL schema)
    • Geocoding
    • SQL/PostGIS
  4. Carto.js
    • CartoJS: What it looks like (HTML/CSS/JS)
    • Examples!
  5. Odyssey.js
    • Brief Intro on authoring narratives with maps
    • Hands-on
  6. Wrap Up
    • Resources
    • Onward!

Later reference

You can find this document in my GitHub Account.

1. Intro to CartoDB!

Examples

  1. Illustreets
  2. Tweets about Beyonce Album Release
  3. Starwars Galaxy Map

Humanitarian Use Cases

  1. Demonstrations in Brazil
  2. Violence in Africa
  3. NGO Aid Map
<iframe src="http://team.cartodb.com/u/santiagoa/viz/bd69bca0-7449-11e4-88e4-0e018d66dc29/embed_map" width="600px" height="400px"></iframe>

Tour of the interface

Data Import

Basic Data Import Data import dialog Most major formats for storing data: Excel Spreadsheets, CSV files, Shapefiles, KML (Google Earth), etc. See complete list here.

  1. Import by URL! Super handy when in a workshop and you don't want to overwhelm the bandwidth
  2. Select file from your HD
  3. Common Data contains useful datasets for everyday use (admin regions, USGS earthquake data, ports and their locations, and many more)

Integration with Google Drive and Dropbox.

Twitter firehose access for Enterprise accounts.

<iframe src="http://srogers.cartodb.com/viz/81916204-c392-11e3-bcbf-0e230854a1cb/embed_map" width="600px" height="400px"></iframe>

Data tables in CartoDB

Schema or column names Column names

Filters & SQL

Filters Filters are a great way to explore your data. Besides filtering your data, they allow you to see histograms of the distributions, the number of unique entries, or a search box for columns that have a large number of text entries.

Types of visualizations

  • Simple -- most basic visualization
  • Cluster -- counts number of points within a certain binned region
  • Choropleth -- makes a histogram of your data and gives bins different colors depending on the color ramp chosen
  • Category -- color data based on unique category (works best for a handful of unique types)
  • Bubble -- size markers based on column values
  • Intensity -- colors by density
  • Density -- data aggregated by number of points within a hexagon
  • Torque -- temporal visualization of data

Check out visualization documentation for more.

Simple Map

The visualization style simple is the default visualization for all maps. Simple visualization

Styles available in the wizard Styling options

Marker Fill: change the size, color, and opacity of all markers Marker Stroke: change the width, color, and opacity of every marker's border Composite Operation: change the color of markers when they overlap Label Text: Text appearing by a marker (can be from columns)

Infowindows/hovers

Infowindow options

  • Select which column data appear in infowindow by toggling column on
  • Customize further by selecting

Change basemap

Select basemaps from different providers, use custom color, NASA data, MapBox tiles, etc. Basemap options

Choropleth

Choropleth maps show map elements colored according to where a value associated with the map element falls in a range. It's like a histogram where each bin is colored differently according to a color scale you pick. Notice the CartoCSS screenshot above.

Quantification is an option to pay attention to since it controls how the data is binned into different colors. Equal interval gives bins of equal size across the range, which means that outliers stand out. Quantile bins so that each quantile has approximately the same number of values.

CartoCSS basics

CartoCSS is the styling language for our maps.

CartoCSS screenshot

Legends

Can be easily customized Legend

You have the option of giving it a title, and changing the text for the colors. You can also change the colors manually, or, even better, change the color ramp back in the wizard. If you want to explore other color ramps, check out Color Brewer for some very well thought out color schemes.

Torque maps

CartoDB created a fully zoomable map that changes over time.

Some examples

  1. World Cup tweets saturate this map
  2. Tweets that mention sunrise map
  3. Animal migration patterns

Last few things

Navigating back to your tables or visualization

Click on the 90-degree arrow to get back to view your tables/visualizations go back to tables

Navigating in general

Navigation bar

Mapping

Let's make maps! Make sure you already have an account setup: https://cartodb.com/signup?plan=academy

Data Import

Import a new dataset by copying the link (not downloading) and pasting it into the import window in your CartoDB account:

USGS reported seismic activity (earthquakes) http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv

Simple Map

Challenge #1

Using the styles in simple, try to recreate the visualization below. It's similar to an intensity map that shows where earthquakes are occurring in largest numbers. Play with styles to your preference.

Styling options

Choropleth Map

More on quantification here.

Challenge #2

Make a choropleth map Next select choropleth from the Vizualization wizard. By default it will select depth. Select the mag column (which means magnitude or power of the earthquake).

Notice that there are lots of US-based earthquakes that are fairly weak -- so perhaps filtering for earthquakes above 3.0 will give a better visualization of our data.

hint: notice that a filter was used Choropleth map

Category Map

Challenge #3

Try to recreate this map using category. net is the column to categorize by...

Category challenge

Multilayer map

Three basic types of data appear on a map.

  • Point data -- like we saw for the earthquakes
  • Line data -- like flight paths, can be seen in this example
  • Polygon data -- like the shapes of states

Challenge #4 -- Create a multilayer visualization

Go back to your dashboard and click on Common Data. Find Administrative Regions, then click on USA States.

Or download Haiti's admin districts here.

After the data imports into your account, click on the large + on the panel on the right side of the page.

multilayer visualization

Select the earthquake dataset. It's default name on import is all_month. Then hit Add layer.

Add additional layer

Name your visualization something like "First multilayer visualization."

You can customize each layer just as you would customize a single layer.

Try to create a map that looks like this:

Multilayer map

Challenge #5 -- Create a basic torque map

Create a torque map and select the time column of the earthquake data

Multilayer example

Multilayer tool developed by The Daily Beast on Abortion Clinic Access.

##Working with Data Workshop

Data is messy

  • Comes in multiple formats
  • Sources uncertain
  • Contains errors
  • etc.

What is Geospatial Data?

Geospatial data is into that ids a geolocation and its characteristic features/frontiers, typically represented by points, lines, polygons, and/or complex geographic features.

Getting Data

Data sets we could use:

  1. Number of NGOs
  2. GDP Data for Haiti
  3. World Bank index data
  4. OECD Database of Econ Stats
  5. World Bank Indicators - Health

Data Representation in CartoDB (SQL schema)

The most basic SQL statement is:

{% highlight sql %} SELECT * FROM table_name {% endhighlight %}

The * means everything. This means that all rows and columns from the table are given back once the query is run.

A more detailed query is like this:

{% highlight sql %} SELECT name, height, age FROM class_list WHERE name = 'Aure' AND ( height > 1.2 OR height < 1.9 ) {% endhighlight %}

  1. SELECT is what you're requesting (required)
  2. FROM is where the data is located (required)
  3. WHERE is the filter on the data you're requesting (optional)
  4. GROUP BY and ORDER BY are optional additions, you can read more about aggregate/other functions below

Geocoding

####Consider the Geom There are two special columns in CartoDB:

  1. the_geom
  2. the_geom_webmercator

The first of these is in the units of standard latitude/longitude, while the second is a projection based on the original Mercator projection but optimized for the web.

If you want to run SQL commands and see your map update, make sure to SELECT the the_geom_webmercator because this is the column that's used for mapping--the other is more of a convenience column since most datasets use lat/long.

Example (if time)

  1. Go back to your tables view (by clicking on the little arrow in the upper lefthand corner of your browser window)
  2. import a new table called usa_counties into your account by pasting the following link into the import box: http://andye.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20usa_counties&filename=usa_counties&format=csv
  3. Rename the table to usa_counties by clicking on table name in the upper left-hand corner of your browser window, like the image below. Change table name

Pro tip: this is a call using our SQL API and is a great way to access your data. More at our SQL API page.

SQL/PostGIS

This is a SQL statement and you'll note it in your visualization tray as a way of querying and exploring your data with immediate visual output.

{% highlight sql %} SELECT * FROM earthquakes_all_month WHERE (mag >= 0.2975 AND mag < 3.17) {% highlight sql %}

You can enter queries, apply them, click on "create table from query" in the green field below the column names.

create table

You'll also note that your sql query box populated when you filtere; the two features serve similar functions serve similar functions, but the filters give you a nice gui for manipulating data, and require less-fluency in query langs.

CartoDB.js

CartoDB.js is our JavaScript API -- a way to make maps using JavaScript.

What it looks like

Three pieces to JavaScript maps

The example above use HTML, CSS, and JavaScript to make a map appear on a webpage.

Check out our Map Academy course on CartoDB.js if you want to learn more.

Extensibility

Use CartoDB.js with other JavaScript libraries to make powerful web map apps.

Check out Urban Reviewer.

If you take a look at the source code, there are a dozen libraries linked: Urban Reviewer source code

Examples!

Illustreets shows standard of living information across England to amazing detail. There are millions of data points, each can be interacted with to give graphs, summaries, etc.

Metrologic weather based transport recs based on the forecast.io api

Torque -- spatio-temporal maps

Requirements:

  1. Info in the_geom
  2. A time column (numeric or date type)

Topical Temporal Examples:

  1. Super Bowl 49
  2. Boston Crime
  3. Beyonce Album Release
<iframe src="http://team.cartodb.com/u/andrew/viz/1e90fefa-ab11-11e4-8b14-0e4fddd5de28/embed_map" width="600px" height="400px"></iframe>

Odyssey -- building narratives with your geospatial data

Home page

Huge revamp coming next week!

Example maps:

  1. Tour of Scotland
  2. HMS Beagle
  3. Al Jazeera: Israeli-Palestinian Conflict by Tweets
  4. The Sounds of 11M

Getting started!

Go to the Sandbox.

Brief tour of the interface. You follow Markdown Syntax to populate a post.

You can read more in the documentation.

We'll check out the inbrowser beta.

Resources

  1. Map Academy
  2. CartoDB Tutorials
  3. CartoDB Editor Documentation
  4. CartoDB APIs
  5. Community help on StackExchange
  6. CartoDB Map Gallery

My contact: aurelia@cartodb.com

If you make a map you're proud of or just want to say hello, connect with me @auremoser

Coat of Arms - Haiti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment