Local: PostgreSQL + PostGIS
PostgreSQL, PostGIS and geoDjango
Tutorial example + leaflet
https://www.paulox.net/2021/07/19/maps-with-django-part-2-geodjango-postgis-and-leaflet/
Use GeoDjango, as an app: “django.contrib.gis”,
Voor prototyping met SQLite, de extensie daarvoor is Spatialite. PostGIS is als enige 100% compatibel met GeoDjango’s functies.
Installation
Follow: https://docs.djangoproject.com/en/5.0/ref/contrib/gis/install/#
GeoDjango requires GDAL so we need to install that too. If you’re running Windows, use the OSGEO4W Installer to download & install a variety of free & open source geospatial tools, including GDAL & QGIS. Visit http://trac.osgeo.org/osgeo4w, and follow the Quick Start for OSGeo4W Users steps. NOTE: Postgres installer stackbuilder for PostGIS already includes GDAL it seems, why does the django website state it seperately??
These instructions seems more straightforward: https://rathank.com/install-postgis-and-gdal-for-django-on-windows/
For Azure, we should be able to enable the extension and that’s it. (?)
Django / PostgreSQL errors fix
Issue (LOCAL DEVELOPMENT): Django says GDAL is not installed. My version is GDAL 308, as found by C:\OSGeo4W\bin (and then finding gdal308.dll). solution: https://stackoverflow.com/questions/44140241/geodjango-on-windows-try-setting-gdal-library-path-in-your-settings The issue ended up being a version mismatch between Django and GDAL. Django was not searching for the correct file name (gdal202.dll in my case).
Fixing it required me to add str(‘gdal202’) to the following file on line 26: (Python Root)\Lib\site-packages\django\contrib\gis\gdal\libgdal.py
Note that if you are working in a Virtual Environment, then Python Root will actually be wherever that is ie: Users\YourName\Envs\project If this issue reoccurs, you can look through your C:\OSGeo4W\bin directory to figure out which gdalxxx.dll it is that Django needs to search for. In addition, make sure that you are using the 32-bit versions of Python and OSGeo4Win. Otherwise, you may see the same failure.
PostgreSQL instructions
Installed programs: CLI: psql (seems to ask for the superuser of the computer’s password!) GUI: psAdmin package manager: Stackbuilder should be a 4th one….
Setting requirements
Further into requirements.txt: django-filter djangorestframework-gis djangorestframework django psycopg2-library
| |
For databases:
- Host is localhost on local postgresql server, on azure as the azure server.
- User: default user is postgres