Blog·Craft·

Which area belongs in the denominator?

Country provides total, land and water area. Choose the field that matches the statistic you want to display.

A country comparison might show population density beside population. The division looks straightforward until you choose the area. People per square kilometre of land and people per square kilometre of total area are different statistics. Using total area includes water in the denominator and can lower the result.

In API 2.0.0, a paid Country lookup with ?deep=true provides three area fields inside deep. area is total area, land_area is land area, and water_area is water area. All three use square kilometres.

If your column says "People per square kilometre of land", calculate it from population and land_area:

const { population, land_area } = response.deep ?? {}
const density = Number.isFinite(population) && population >= 0 &&
  Number.isFinite(land_area) && land_area > 0
  ? population / land_area
  : null

This produces a derived value for your application. Country does not return that density as its own field. Keep population_period with the result so the caption can identify the population estimate's year or period when known. The calculation does not make that estimate more recent.

The missing-value check matters because a country can have a total area without a usable land-and-water breakdown. Those fields are null when unknown or when the breakdown conflicts with the total. Filling missing land area with total area would quietly change the meaning of the density column for some rows. Leave that density unavailable instead.

Water area also distinguishes a reported zero from an unknown value. Show water_area: 0 as zero if you display it. It does not mean the field was omitted. If one part of the breakdown is missing, don't manufacture it by subtracting the other part from total area.

For a table comparing how large countries are in total, area is still the appropriate field. For density, choose the denominator once, label it, and use the same definition throughout the comparison.