Home | Benchmarks | Categories | Atom Feed

Posted on Sun 25 May 2025 under Artificial Intelligence

Better Building Footprints

Last month, I published a review of GeoDeep, a Python package that wraps up much of the complexity around detecting objects in satellite imagery into simple BASH commands.

The bundled building footprint detection model in GeoDeep often would result in outlines that were wobbly rather than straight lines. Below is an example.

GeoDeep Bangkok

I recently came across a Python package that can help correct this issue.

Building Regulariser is a 747-line Python package that can make AI-detected building footprints more plausibly-shaped. Its only dependencies are GeoPandas and Numpy and it supports multiple CPU cores. It has sensible defaults while still offering many knobs and dials for tuning results.

It has been in development for the past eight weeks and is the work of Nick Wright, a Senior Research Scientist at the Western Australian Department of Primary Industries and Regional Development.

In this post, I'll try out Building Regulariser on building outlines detected by GeoDeep on Maxar's satellite imagery of Bangkok, Thailand.

My Workstation

I'm using a 5.7 GHz AMD Ryzen 9 9950X CPU. It has 16 cores and 32 threads and 1.2 MB of L1, 16 MB of L2 and 64 MB of L3 cache. It has a liquid cooler attached and is housed in a spacious, full-sized Cooler Master HAF 700 computer case.

The system has 96 GB of DDR5 RAM clocked at 4,800 MT/s and a 5th-generation, Crucial T700 4 TB NVMe M.2 SSD which can read at speeds up to 12,400 MB/s. There is a heatsink on the SSD to help keep its temperature down. This is my system's C drive.

The system is powered by a 1,200-watt, fully modular Corsair Power Supply and is sat on an ASRock X870E Nova 90 Motherboard.

I'm running Ubuntu 24 LTS via Microsoft's Ubuntu for Windows on Windows 11 Pro. In case you're wondering why I don't run a Linux-based desktop as my primary work environment, I'm still using an Nvidia GTX 1080 GPU which has better driver support on Windows and ArcGIS Pro only supports Windows natively.

Installing Prerequisites

I'll use GDAL 3.9.3, Python 3.12.3 and a few other tools to help analyse the data in this post.

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
$ sudo apt update
$ sudo apt install \
    gdal-bin \
    jq \
    python3-pip \
    python3.12-venv

I'll set up a Python Virtual Environment and install the latest GeoDeep release.

$ python3 -m venv ~/.geodeep
$ source ~/.geodeep/bin/activate
$ python3 -m pip install \
    geodeep \
    buildingregulariser

I'll use DuckDB, along with its H3, JSON, Lindel, Parquet and Spatial extensions, in this post.

$ cd ~
$ wget -c https://github.com/duckdb/duckdb/releases/download/v1.3.0/duckdb_cli-linux-amd64.zip
$ unzip -j duckdb_cli-linux-amd64.zip
$ chmod +x duckdb
$ ~/duckdb
INSTALL h3 FROM community;
INSTALL lindel FROM community;
INSTALL json;
INSTALL parquet;
INSTALL spatial;

I'll set up DuckDB to load every installed extension each time it launches.

$ vi ~/.duckdbrc
.timer on
.width 180
LOAD h3;
LOAD lindel;
LOAD json;
LOAD parquet;
LOAD spatial;

The maps in this post were rendered using Esri's ArcGIS Pro 3.5. This is the latest version which was released last week.

Maxar's Bangkok Satellite Imagery

Maxar have an open data programme that I wrote a post on a few years ago. I later revisited this feed last month after the earthquake struck Myanmar and Thailand.

The image I'm using in this post covers part of the Chatuchak district in Bangkok and includes Ratchadaphisek Road which has several tall towers along it.

The image is a GeoTIFF pyramid containing a 17408x17408-pixel JPEG covering an area ~5.2 x 4.2 KM. The image was captured on February 14th by Maxar's WorldView 3 satellite at a resolution of 38cm.

$ wget https://maxar-opendata.s3.amazonaws.com/events/Earthquake-Myanmar-March-2025/ard/47/122022102203/2025-02-14/10400100A4C67F00-visual.tif

This is the image below in relation to its surrounding area in Bangkok.

DepthAnything v2 Bangkok

Below I've zoomed into Ratchadaphisek Road where you can see the tall towers.

DepthAnything v2 Bangkok

This is the metadata for the above image.

{
  "geometry": {
    "coordinates": [
      [
        [
          100.574350016387555,
          13.833249903918164
        ],
        [
          100.525209298594646,
          13.833560533960037
        ],
        [
          100.525429970258031,
          13.86737334
        ],
        [
          100.574579936582708,
          13.86737334
        ],
        [
          100.574350016387555,
          13.833249903918164
        ]
      ]
    ],
    "type": "Polygon"
  },
  "properties": {
    "ard_metadata_version": "0.0.1",
    "catalog_id": "10400100A4C67F00",
    "data-mask": "https://maxar-opendata.s3.amazonaws.com/events/Earthquake-Myanmar-March-2025/ard/47/122022102203/2025-02-14/10400100A4C67F00-data-mask.gpkg",
    "datetime": "2025-02-14T04:02:15Z",
    "grid:code": "MXRA-Z47-122022102203",
    "gsd": 0.38,
    "ms_analytic": "https://maxar-opendata.s3.amazonaws.com/events/Earthquake-Myanmar-March-2025/ard/47/122022102203/2025-02-14/10400100A4C67F00-ms.tif",
    "pan_analytic": "https://maxar-opendata.s3.amazonaws.com/events/Earthquake-Myanmar-March-2025/ard/47/122022102203/2025-02-14/10400100A4C67F00-pan.tif",
    "platform": "WV03",
    "proj:bbox": "664843.75,1529843.75,670156.25,1533619.8386004784",
    "proj:code": "EPSG:32647",
    "proj:geometry": {
      "coordinates": [
        [
          [
            670156.25,
            1529843.75
          ],
          [
            664843.75,
            1529843.75
          ],
          [
            664843.75,
            1533585.6070091636
          ],
          [
            670156.25,
            1533619.8386004784
          ],
          [
            670156.25,
            1529843.75
          ]
        ]
      ],
      "type": "Polygon"
    },
    "quadkey": "122022102203",
    "tile:clouds_area": 0.0,
    "tile:clouds_percent": 0,
    "tile:data_area": 19.9,
    "utm_zone": 47,
    "view:azimuth": 243.9,
    "view:incidence_angle": 59.9,
    "view:off_nadir": 27.2,
    "view:sun_azimuth": 139.3,
    "view:sun_elevation": 55.3,
    "visual": "https://maxar-opendata.s3.amazonaws.com/events/Earthquake-Myanmar-March-2025/ard/47/122022102203/2025-02-14/10400100A4C67F00-visual.tif"
  },
  "type": "Feature"
}

Building Footprint Regularisation

I'll run Maxar's image through GeoDeep's default building footprint detection model.

$ geodeep \
    ard_47_122022102230_2025-02-14_10400100A4C67F00-visual.tif \
    buildings \
    --output buildings.geojson

The resulting buildings.geojson file is 478 MB uncompressed and contains 32,958 building footprint detections.

$ jq -S '.features|length' \
    buildings.geojson # 32958

Anything that can read GeoJSON via GDAL will complain this file is too 'complex/large'. To add to this, ArcGIS Pro didn't want to open up GeoJSON files. I convert the above file into a Shapefile instead.

$ OGR_GEOJSON_MAX_OBJ_SIZE=0 \
    ogr2ogr \
        -nlt POLYGON \
        -skipfailures \
        buildings.shp \
        buildings.geojson

I tried to run 32,958 through Building Regulariser but after 12 hours it still hadn't finished. I'll pick a point in the result set and select the 100 closest buildings to that point.

$ ~/duckdb
COPY (
    FROM ST_READ('buildings.shp')
    ORDER BY ST_DISTANCE(ST_POINT(100.572653, 13.791058),
                         ST_CENTROID(geom))
    LIMIT 100
)
TO 'buildings.100.gpkg'
    WITH (FORMAT GDAL,
          DRIVER 'GPKG',
          LAYER_CREATION_OPTIONS 'WRITE_BBOX=YES');

I'll run these 100 buildings through Building Regulariser and get a GeoPackage (GPKG) file with the outlines straightened into more plausible shapes.

$ python3
from   buildingregulariser import regularize_geodataframe
import geopandas as gpd


regularize_geodataframe(
    gpd.read_file('buildings.100.gpkg')
       .to_crs('+proj=cea'),
).to_file('buildings.regularised.shp')

Below in orange are the GeoDeep-detected building outlines and in dark red are the regularised outlines.

GeoDeep Bangkok
Thank you for taking the time to read this post. I offer both consulting and hands-on development services to clients in North America and Europe. If you'd like to discuss how my offerings can help your business please contact me via LinkedIn.

Copyright © 2014 - 2025 Mark Litwintschik. This site's template is based off a template by Giulio Fidente.