Tutorials

How to use CartoDB to visualize animal tracking data

This tutorial was written by Peter Desmet for LifeWatch INBO, a biodiversity observatory based in Belgium, and is released under the CC BY 4.0 license. It originally appeared on the LifeWatch INBO blog on September 1, 2015. Peter Desmet is LifeWatch INBO’s the team coordinator. Follow Peter on Twitter or on his website. Mapping novice? Storybench has a simpler CartoDB tutorial here.

CartoDB is a tool to explore, analyze and visualize geospatial data online. In my opinion, it’s like Gmail or GitHub: one of the best software tools ever. CartoDB is used in a wide area of domains and has great documentation, but in this tutorial I’ll focus on how it can be used for exploring and visualizing animal tracking data. Since we are tracking birds, I’ll use our open data of lesser black-backed gulls in the examples, but the methods can be applied to other animal tracking data as well (I hope). This tutorial is by no means meant to be exhaustive: it’s a step by step guide to get you started and hopefully inspire you to do cool things with your own data.

Note: If you want to follow along with this tutorial, you’ll at least need to do the actions in bold, all the rest in optional.

Create an account

Go to https://cartodb.com/signup to create an account, if you haven’t got one already. Free accounts allow you to upload 50MB of data, but keep in mind that all your data and maps will be public.

Login

  1. Once logged in, you see your private dashboard. This is where you (and only you) can upload data, create maps and manage your account.
  2.  

  3. CartoDB will display contextual help messages to get you to know the tool. For an overview, see the documentation on the CartoDB editor.
  4.  

  5. At the top, you can toggle between your Maps and Datasets.
  6.  

  7. You also have a public profile (https://user.cartodb.com/maps). All datasets you upload and maps you create, will be visible there.
  8.  

1280px-Larus-fuscus-taxbox

Upload data

For this tutorial, well use our open bird tracking data. To make it easier to follow along with a free CartoDB account, you can download a subset of the data (2.1MB), containing migration data for three gulls. If you want to know how that subset was created, here’s the SQL query I used.

sql1

  1. Download this zipped bird tracking csv file. Alternate link here.
  2.  

  3. Go to your datasets dashboard.
  4.  

  5. Upload the file by dragging it to your browser window. CartoDB recognizes multiple files formats.
  6.  

 

Data view

  1. CartoDB is powered by PostgreSQL & PostGIS and has created a database table from your file and done some automatic interpretation of the data types. Some additional columns have been created as well, such as cartodb_id.
  2.  

  3. Geospatial data are interpreted automatically in the_geom. This interpretation assumes the geodetic datum to be WGS84. the_geom supports points, lines and polygons, but only one type per dataset.
  4.  

  5. Click the arrow next to field name to manipulate columns, such as sorting, renaming, deleting or changing data types.
  6.  

  7. Most of the functionality is in the collapsed toolbar on the right, such as merging datasets, adding rows or columns, and filters.
  8.  

  9. Filters are great for exploring the data. Try out the filter for altitude.
     cartodb-filters
  10.  

  11. Filters are actually just SQL, a much more powerful language to select, aggregate or update your data. CartoDB supports all PostgreSQL and PostGIS SQL functions.
  12.  

  13. Click SQL in the toolbar and try this SQL to get some statistics about the scope of the dataset:sql2
  14.  

  15. From the Edit menu in the top right you can export any query you make, in multiple file formats. This is useful if you want to convert geospatial data from one file format to another, but don’t have the tools on your computer to do so.
  16.  

  17. Click Clear view to remove any applied SQL.
  18.  

Create your first map

  1. Click Visualize in the top right to create your first map.
  2.  

  3. Once created, click the title bird_tracking1 and rename it to My first map.
  4.  

  5. Click Map view.
  6.  

  7. You can change the background map by clicking Change basemap in the bottom right. Positron is a good default basemap, but there are many other options available and even more via Yours (including daily cloud cover maps from NASA). Note that for the Positron and Dark matter basemaps, city labels will be positioned on top of your data, making them more readable. ChoosePositron (labels below) to turn this off or Positron (lite) to have no labels at all.
  8.  

  9. Click Options in the bottom right to select the map interaction options you want to provide to the visitors of your map, such as Zoom controls or a Fullscreenbutton.
  10.  

  11. The map view also provides a toolbar on the right, where you’ll recognize the sameSQL and Filters features from the data view.
  12.  

  13. Click Wizards in the toolbar to see a plethora of visualization options. These are all explained in the CartoDB documentation.
  14.  

  15. Try Intensity with the following options to get a sense of the distribution of occurrences:
     
     cartodb-intensity
  16.  

  17. Try Choropleth with the following options to see the relative altitude distribution (see the documentation to learn more about the different quantification methods):
     
     cartodb-choropleth
  18.  

  19. Just like the filters are powered by SQL, the wizards are powered by CartoCSS, which you can use to fine-tune your map. Click CSS in the toolbar to discover how the quantification buckets (in this case Quantile) are defined:css3
  20.  

Create a map of migration speed

  1. We want to save our previous work and create another map. Click Edit > Duplicate map and name it Where does gull Nico rest?.
  2.  

  3. Add a WHERE clause to the SQL to only select gull Nico between specific dates:sql4
  4.  

  5. We want to visualize the travel speed of gull Nico. The best way to start is to create a Choropleth map, with the following options:cartodb-migration-speed-1
  6.  

  7. Most of the dots are red and the story does not come across yet. Let’s dive into the CSS to fine-tune the map. We basically set all dots to green, except where the speed is below 2m/s, which we show larger and in red:
     css5
  8.  

  9. Click Legends in the toolbar to manually set what to be shown in the legend (using template Custom):cartodb-migration-speed-2
  10.  

  11. Click a point and chose Select fields to create an info window.cartodb-migration-speed-3
  12.  

  13. Describe your map by clicking Edit metadata... in the top left.
  14.  

  15. Share your map by clicking Publish in the top right. The dialog box provides you with a link to the map or the code to embed it in a web page. CartoDB.js is for advanced use in apps.
  16.  

  17. Copy the link and paste it in a new browser tab to verify the info windows are working and the bounding box makes sense, i.e. are the interesting part of the data visible? Anything you update in your map (including zoom level and bounding box) will affect the public map (reload the page to see the changes).
  18.  

  19. Researchers often ask if they can export the map6. That’s not the goal of CartoDB (which is creating online, interactive maps), but you can create a screenshot by clicking Export Image in the top left. Unedited, it’s probably not fit for publication in a journal (e.g. the scale and indication of north are missing, which you could add manually), but luckily the default basemaps are already open data (required by some journals). You just need to credit OpenStreetMap.
  20.  

Create a map of tracks per month

  1. Duplicate your map and name it Tracks per month.
  2.  

  3. This time we want to string the occurrences together as lines: one line per individual (with the occurrences sorted by date), per month. This can be done in the SQL. See the PostgreSQL documentation for date functions. the_geom_webmercator is a geospatial field that is calculated by CartoDB in the background based on the_geomand is used for the actual display on the map. Since we’re defining a new geospatial field (i.e. a line), we have to explicitly include it.
     makeline
  4.  

  5. We want to display each month in a different color, so start with a Choropleth map, with the following options:cartodb-month-tracks-1
  6.  

  7. We will also include labels (start doing this in the Choropleth options), so you can still see which track belongs to which individual. Fine-tune the map in the CSS (note that I’ve changed the months to integers):
     css6cartodb
  8.  

  9. Update the legend:cartodb-month-tracks-2
  10.  

  11. To provide some more context, let’s annotate the map. In the top right, click Add Element > Add annotation item and indicate summer and winter locations. The position of an annotation element is linked to a location on the map (though placement can be a bit difficult) and you can define between which zoom levels to show it, to avoid cluttering:cartodb-month-tracks-3
  12.  

  13. Finally, update the description in Edit metadata... and publish your map.
  14.  

Create an animated map

  1. Duplicate your map and name it Migration in time.
  2.  

  3. This time, we’ll add a map on top of the previous one. Click + on the right hand side to add a new layer and choose the same table bird_tracking.
  4.  

  5. Apply the same time constraints in the SQL:
     
     sqlanimated
  6.  

  7. From the Wizards, choose Torque cat, with the following options. TheTime Column should always be your date.cartodb-torque-1
    cartodb-torque-2
  8.  

  9. The final CSS looks like this:
     cssanimtated
  10.  

  11. Update the legend, remove the bird_name labels from the other layer (they are no longer required) and publish your map.
  12.  

Go forth and start mapping

And there you have it. I hope this tutorial helped you to get a better idea of what you can do with CartoDB and that you’re inspired to use it for your own tracking data. Please share your maps or any feedback you have regarding this tutorial in the comments on the original tutorial’s website.

 

DON’T MISS  How to build a weather map in CartoDB

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest from Storybench

Keep up with tutorials, behind-the-scenes interviews and more.