Changing between types of geographical support
Last updated
Was this helpful?
Last updated
Was this helpful?
The tutorials on this page will teach you how to transform different types of geographic support (such as points, lines and polygons) - and their variables - into polygons. By the end, you will understand how to enrich geographical data and how different geographical supports can impact spatial analysis. We'll be using functions from CARTO's Analytics Toolbox, and you'll be provided with both SQL and low-code Workflows approaches.
Access to a target polygon table - this is the table we will be transforming data into. You will also need source line and point tables, which we will be transforming data from. These tables will need to have some sort of spatial overlap.
We will be using the following BigQuery tables, sourced from Madrid’s Open Data Portal. You will need either a Google BigQuery connection or to use the CARTO Data Warehouse to use these specific tables.
cartobq.docs.madrid_districts
: District boundaries in Madrid.
cartobq.docs.madrid_bike_parkings
: Locations of public bicycle parking.
cartobq.docs.madrid_bike_all_infrastructure
: Bicycle-friendly infrastructure (bike lanes, shared lanes, and quiet streets).
cartobq.docs.madrid_bike_parkings_5min
: 5-minute walking isolines around bike parking locations.
When aggregating spatial data, it is important to be aware of the Modifiable Areal Unit Problem (MAUP). MAUP occurs when spatial data is grouped into different geographical units, which can lead to misleading interpretations. This issue arises because variation in the size and shape of the geographical areas affect the aggregation results.
Once of the ways that spatial analysts overcome MAUP is by converting data to a regular grid, including Spatial Indexes like H3 and Quadbin. You can see the difference in the maps below. Learn more about the benefits of this approach here, or get started with our Create and enrich an index tutorial.
To better understand MAUP, we distinguish between two types of properties:
Extensive properties: These typically increase as the size of an area increase. This could include population, total bike parking spots or total road length.
Intensive properties: These are independent of area size and are often derived by normalizing extensive properties. Examples include population density, bike parking density or road length per capita.
You can see the difference between these two types of properties in the maps below, the first of which shows the extensive bike parking count, and the second of which shows the intensive bike parking density.
When transforming numeric variables between different types of geographic support, it's important to be aware of whether you are working with an extensive or intensive variable, as this will impact the type of aggregation you do. For instance, if you wanted to calculate the total population in a county based on census tracts, you would want to sum this extensive property. If you wanted to calculate the population density, you would want to average this intensive property.
Time needed: < 5 minutes
Let's start with something simple, counting the number of points in a polygon, which can be achieved with the below Workflow. If this is your first time using CARTO Workflows, we recommend reading our Introduction to Workflows first to get familiar.
For our example, we'll be counting the number of bike parking locations in each district. We'll make use of the ENRICH_POLYGONS
function using count as the aggregation function. This will create a new column in the destination table called id_count
with the total number.
Prior to running the enrichment, we'll also need to generate a row number so that we have a numeric variable to aggregate.
Explore the results 👇
If you were to undertake this task with "vanilla SQL" this would be a far more complicated process, and require a deeper usage of spatial predicates (relationships) such as ST_CONTAINS
or ST_INTERSECTS
. However, this approach is versatile enough to handle more complex spatial operations - let's explore an example.
Time needed: < 5 minutes
Next, we'll be transforming lines to polygons - but still using the ENRICH_POLYGONS
function. For our example, we want to calculate the length of cycling infrastructure within each district.
In the Workflow below, we will aggregate the lane_value
variable with sum
as the aggregation function (but you could similarly run other aggregation types such as count, avg, min and max). This ensures that the lane values are proportionally assigned based on their intersection length with the district boundaries (rather than the entire length of each line). The sums of all these proportional lengths will be stored in the lane_value_sum
column in the destination table.
Explore the results 👇
Time needed: < 5 minutes
We can also use polygons as source geometries. This is incredibly useful when working with different organizational units - such as census tracts and block groups - which is very common when working with location data. The function works very similarly to when enriching with lines: it will sum the proportions of the intersecting polygons of each district. In this case, the proportions are computed using the intersecting area, rather than length.
Again, we use the Enrich Polygons component for this process, summing the area which intersects each district.
Explore the results 👇
In the resulting map, we can see the total area covered by 5' walking isolines per district, in squared meters.
Time needed: < 10 minutes
In addition to the standard enrichment methods we've covered, there are more advanced, alternative ways to enrich polygons. These include:
Raw enrichment: This method pairs source and target geometries that intersect and provides useful details, such as the area of the intersection. This allows users to apply their own aggregation methods as needed.
Weighted enrichment: This method distributes data based on a chosen column, using a proxy variable to more customize the way values are aggregated across polygons.
To demonstrate this, we'll use a simple Workflow to estimate the distribution of bicycles across the city using the Overture Buildings dataset. Our starting assumption is that 65% of the population owns a bike, leading to a total estimate of 2.15 million bicycles citywide.
This requires two enrichment steps:
Weighted enrichment: Using the Enrich Polygons with Weights
components, we distribute the estimated number of bikes based on the number of buildings and their floors, assuming taller buildings house more people.
H3 grid aggregation: We enrich a standardized H3 grid, making it easier to analyze and visualize patterns with an Enrich H3 Grid component
. This approach transforms a single city-wide estimate into a detailed spatial distribution, helping identify where bicycle infrastructure should be expanded to meet demand.
Explore the results 👇
This tutorial covered how to enrich spatial data using the CARTO Analytics Toolbox, addressing challenges like MAUP and leveraging Spatial Indexes for better accuracy. By exploring raw and weighted enrichment, we demonstrated how broad statistics can be transformed into meaningful spatial insights. These techniques will help you make more informed decisions in your own spatial analysis.