A centroid is a geometric center that is calculated from geometries in a map layer. You can define whether centroids are calculated using all geometries, a group of geometries, or by a singular geometry.
This guide describes how to apply the Find centroid of geometries analysis to find unweighted, or weighted, centers of polygons for geometry groupings.
This multi-step process locates the service areas (by applying the Calculate clusters with points analysis), then calculates the weight, by usage, within the identified service areas (by applying the Find centroid of geometries analysis).
the_geomallows you to collapse the polygons to their individual centroids.
Let's explore the Citi Bike data for New York City taken from June 2016. This dataset contains a column called
count, that contains the number of times users ended their trip in the month of June. The
end_station_name column contains the bike station where they ended their trip in the month of June.
Suppose the New York City Department of Transportation has a budget to position seven vans around the bike share network to reallocate excess bikes to empty stations. This example finds the optimal seven points, given our basic assumptions, according to the dataset.
Import the template .carto file packaged from "Download resources" of this guide and create the map. Builder opens with Citi Bike data as the first and only map layer.
From the LAYERS pane, click the Citi Bike map layer.
Click the ANALYSIS tab and apply the Calculate clusters of points option. The source layer must be the layer for which you need the clusters.
7 as the number of clusters.
Switch to the Data View of the Citi Bike map layer, you will see that this step gives a
cluster_no to each station, from one to seven.
Now that the cluster assignment of each station has been calculated (the result being the
cluster_no column of the map layer), locate a weighted center for these clusters to optimally position the Citi Bike re-balance van.
From the Citi Bike layer ANALYSIS tab, click
+ from Your worflow, to add a second analysis to the chain.
Select the Find centroid of geometries analysis.
The analysis confirmation dialog displays which columns from your dataset were updated. The result is seven points as weighted centers of clusters for servicing the most frequented stations with the vans.
To apply even more style enhancements, you can style these centroids BY VALUE and choose one of the updated columns from your dataset. This helps display where the weighted centers are located, in relation to the most frequently used bike stations.
Click and drag
A1 Clusters from the Citi Bike map layer and drop it below the Citi Bike layer.
A new map layer is created,
B Citi Bike, displaying all of the centroids in the cluster of stations. Style this layer BY VALUE using the
cluster_no column to visualize how the regions are defined geographically, according to the most frequented stations.
If you are interested in using the underlying functions in the SQL view of Builder, you can find centroids of polygon geometries (or clusters) with the SQL
ST_Centroid query. View the PostGIS ST_Centroid documentation for details.
We would love to hear from you! Was it easy to understand? Do you need more information? Let us know.