Skip to content

Instantly share code, notes, and snippets.

@piensaenpixel
Last active April 13, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piensaenpixel/d7596c688dac980bde61886bc1a21869 to your computer and use it in GitHub Desktop.
Save piensaenpixel/d7596c688dac980bde61886bc1a21869 to your computer and use it in GitHub Desktop.

#Migration map This map shows the migration of three birds species along a year. This is the map we should design. https://designwebinar.cartodb.com/viz/fc8b4588-015c-11e6-98a0-0ecfd53eb7d3/embed_map

Dataset

Import the migration dataset https://designwebinar.cartodb.com/tables/scge_migration

##Basemap First of all we are going to reuse the basemap which we designed in the previous webinar

##Mapping

  1. Import dataset migration

  2. Actually this is a point dataset, for our first layer we need convert this point dataset into a line dataset. We are going to use this simple SQL:

       SELECT 
       device_info_serial, 
       device_info_serial as cartodb_id,
       ST_MakeLine (the_geom_webmercator order by date_time) as the_geom_webmercator
          FROM scge_migration
       GROUP BY device_info_serial 

    For more information: http://blog.cartodb.com/jets-and-datelines/

  3. Colors:

    • Bird 1: #ffcc00;
    • Bird 2: #1F78B4;
    • Bird 3: #B2DF8A;
  4. We are going to style this layer, with a simple cartocss (Device info serial is the column for each bird)

       #scge_migration {
         line-width: 1;
         line-opacity: 0.5;
         line-dasharray: 2,2;
       }
       #scge_migration[device_info_serial=311] {
          line-color: #ffcc00;
       }
       #scge_migration[device_info_serial=317] {
          line-color: #1F78B4;
       }
       #scge_migration[device_info_serial=344] {
          line-color: #B2DF8A;
       } 
  5. Above this layer we are going to design the torque layer. We need to add the same layer but in this case we are not going to change the layer type.

    • We use the wizard for changing this layer into a category torque map.
    • We are going to remove trails (a lot of noise in this case)
    • Use bird's colors (we are going to use cartocss vars)
       @bird1: #FFCC00;
       @bird2: #5ca2d1;
       @bird3: #B2DF8A;
       
       
       Map {
       -torque-frame-count:256;
       -torque-animation-duration:30;
       -torque-time-attribute:"date_time";
       -torque-aggregation-function:"CDB_Math_Mode(torque_category)";
       -torque-resolution:2;
       -torque-data-aggregation:linear;
       }
       
       #scge_migration{
         comp-op: source-over;
         marker-fill-opacity: 0.9;
         marker-line-color: #FFF;
         marker-line-width: 0;
         marker-line-opacity: 1;
         marker-type: ellipse;
         marker-width: 2;
         [value=1] {
          marker-fill: @bird1;
         }
         [value=2] {
          marker-fill: @bird2;
         }
         [value=3] {
          marker-fill: @bird3;
         }
       }
    • We can add some additional styling to the points so we can see the migration path of the birds better
       #scge_migration::point{
         comp-op: source-over;
         marker-fill-opacity: 0.05;
         marker-line-color: #FFF;
         marker-line-width: 1;
         marker-line-opacity: 0;
         marker-type: ellipse;
         marker-width: 15;
         [value=1] {
          marker-fill: @bird1;
         }
         [value=2] {
           marker-fill: @bird2;
         }
         [value=3] {
          marker-fill: @bird3;
         }
       }
  6. For more context we should add a legend in the torque layer

  • Add legend
  • In the Template we choose 'category'
  • Add title in the legend (Bird's name) For example
  • Now we need change the value of the labels (311, 317, 344 really doesn't give any information)
  • We click in Change HTML and then we can change the labels (imagine we now the bird's name) Robin, Machango and Flint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment