Example - Explore Chicago's Police Station and Crime Data
Learn how to explore how far police station locations are from crimes centroids per district in the city of Chicago.
- Datasets needed:
- Chicago Crimes (
chicago_crimes_sampled): download it from thebuilder-demoCARTO account and import it into CARTO from your local machine. - Chicago Police Stations (
chicago_police_stations): download it from thebuilder-demoCARTO account and import it into CARTO from your local machine.
- Chicago Crimes (
Import datasets and create a map
Import datasets into CARTO
- It’s easy to import files into CARTO! Drag and drop the
chicago_crimes_sampledcsv file in your CARTO Datasets dashboard first, then thechicago_police_stationscsv.
- Select
chicago_crimes_sampledandchicago_police_stations, click onCreate map.
Rename map title and layers
- Rename map title to
Police Stations Location Demo. - Rename layers:
chicago_crimes_sampledasCrimes,chicago_police_stationsasPolice 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
Crimeslayer. - In DATA tab, activate the checkbox on
point count,dateandprimary_type. - Rename them as
Number of Crimes,DateandType of Crimerespectively.
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
Crimeslayer. - Click on the
ANALYSIStab andADD ANALYSIS. - Select
Find centroid from geometriesanalysis. - 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
Crimeslayer follow these steps:- Click on
Crimeslayer. - Click on
STYLE:FILL: set the marker size value to2and color to yellow (#FFE95C).STROKE: set stroke width to0.BLENDING:multiply.
- Click on

Connect police stations with centroids and calculate distances
- Add a new analysis (to the
Centroidslayer). - Select Connect with lines.
- Click on ADD ANALYSIS.
- Set the parameters as follows:
TYPE:To SourceTARGET:Police Stations- Check the
GROUP BYoption:SOURCE COL.:category.TARGET COL.:district_char.

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
lengthcolumn 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
Crimesbut belowPolice StationsandCentroids. Rename the new layer asLines.
Lines style
- In order to style
Lineslayer follow these steps:- Click on
Lineslayer. - Click on
STYLE:FILL: set the line width value to3and color blue (#40B4E5).
- Click on
Centroids style
- In order to style the
Centroidslayer follow these steps:- Click on
Centroidslayer. - Click on
STYLE:FILL: set the marker size value to20and color to wageningen green (#3FAE29).STROKE: set stroke width to0.- Check the
Labelsoption:COLUMN:category.SIZE:8.HALO:0.OFFSET:0.
- Click on
Police Stations style
- In order to style the
Police Stationslayer follow these steps:- Click on
Police Stationslayer. - Click on
STYLE:FILL: set the marker size value to20and color to dark pink (#EA526F).STROKE: set stroke width to0.- Check the
Labelsoption:COLUMN:district_char.SIZE:8.HALO:0.OFFSET:0.
- Click on
Add a histogram widget for filtering by distance
Add a widget for filtering by distance
- Go back to
LAYERSpane on main Builder interface, click on theLineslayer. - In the
DATAtab. Activate the Add as a widget checkbox on thelengthcolumn. - Rename them as
Distance.

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.
