Contents

AzurePostGIS

Enabling PostGIS + GeoDjango on Azure

In order to use GeoDjango and PostGIS, we need GDAL (Geospatial Data Abstraction Library), PROJ (Cartographic Projections library), and GEOS (Geometry Engine Open Source); installed into Azure. Big Oof. Also, on Azure we need to enable PostGIS, but this is easy.

Enable on the database server

  1. Go to the server resource.
  2. Then under settings go to ‘Server Parameters’
  3. In the search bar, type ’extensions’ and click on the dropdown of ‘azure.extensions’.
  4. Select ‘POSTGIS’
  5. Save

IMPORTANT: In Azure, PostGIS is not available for PostgreSQL16 yet, only until 15! https://learn.microsoft.com/en-gb/azure/postgresql/flexible-server/concepts-extensions?WT.mc_id=Portal-Microsoft_Azure_OSSDatabases#extension-versions

Create a Docker Image on Azure using Azure Container Registry

See post

Install GDAL

See the following blogpost: https://learn.microsoft.com/en-us/answers/questions/1287370/azure-web-app-gdal-support

First of all, GeoDjango requires GDAL 3.7 as the highest version. For local its easy to update this to 3.8. For Azure probably not. Make sure to install version 3.7.3 (see https://gdal.org/download.html)

Azure runs on linux, so we need linux commands to install GDAL. Luckily this is so much easier than on Windows. Run this in the SSH of the App Service.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# display all available versions for apt-get (not needed)
sudo apt list -a gdal-bin

# get it
sudo apt-get install gdal-bin=3.7.3

# set to path
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/

# weirdly set python? --> set GDAL==3.7.3 in requirements.txt
pip install GDAL==3.7.3

If this doesnt work, install a custom wheel of GDAL, see the last comment in the post.