Установка ПостГИС¶
PostGIS добавляет поддержку географических объектов в PostgreSQL, превращая его в пространственную базу данных. ГЕОС, ПРОДЖ и ГДАЛ должны быть установлены до сборки PostGIS. Вам также могут понадобиться дополнительные библиотеки, см. Требования PostGIS.
The psycopg2 module is required for use as the database adapter when using GeoDjango with PostGIS.
On Debian/Ubuntu, you are advised to install the following packages: postgresql-x.x, postgresql-x.x-postgis, postgresql-server-dev-x.x, python-psycopg2 (x.x matching the PostgreSQL version you want to install). Alternately, you can build from source. Consult the platform-specific instructions if you are on macOS or Окна.
После установки¶
Создание пространственной базы данных¶
PostGIS 2 includes an extension for PostgreSQL that’s used to enable spatial functionality:
$ createdb <db name>
$ psql <db name>
> CREATE EXTENSION postgis;
Пользователь базы данных должен иметь права суперпользователя, чтобы запускать CREATE EXTENSION postgis. Команда запускается во время процесса migrate. Альтернативой является использование операции миграции в вашем проекте:
from django.contrib.postgres.operations import CreateExtension
from django.db import migrations
class Migration(migrations.Migration):
operations = [
CreateExtension('postgis'),
...
]
If you plan to use PostGIS raster functionality on PostGIS 3+, you should also
activate the postgis_raster extension. You can install the extension using
the CreateExtension migration
operation, or directly by running CREATE EXTENSION postgis_raster;.
GeoDjango в настоящее время не использует какие-либо функции топологии PostGIS. Если вы планируете использовать эти функции в какой-то момент, вы также можете установить расширение postgis_topology, выполнив команду CREATE EXTENSION postgis_topology;.
Управление базой данных¶
To administer the database, you can either use the pgAdmin III program
() or the
SQL Shell ().
For example, to create a geodjango spatial database and user, the following
may be executed from the SQL Shell as the postgres user:
postgres# CREATE USER geodjango PASSWORD 'my_passwd';
postgres# CREATE DATABASE geodjango OWNER geodjango;