Example - Explore Chicago's Police Station and Crime Data
- Datasets needed:
- Chicago Crimes (
chicago_crimes_sampled
): download it from thebuilder-demo
CARTO account and import it into CARTO from your local machine. - Chicago Police Stations (
chicago_police_stations
): download it from thebuilder-demo
CARTO 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_sampled
csv file in your CARTO Datasets dashboard first, then thechicago_police_stations
csv.
- Select
chicago_crimes_sampled
andchicago_police_stations
, click onCreate map
.
Rename map title and layers
- Rename map title to
Police Stations Location Demo
. - Rename layers:
chicago_crimes_sampled
asCrimes
,chicago_police_stations
asPolice 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
andprimary_type
. - Rename them as
Number of Crimes
,Date
andType 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 andADD 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 to2
and 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
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
.
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 belowPolice Stations
andCentroids
. Rename the new layer asLines
.
Lines style
- In order to style
Lines
layer follow these steps:- Click on
Lines
layer. - Click on
STYLE
:FILL
: set the line width value to3
and color blue (#40B4E5
).
- Click on
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 to20
and color to wageningen green (#3FAE29
).STROKE
: set stroke width to0
.- Check the
Labels
option:COLUMN
:category
.SIZE
:8
.HALO
:0
.OFFSET
:0
.
- Click on
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 to20
and color to dark pink (#EA526F
).STROKE
: set stroke width to0
.- Check the
Labels
option: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
LAYERS
pane on main Builder interface, click on theLines
layer. - In the
DATA
tab. Activate the Add as a widget checkbox on thelength
column. - 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.