---
title: "地理空間ライブラリのインストール"
version: 6.0
locale: ja
source: https://docs.djangoproject.com/ja/6.0/ref/contrib/gis/install/geolibs/
canonical: https://djangodocs.dev/ja/6.0/ref/contrib/gis/install/geolibs/
---
# 地理空間ライブラリのインストール

## 地理空間ライブラリ (Geospatial library)

GeoDjangoは、以下のオープンソースの地理空間ライブラリを使用し、またはそのインターフェースを提供します:

| プログラム | 説明 | 必須 | サポートされるバージョン |
| --- | --- | --- | --- |
| [GEOS](/ja/6.0/ref/contrib/gis/geos/#geos-overview) | Geometry Engine Open Source | Yes | 3.14, 3.13, 3.12, 3.11, 3.10, 3.9, 3.8 |
| [PROJ](https://proj.org/) | Cartographic Projections library | Yes (PostgreSQL and SQLite のみ) | 9.x, 8.x, 7.x, 6.x |
| [GDAL](/ja/6.0/ref/contrib/gis/gdal/#gdal-overview) | 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 |
| [GeoIP](/ja/6.0/ref/contrib/gis/geoip2/#geoip2-overview) | IPベースのジオロケーション ライブラリ | No | 2 |
| [PostGIS](https://postgis.net/) | PostgreSQL の空間拡張機能 | Yes (PostgreSQL のみ) | 3.5, 3.4, 3.3, 3.2, 3.1 |
| [SpatiaLite](https://www.gaia-gis.it/gaia-sins/) | SQLite の空間拡張機能 | Yes (SQLite のみ) | 5.1, 5.0, 4.3 |

これらのライブラリの古いバージョンや新しいバージョンは GeoDjango でも全く問題なく動くかもしれません。あなたの感覚によって異なるかもしれません。

> **Note**
>
> 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`](/ja/6.0/ref/contrib/gis/#module-django.contrib.gis).

Debian/Ubuntuでは、必要な地理空間ライブラリを直接または依存関係によってインストールする以下のパッケージをインストールすることをお勧めします:

```console
$ sudo apt-get install binutils libproj-dev gdal-bin
```

また、 [macOS](/ja/6.0/ref/contrib/gis/install/#macos) や [Windows](/ja/6.0/ref/contrib/gis/install/#windows) を使用している場合は、プラットフォーム別の説明も参照してください。

## ソースコードからビルドする

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.

> **Note**
>
> Linuxプラットフォームでは、各ライブラリをインストールした後に `ldconfig` コマンドを実行する必要があるかもしれません。例えば:
>
> ```shell
> $ sudo make install
> $ sudo ldconfig
> ```

> **Note**
>
> macOSユーザーは、ソフトウェアをソースからコンパイルするために [Xcode](https://developer.apple.com/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をダウンロードし、ソースアーカイブを解凍します:

```shell
$ wget https://download.osgeo.org/geos/geos-X.Y.Z.tar.bz2
$ tar xjf geos-X.Y.Z.tar.bz2
```

次に、GEOSディレクトリに移動し、 `build` フォルダを作成して、その中に移動してください:

```shell
$ cd geos-X.Y.Z
$ mkdir build
$ cd build
```

次に、パッケージをビルドしてインストールします:

```shell
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build .
$ sudo cmake --build . --target install
```

#### トラブルシューティング

##### GEOSライブラリが見つかりません

GeoDjango が GEOS を見つけられない場合、次のエラーが発生します:

```text
ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings.
```

最も一般的な解決策は、[ライブラリの環境設定](/ja/6.0/ref/contrib/gis/install/#libsettings) を適切に設定するか、 *または* 設定で [GEOS\_LIBRARY\_PATH](#geoslibrarypath) を設定することです。

GEOSのバイナリパッケージを使用する場合 (たとえばUbuntu上で) 、 [binutils をインストールする](/ja/6.0/ref/contrib/gis/install/#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`](/ja/6.0/ref/contrib/gis/geos/#std-setting-GEOS_LIBRARY_PATH)
setting may be added to your Django settings file with the full path to the
GEOS C library. For example:

```shell
GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'
```

> **Note**
>
> 設定は **C** 共有ライブラリの *フル* パスである必要があります。つまり、 `libgeos.so` ではなく `libgeos_c.so` を使用することが望まれます。

次も参照してください [ログがGEOS関連のエラーでいっぱいです](/ja/6.0/ref/contrib/gis/geos/#geos-exceptions-in-logfile) 。

### PROJ

[PROJ](https://proj.org/) は、地理空間データを異なる座標参照系に変換するためのライブラリです。

まず、PROJのソースコードをダウンロードします:

```shell
$ wget https://download.osgeo.org/proj/proj-X.Y.Z.tar.gz
```

... と座標変換 (datum shifting) ファイル (PROJ \< 7.x の場合は `proj-datumgrid-X.Y.tar.gz` をダウンロード) [^1]:

```shell
$ wget https://download.osgeo.org/proj/proj-data-X.Y.tar.gz
```

次に、ソースコードアーカイブを解凍し、`data` サブディレクトリ内にある座標変換ファイルを抽出します。これは設定を行う *前* に実行する必要があります。

```shell
$ 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](https://proj.org/community/rfc/rfc-7.html#rfc7) 参照) 。

`CMake` を使用してビルドするには、システムが [build requirements](https://proj.org/install.html#build-requirements) を満たしていることを確認してください。その後、PROJディレクトリ内に `build` フォルダを作成し、そのフォルダに移動します。

```shell
$ cd proj-X.Y.Z
$ mkdir build
$ cd build
```

最後に、PROJの設定、作成、およびインストールを行います:

```shell
$ cmake ..
$ cmake --build .
$ sudo cmake --build . --target install
```

### GDAL

[GDAL](https://gdal.org/) 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](/ja/6.0/ref/contrib/gis/gdal/#gdal-vector-data) capabilities [^2].
[GEOS](#geosbuild) and [PROJ](#proj4) should be installed prior to building GDAL.

まず、最新のGDALリリースバージョンをダウンロードし、アーカイブを解凍します:

```shell
$ 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` フォルダを作成し、その中に移動してください:

```shell
$ cd gdal-X.Y.Z
$ mkdir build
$ cd build
```

最後に、GDAL の設定、ビルド、インストールを行います:

```shell
$ cmake ..
$ cmake --build .
$ sudo cmake --build . --target install
```

問題が発生した場合は、以下のトラブルシューティングのセクションを参照してください。

#### トラブルシューティング

##### GDAL ライブラリが見つかりません

GeoDjango が GDAL ライブラリを見つけられない場合は、 [ライブラリの環境設定](/ja/6.0/ref/contrib/gis/install/#libsettings) を設定するか、*もしくは* 設定で [GDAL\_LIBRARY\_PATH](#gdallibrarypath) を設定してください。

##### `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`](/ja/6.0/ref/contrib/gis/gdal/#std-setting-GDAL_LIBRARY_PATH)
setting may be added to your Django settings file with the full path to
the GDAL library. For example:

```shell
GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'
```

**脚注**

[^1]: The datum shifting files are needed for converting data to and from
certain projections.
For example, the PROJ string for the [Google projection (900913 or 3857)](https://spatialreference.org/ref/epsg/3857/) requires the `null`
grid file only included in the extra datum shifting files. It is easier
to install the shifting files now, than to debug a problem caused
by their absence later.

[^2]: 具体的には、GeoDjango は GDAL のコンポーネントである [OGR](https://gdal.org/user/vector_data_model.html) ライブラリをサポートしています。
