This content applies to a previous version of CARTO
In October 2021 we released a new version of our platform. You can find the latest documentation at docs.carto.com
How can I inset a map feature?
Why do I need an inset?
When creating maps, areas of interest may be separated by large irrelevant regions, forcing suboptimal zoom levels. For instance, displaying all 50 US states requires zooming out enough to include Alaska and Hawaii, which reduces detail visibility for continental areas.
In traditional print cartography, insets solve this by rendering distant regions closer to primary areas. This technique also works for digital maps.
How can I create an inset?
CARTO enables insets using SQL queries with PostGIS functions.
ST_TransScale modifies geometry by relocating it and adjusting its size simultaneously. Parameters specify:
- The geometry to modify
- East/West and North/South axis offsets (in SRID units)
- Scale factors for East/West and North/South axes
ST_Transform defines projections. Using different projections for different states prevents distortion – for example, applying the Alaska Albers projection (EPSG 3338) to Alaska and Hawaii Albers projection (EPSG 102007) to Hawaii while using the North American Albers projection (EPSG 42303) for other states.
Example SQL Query
SELECT
CASE
WHEN name != 'Alaska' AND name != 'Hawaii'
THEN ST_Transform(the_geom_webmercator,42303)
WHEN name = 'Alaska'
THEN
ST_TransScale(
ST_Transform(
the_geom_webmercator
, 3338
)
, -3800000
, -900000
, 0.7
, 0.7
)
WHEN name = 'Hawaii'
THEN
ST_TransScale(
ST_Transform(
the_geom_webmercator
, 102007
)
, -1200000
, -450000
, 1.2
, 1.2
)
END the_geom_webmercator
, cartodb_id
FROM ne_50m_admin_1_states
Note: Builder widgets cannot function on mixed SRID geometries.
