PostGISは、PostgreSQLデータベース管理システム用の無料のオープンソースデータベースエクステンダーです。これは、面積、和集合、交差、距離、データ型などのいくつかの追加関数を追加し、SQLで位置クエリを実行できるようにするのに役立ちます。 PostGISを使用すると、データのポリゴンタイプとポイントタイプをPostgreSQLデータベースに保存できます。
このチュートリアルでは、CentOS8にPostgreSQLを使用してPostGISをインストールする方法を示します。
- CentOS8を実行しているサーバー。
- ルートパスワードはサーバーで構成されています。
始める前に、PostGISとEPELリポジトリをシステムにインストールする必要があります。次のコマンドを実行して、両方をインストールできます。
dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
次に、次のコマンドを使用して、Powertoolリポジトリを有効にし、デフォルトのPostgreSQLリポジトリを無効にします。
dnf config-manager --set-enabled PowerTools
dnf -qy module disable postgresql
終了したら、次のステップに進むことができます。
これで、次のコマンドを実行してPostGISをインストールできます:
dnf install postgis25_12
インストールが完了したら、次のコマンドでPostGISパッケージを確認できます:
rpm -qi postgis25_12
次の出力が得られるはずです:
Name : postgis25_12 Version : 2.5.5 Release : 2.rhel8 Architecture: x86_64 Install Date: Monday 01 February 2021 11:59:37 PM EST Group : Unspecified Size : 29832534 License : GPLv2+ Signature : DSA/SHA1, Tuesday 10 November 2020 01:36:47 PM EST, Key ID 1f16d2e1442df0f8 Source RPM : postgis25_12-2.5.5-2.rhel8.src.rpm Build Date : Tuesday 10 November 2020 01:30:09 PM EST Build Host : koji-rhel8-x86-64-pgbuild Relocations : (not relocatable) Vendor : PostgreSQL Global Development Group URL : http://www.postgis.net/ Summary : Geographic Information Systems Extensions to PostgreSQL Description : PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS "spatially enables" the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI's SDE or Oracle's Spatial extension. PostGIS follows the OpenGIS "Simple Features Specification for SQL" and has been certified as compliant with the "Types and Functions" profile.
次に、次のコマンドを使用してPostgreSQLデータベースを初期化します。
/usr/pgsql-12/bin/postgresql-12-setup initdb
次に、PostgreSQLサービスを開始し、次のコマンドを使用してシステムの再起動時に開始できるようにします。
systemctl start postgresql-12.service
systemctl enable postgresql-12.service
この時点で、PostgreSQLとPostGISがインストールされています。次に、PostGISの拡張機能を作成する必要があります。
まず、次のコマンドを使用してPostgresユーザーにログインします。
su - postgres
次に、次のコマンドを使用してpostgresユーザーとデータベースを作成します。
createuser test_usr
createdb test_postgis -O test_usr
次に、次のコマンドを使用してデータベースに接続します。
psql -d test_postgis
次の出力が表示されます。
psql (12.5) Type "help" for help.
次に、次のコマンドを使用してPostGIS拡張機能を作成します:
CREATE EXTENSION postgis;
次に、次のコマンドを使用してPostGISのバージョンを確認できます:
select PostGIS_Full_Version();
次の出力にPostGISバージョンが表示されます:
postgis_full_version ----------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------- POSTGIS="2.5.5" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="Rel. 7.2.1, January 1st, 2021" GDAL="GDAL 3.2.1, released 2020/12/29" L IBXML="2.9.7" LIBJSON="0.13.1" LIBPROTOBUF="1.3.0" RASTER (1 row)
次に、次のコマンドを使用してPostgresシェルを終了します;
exit
exit
上記のガイドでは、CentOS8にPostgreSQLを使用してPostGISをインストールする方法を学習しました。これでPostGISを使用してデータベースにジオメトリを追加できます。