Exercise:)Conditional)Styling)withCartoCSS) · Exercise:)Conditional)Styling)withCartoCSS)!...
Transcript of Exercise:)Conditional)Styling)withCartoCSS) · Exercise:)Conditional)Styling)withCartoCSS)!...
Exercise: Conditional Styling with CartoCSS Thematic mapping can be accomplished in CartoDB through the use of CartoCSS. You can define default properties for a table and then additional properties to define styles for features based on values of rows using conditional parameters such as equal to, greater than, less than, and others. You can combine these conditional operators with SQL statements to create advanced styles.
In this exercise you are going to learn how to use CartoCSS to conditionally style a table containing crime data by hour. Each point will be styled according to the time of day when the crime occurred.
Step 1: Login to CartoDB
• Go to http://cartodb.com and login to your account.
Step 2: Import Crime Data to a Table
• In your exercise data folder you will find a file called neisd_burglaries.zip which contains a shapefile of burglaries from the year 2009 in the North East Independent School District in San Antonio.
• Using the skills you learned in past exercises, import this shapefile as a dataset.
Step 3: Style the Points using CartoCSS
• Open the dataset you just connected and switch to Map View. The default symbology should appear as seen in the screenshot below.
• Switch to Table view and find the field called ‘hr’. This field contains numeric data representing the hour of the day when the burglary was committed. It is in a 24 hour format. We’re going to
style the data based on this field.
• Switch back to Map view.
• Click the CSS button to symbolize each point into one of four categories including:
o 0-‐6 (early morning)
o 7-‐12 (morning)
o 13-‐18 (afternoon)
o 19-‐24 (night)
• Add the following CartoCSS code to symbolize the burglaries that occurred between midnight and 6 AM in a blue fill color.
• Apply the style and you should see that some of the points have now been turned blue indicating that this particular burglary occurred in the early morning hours. I’ve zoom in a bit in this case.
• Now add the other three styles as seen below and apply them to see the result.