地理空間ライブラリのインストール¶
地理空間ライブラリ (Geospatial library)¶
GeoDjangoは、以下のオープンソースの地理空間ライブラリを使用し、またはそのインターフェースを提供します:
プログラム |
説明 |
必須 |
サポートされるバージョン |
|---|---|---|---|
Geometry Engine Open Source |
Yes |
3.14, 3.13, 3.12, 3.11, 3.10, 3.9, 3.8 |
|
Cartographic Projections library |
Yes (PostgreSQL and SQLite のみ) |
9.x, 8.x, 7.x, 6.x |
|
Geospatial Data Abstraction Library |
Yes |
3.11, 3.10, 3.9, 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1 |
|
IPベースのジオロケーション ライブラリ |
No |
2 |
|
PostgreSQL の空間拡張機能 |
Yes (PostgreSQL のみ) |
3.5, 3.4, 3.3, 3.2, 3.1 |
|
SQLite の空間拡張機能 |
Yes (SQLite のみ) |
5.1, 5.0, 4.3 |
これらのライブラリの古いバージョンや新しいバージョンは GeoDjango でも全く問題なく動くかもしれません。あなたの感覚によって異なるかもしれません。
注釈
The GeoDjango interfaces to GEOS, GDAL, and GeoIP may be used
independently of Django. In other words, no database or settings file
required -- import them as normal from django.contrib.gis.
Debian/Ubuntuでは、必要な地理空間ライブラリを直接または依存関係によってインストールする以下のパッケージをインストールすることをお勧めします:
$ sudo apt-get install binutils libproj-dev gdal-bin
ソースコードからビルドする¶
When installing from source on UNIX and GNU/Linux systems, please follow the installation instructions carefully, and install the libraries in the given order. If using MySQL or Oracle as the spatial database, only GEOS is required.
注釈
Linuxプラットフォームでは、各ライブラリをインストールした後に ldconfig コマンドを実行する必要があるかもしれません。例えば:
$ sudo make install
$ sudo ldconfig
注釈
macOSユーザーは、ソフトウェアをソースからコンパイルするために Xcode をインストールする必要があります。
GEOS¶
GEOS is a C++ library for performing geometric operations, and is the default
internal geometry representation used by GeoDjango (it's behind the "lazy"
geometries). Specifically, the C API library is called (e.g., libgeos_c.so)
directly from Python using ctypes.
まず、GEOSのウェブサイトからGEOSをダウンロードし、ソースアーカイブを解凍します:
$ wget https://download.osgeo.org/geos/geos-X.Y.Z.tar.bz2
$ tar xjf geos-X.Y.Z.tar.bz2
次に、GEOSディレクトリに移動し、 build フォルダを作成して、その中に移動してください:
$ cd geos-X.Y.Z
$ mkdir build
$ cd build
次に、パッケージをビルドしてインストールします:
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build .
$ sudo cmake --build . --target install
トラブルシューティング¶
GEOSライブラリが見つかりません¶
GeoDjango が GEOS を見つけられない場合、次のエラーが発生します:
ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
最も一般的な解決策は、ライブラリの環境設定 を適切に設定するか、 または 設定で GEOS_LIBRARY_PATH を設定することです。
GEOSのバイナリパッケージを使用する場合 (たとえばUbuntu上で) 、 binutils をインストールする が必要になる可能性があります。
GEOS_LIBRARY_PATH¶
If your GEOS library is in a non-standard location, or you don't want to
modify the system's library path then the GEOS_LIBRARY_PATH
setting may be added to your Django settings file with the full path to the
GEOS C library. For example:
GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
注釈
設定は C 共有ライブラリの フル パスである必要があります。つまり、 libgeos.so ではなく libgeos_c.so を使用することが望まれます。
次も参照してください ログがGEOS関連のエラーでいっぱいです 。
PROJ¶
PROJ は、地理空間データを異なる座標参照系に変換するためのライブラリです。
まず、PROJのソースコードをダウンロードします:
$ wget https://download.osgeo.org/proj/proj-X.Y.Z.tar.gz
... と座標変換 (datum shifting) ファイル (PROJ < 7.x の場合は proj-datumgrid-X.Y.tar.gz をダウンロード) [1]:
$ wget https://download.osgeo.org/proj/proj-data-X.Y.tar.gz
次に、ソースコードアーカイブを解凍し、data サブディレクトリ内にある座標変換ファイルを抽出します。これは設定を行う 前 に実行する必要があります。
$ tar xzf proj-X.Y.Z.tar.gz
$ cd proj-X.Y.Z/data
$ tar xzf ../../proj-data-X.Y.tar.gz
$ cd ../..
PROJ 9.x以降のリリースでは、CMake を使用したビルドのみがサポートされます (PROJ RFC-7 参照) 。
CMake を使用してビルドするには、システムが build requirements を満たしていることを確認してください。その後、PROJディレクトリ内に build フォルダを作成し、そのフォルダに移動します。
$ cd proj-X.Y.Z
$ mkdir build
$ cd build
最後に、PROJの設定、作成、およびインストールを行います:
$ cmake ..
$ cmake --build .
$ sudo cmake --build . --target install
GDAL¶
GDAL is an excellent open source geospatial library that has support for reading most vector and raster spatial data formats. Currently, GeoDjango only supports GDAL's vector data capabilities [2]. GEOS and PROJ should be installed prior to building GDAL.
まず、最新のGDALリリースバージョンをダウンロードし、アーカイブを解凍します:
$ wget https://download.osgeo.org/gdal/X.Y.Z/gdal-X.Y.Z.tar.gz
$ tar xzf gdal-X.Y.Z.tar.gz
GDAL 3.6.x 以降では、リリースは CMake を使用したビルドのみをサポートしています。 CMake を使ってビルドするには、GDAL ディレクトリに build フォルダを作成し、その中に移動してください:
$ cd gdal-X.Y.Z
$ mkdir build
$ cd build
最後に、GDAL の設定、ビルド、インストールを行います:
$ cmake ..
$ cmake --build .
$ sudo cmake --build . --target install
問題が発生した場合は、以下のトラブルシューティングのセクションを参照してください。
トラブルシューティング¶
GDAL ライブラリが見つかりません¶
GeoDjango が GDAL ライブラリを見つけられない場合は、 ライブラリの環境設定 を設定するか、もしくは 設定で GDAL_LIBRARY_PATH を設定してください。
GDAL_LIBRARY_PATH¶
If your GDAL library is in a non-standard location, or you don't want to
modify the system's library path then the GDAL_LIBRARY_PATH
setting may be added to your Django settings file with the full path to
the GDAL library. For example:
GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
脚注