pycensus.census.worldwide.gba¶
GlobalBuildingAtlas (GBA) global source: building footprints with heights, building metrics, and a population estimate from built floor area.
from pycensus.census.worldwide import gba b = gba.fill_heights(gba.load_buildings(aoi, cache_dir)) # footprints + heights (+ built_m2) cells = gba.h3_metrics(b, 11) # buildingHeightMax/Median, buildingFootprintArea, builtFloorArea, ... built, prof = gba.built_area_raster(b, worldpop_tif) # built m2 on WorldPop's grid est, info = gba.built_surface_population(built, worldpop, prof, census=polys)
download_tiles(tiles, cache_dir=None)
¶
Download the three parts of each tile (skipping files already there). Returns [(tile, continent)] for the tiles GBA has.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiles
|
Iterable[str]
|
Tile names. |
required |
cache_dir
|
Cache folder; |
None
|
load_buildings(aoi, cache_dir=None, clip=True, refresh=False)
¶
Every GBA footprint of aoi with its LoD1 height.
Returns a GeoDataFrame (EPSG:4326): source (osm / ms / google / ...), id, region, height (m; NaN where GBA has none),
height_var, footprint_m2 (true area). clip: keep the footprints whose centroid lies inside the AOI polygon (else its bbox).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
GeoDataFrame
|
Area of interest (GeoDataFrame). |
required |
cache_dir
|
Cache folder; |
None
|
|
clip
|
bool
|
Keep only footprints inside the AOI polygon. |
True
|
refresh
|
bool
|
Ignore the cached file. |
False
|
read_heights(json_path, keys, chunk=1 << 26)
¶
{key: (height, var)} for keys from a GBA LoD1 height file (a single JSON object, read in chunks -- the files are ~1 GB).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_path
|
Path
|
LoD1 height file. |
required |
keys
|
set
|
Building keys wanted. |
required |
chunk
|
int
|
Read size in bytes. |
1 << 26
|
tile_index(cache_dir=None)
¶
{tile: continent} for every tile GBA publishes (from the HuggingFace folder listings of GBA.LoD1 Polygon/<continent>; cached).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Cache folder; |
None
|
tile_name(lon, lat)
¶
Name of the 5-degree tile containing (lon, lat), e.g. (34.8, 31.25) -> 'e030_n35_e035_n30'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
Longitude. |
required |
lat
|
float
|
Latitude. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The tile name. |
tiles_for_bbox(west, south, east, north)
¶
Every tile a WGS84 bounding box touches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
west
|
float
|
West bound. |
required |
south
|
float
|
South bound. |
required |
east
|
float
|
East bound. |
required |
north
|
float
|
North bound. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
Tile names. |
built_area_raster(b, template_tif, out_tif=None, column='built_m2')
¶
Sum of column per pixel of template_tif's grid (e.g. the WorldPop raster), buildings by centroid. Returns (array, profile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
GeoDataFrame
|
Buildings with |
required |
template_tif
|
str
|
Raster whose grid is used. |
required |
out_tif
|
Optional[str]
|
Optional output GeoTIFF. |
None
|
column
|
str
|
Column summed. |
'built_m2'
|
fill_heights(b, resolution=8)
¶
Copy of b with height filled where GBA has none (median of its res-resolution h3 cell, else of all), height_filled flag,
and built_m2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
GeoDataFrame
|
GBA buildings. |
required |
resolution
|
int
|
H3 resolution of the medians. |
8
|
h3_metrics(b, resolution)
¶
METRIC_COLUMNS per h3 cell (index: cell id) at resolution, buildings by centroid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
GeoDataFrame
|
Buildings with heights and areas. |
required |
resolution
|
int
|
H3 resolution. |
required |
polygon_metrics(b, polygons, id_col)
¶
METRIC_COLUMNS per polygon (index: polygons[id_col]), buildings by centroid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
GeoDataFrame
|
Buildings with heights and areas. |
required |
polygons
|
GeoDataFrame
|
Zones. |
required |
id_col
|
str
|
Zone id column. |
required |
zone_metrics(b, zone)
¶
METRIC_COLUMNS per zone id (zone: one id per building, NaN = outside every zone). b needs height, footprint_m2, built_m2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
GeoDataFrame
|
Buildings with heights and areas. |
required |
zone
|
Series
|
Zone id per building. |
required |
built_surface_population(built, worldpop, profile, census=None, census_col='population', min_ratio=0.25, k_nearest=5, out_tif=None)
¶
See the module docstring. Returns (estimate array, info dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
built
|
ndarray
|
Built floor area per pixel. |
required |
worldpop
|
ndarray
|
WorldPop population per pixel (same grid). |
required |
profile
|
dict
|
Raster profile of the grid. |
required |
census
|
Optional[GeoDataFrame]
|
Optional census polygons with population. |
None
|
census_col
|
str
|
Census population column. |
'population'
|
min_ratio
|
float
|
WorldPop below this share of the built-surface estimate counts as missing. |
0.25
|
k_nearest
|
int
|
Census polygons used to calibrate a pixel outside the census. |
5
|
out_tif
|
Optional[str]
|
Optional output GeoTIFF. |
None
|