GeoDjango is a world-class geographic Web framework. We will install GeoDjango step by step:
- Installing Geospatial library:
GDAL
- Database installation:
PostGIS
DATABASES
configuration- Add
django.contrib.gis
toINSTALLED_APPS
Installing Geospatial library: GDAL
:
GeoDjango provides interfaces for some source geospatial libraries e.g. GEOS, PROJ.4, GDAL, GeoIP, PostGIS, SpatiaLite. On ubuntu/Debian, We will install the following packages which will install, directly or by dependency, the required geospatial libraries:
sudo apt-get update
sudo apt-get install python3-pip python3-dev libpq-dev
sudo apt-get install binutils libproj-dev gdal-bin
pip install GDAL
Database installation: PostGIS
:
PostGIS adds geographic object support to PostgreSQL, turning it into a spatial database.
- Install PostgreSQL
- Create Database, User and Grant Privileges
- Install PostGIS apt package
- Install the package that contains postgis.control manually
- Create PostGIS Extension
Install PostgreSQL :
sudo apt-get update
sudo apt install postgresql postgresql-contrib
Create Database, User and Grant Privileges :
Log into an interactive Postgres session by typing:
sudo -u postgres psql
First, create a database.
postgres=# CREATE DATABASE db_name;
Next, create a database user.
postgres=# CREATE USER db_user WITH PASSWORD 'password';
Then, give our new user access to administer our new database:
postgres=# GRANT ALL PRIVILEGES ON DATABASE db_name TO db_user;
Exit out of the PostgreSQL prompt by typing:
postgres# \q
Install PostGIS apt package :
sudo apt install postgis --no-install-recommends
Install the package that contains postgis.control manually :
sudo apt-get install postgis postgresql-<POSTGRESQL_VERSION>-postgis-scripts
Create PostGIS Extension :
sudo -u postgres psql
postgres=# \c db_name
db_name=# CREATE EXTENSION postgis;
DATABASES
configuration :ΒΆ
Add the following ENGINE
to DATABASES
config at settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
....
},
}
Add django.contrib.gis
to INSTALLED_APPS :
INSTALLED_APPS = [
'django.contrib.admin',
.......,
'django.contrib.gis',
]
Feel free to leave a comment.
Top comments (3)
I'm getting error:
could not open extension control file "/usr/share/postgresql/12/extension/postgis.control"
Resolved by using command
Thanks