Cartogram

Resizes regions by a numeric value.

type: cartogramtoolbarstable

What it does

A cartogram sizes each region by a value instead of by its real area. Choose a population column and countries with more people take up more room.

The whole layer keeps roughly the same overall size. The distribution changes, not the frame of the map.

Areas are measured on the sphere in square metres. This avoids using Mercator screen area, where high-latitude regions start too large.

Five methods are available:

Use something else when the question is "how big is this really?" rather than "how big is this value." That is True area, or a switch to an equal-area projection with the Projection tool.

The demo map opens in Equal Earth, not Web Mercator. The projection tool is on the toolbar so you can compare the same result in Mercator.

Using it

  1. Open the cartogram icon in the toolbar.
  2. Pick the input layer. Any polygon layer on the map can be used.
  3. Pick the attribute to size by. Only attributes observed to hold numbers are offered. Features without a positive value are left out.
  4. Pick a cartogram type. Start with the default.
  5. Optionally raise leave out anything below: a region asked to shrink ten thousandfold cannot get there and can distort the rest of the map.
  6. Press Calculate. The elapsed time is shown while it runs and the run can be canceled. A world layer takes a few seconds.
  7. The result arrives as a new layer in the legend, with the original still underneath. That comparison is the point of the result.

Only drawn data is used. For a layer served as vector tiles, only the features in view take part, and the panel says so. Zoom out until the whole layer is on screen before calculating, or use a layer with a geojson source, where the full dataset is always available.

Worked example: the same five countries sized by pop_est, generated by running the operation rather than drawn by hand.

Polygons only. A cartogram sizes a shape by its area, and a point or a line has none, so the operation refuses those rather than guessing. See the geometry matrix.

In your own map

The tool works on an ordinary polygon layer that carries a numeric attribute. There is no special layer type and no preparation step. The demo config points at Natural Earth country polygons with a pop_est column.

Extending it

webmapx-cartogram-tool subclasses the geoprocessing tool with one operation pinned. Use the same pattern to give another analysis operation its own toolbar button: subclass, set pinnedOperation, add a registry entry.

The maths is a plain GeoJSON→GeoJSON function in src/utils/cartogram.ts, wired in as the operation's compute. The function undoes the pipeline's Web Mercator round trip itself, because the pipeline hands every operation EPSG:3857 and Mercator inflates area by 1/cos²(latitude).

Three rules are important: grow each part of a multipart feature around that part's own center, take longitude steps the short way round the globe, and measure and correct the achieved area over up to four passes.

Config typecartogram
Element<webmapx-cartogram-tool>
Placementtoolbar
Sourcesrc/components/webmapx-cartogram-tool.ts
src/utils/cartogram.ts
src/utils/geoprocessing-operations.ts
Teststests/cartogram.test.ts
Relatedgeoprocessing, projection, truearea