How is the population density calculated?

When the data is available, the population density is calculated by population/area, and whenever the data is not available we use an estimate based on the lat/lng.