Apply the Albers Projection with a SQL Query

Data/SQL Guides

Apply the Albers Projection with a SQL Query

By default, maps created in CARTO use the Web Mercator projection. All maps are projections - a way to represent the "spherical" Earth as a flat representation in a browser. The Albers projection is a popular map projection for the US because it creates minimal distortions for most of the country.

To see an example of the Albers projection, view this map which uses the Albers projection to visualize flight routes to and from all airports in the US.

In CARTO, geometries are stored using the WGS84 projection, which uses the_geom column. To show data on a map, the Web Mercator projection makes it easy to quickly transform your data into pixels. Web Mercator versions of your data are pre-stored in a hidden column, called the_geom_webmercator.

This guide describes how to quickly project your map and data with the Albers projection, instead of the default, Web Mercator.

Create a Map using US Counties

  1. Create a a map from the cb_2013_us_county_500k dataset, showing all USA counties and their information. This dataset is available from CARTO's Data Library when connecting a dataset. The map opens in the Builder, displaying polygon geometries for the map layer.

    When using a different projection in CARTO other than Web Mercator, you must change the default basemap in order to better visualize state borders. It is recommended to select a color as your basemap.

  2. Click on the default basemap to view the basemap options.

  3. Select COLOR as the basemap source and select black as the background color.

Change basemap using a color source

Apply the Albers Projection with a SQL Query

The SQL option is available from CARTO Builder when a map layer is selected.

  • Switch the slider button, located at the bottom of the DATA tab, from VALUES to SQL and apply the following SQL query:
  ST_Transform(the_geom_webmercator, 2163) AS the_geom_webmercator,

Albers projection applied

This SQL query applied the ST_Transform PostGIS function, which returns the geometry with coordinates transformed to the Albers projection. ST_Transform takes the hidden column (the_geom_webmercator) and the ID number for the Spatial Reference System being applied (the Albers projection, SRID 2163).

Click on "Download resources" from this guide to download the final .carto file used for this guide. Remember to extract the zip file before importing.