New police stations based on Chicago crime locations clusters
In this example we are going to use points clustering to analyze where to locate five new police stations in Chicago based on 5000 samples of crime locations.
Generating the clusters
First, we calculate crime locations clusters using the
This query takes the crimes samples data, gathers their geometries in order to establish clusters and then groups the different geometry clusters. In the following visualization we can easily identify the different clusters by colors.
Calculating the clusters' centers
Once we have split the sample of points into clusters, we can easily work with them to calculate their centers, envelopes, concave/convex hulls and other different transformations. In this particular example we are interested in finding the center of the clusters, since that is where we are going to place the police stations. The Spatial Extension offers different functions for this task:
ST_CENTEROFMASS. In this case let’s use
ST_CENTERMEDIAN to calculate the location of the new police stations:
We can see the result in the following visualization, where the bigger dots represent the police stations we have decided to open based on our analysis: