DIY  /  Builder

Explore Chicago's police stations and crimes per district.

Learn how to explore how far police station locations are from crimes centroids per district in the city of Chicago.

Import datasets and create a map

Import datasets into CARTO

  • It’s easy to import files into CARTO! Drag and drop the chicago_crimes_sampled csv file in your CARTO Datasets dashboard first, then the chicago_police_stations csv.
  • Select chicago_crimes_sampled and chicago_police_stations, click on Create map.

Rename map title and layers

  • Rename map title to Police Stations Location Demo.
  • Rename layers:
    1. chicago_crimes_sampled as Crimes,
    2. chicago_police_stations as Police Stations,

Layers and widgets

Show the different layer options

  • Click on the basemap layer and select Dark Matter Lite.
  • Each layer has 5 options: DATA, ANALYSES, STYLE, POP-UPS and LEGENDS.

Add widgets in order to explore the crimes layer

  • Back to the main menu, click on Crimes layer.
  • In DATA tab, activate the checkbox on point count, date and primary_type.
  • Rename them as Number of Crimes, Date and Type of Crime respectively.

Add Analysis and styles

Optional: sample the dataset

You can add the Subsample percent of rows analysis to the crimes dataset. We could reduce the dataset size to a 10% while we define the analysis workflow, and then set it to 100% when we finish in order to recalculate the analysis with the whole dataset.

Create crimes centroids by district

  • Back to the main menu, click on the Crimes layer.
  • Click on the ANALYSIS tab and ADD ANALYSIS.
  • Select Find centroid from geometries analysis.
  • Click on ADD ANALYSIS.
  • Set the parameters as follows:
    • CATEGORIZE...: district_c.
  • Click on APPLY.

Style the crimes layer

  • After applying the analysis, drag and drop out the original node layer. Rename the analysis node layer as Centroids.

Now you should have a mess of points, three layers equally styled.

  • In order to style the Crimes layer follow these steps:
    • Click on Crimes layer.
    • Click on STYLE:
      • FILL: set the marker size value to 2 and color to yellow (#FFE95C).
      • STROKE: set stroke width to 0.
      • BLENDING: multiply.

style

Connect police stations with centroids and calculate distances

  • Add a new analysis (to the Centroids layer).
  • Select Connect with lines.
  • Click on ADD ANALYSIS.
  • Set the parameters as follows:
    • TYPE: To Source
    • TARGET: Police Stations
    • Check the GROUP BY option:
      • SOURCE COL.: category.
      • TARGET COL.: district_char.

lines

Click on the DATA tab and switch to the Data View to see how the new fields have been created from this analysis, With the length column being specifically interesting.

Style police stations, centroids and lines layers

  • After applying the analysis, drag and drop out the Connect with lines analysis node, on top of Crimes but below Police Stations and Centroids. Rename the new layer as Lines.

Lines style

  • In order to style Lines layer follow these steps:
    • Click on Lines layer.
    • Click on STYLE:
      • FILL: set the line width value to 3 and color blue (#40B4E5).

Centroids style

  • In order to style the Centroids layer follow these steps:
    • Click on Centroids layer.
    • Click on STYLE:
      • FILL: set the marker size value to 20 and color to wageningen green (#3FAE29).
      • STROKE: set stroke width to 0.
      • Check the Labels option:
        • COLUMN: category.
        • SIZE: 8.
        • HALO: 0.
        • OFFSET: 0.

Police Stations style

  • In order to style the Police Stations layer follow these steps:
    • Click on Police Stations layer.
    • Click on STYLE:
      • FILL: set the marker size value to 20 and color to dark pink (#EA526F).
      • STROKE: set stroke width to 0.
      • Check the Labels option:
        • COLUMN: district_char.
        • SIZE: 8.
        • HALO: 0.
        • OFFSET: 0.

Add a histogram widget for filtering by distance

Add a widget for filtering by distance

  • Go back to LAYERS pane on main Builder interface, click on the Lines layer.
  • In the DATA tab. Activate the Add as a widget checkbox on the length column.
  • Rename them as Distance.

final

Link to the map.

Extension

This demo can be improved:

  • With the Filter by layer analysis to link police stations and crime locations

  • Adding Areas of interest to the centroids and police stations and check which crimes are less than certain distance to both locations.

extension