> For the complete documentation index, see [llms.txt](https://homata.gitbook.io/geodjango/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://homata.gitbook.io/geodjango/hajimeteno/database.md).

# Geoデータベース

## GeoDjangoサポート 空間データベース

| Database   | Library Requirements           | Supported Versions | Notes                                     |
| ---------- | ------------------------------ | ------------------ | ----------------------------------------- |
| PostgreSQL | GEOS, GDAL, PROJ.4, PostGIS    | 9.4+               | Requires PostGIS.                         |
| MySQL      | GEOS, GDAL                     | 5.6+               | Not OGC-compliant; limited functionality. |
| Oracle     | GEOS, GDAL                     | 12.1+              | XE not supported.                         |
| SQLite     | GEOS, GDAL, PROJ.4, SpatiaLite | 3.7.15+            | Requires SpatiaLite 4.1+                  |

**Note**: PostGIS is recommended, because it is the most mature and feature-rich open source spatial database.

&#x20;\* <https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#requirements>

## PostGIS

* PostGIS <http://postgis.refractions.net/> はカナダにあるRefractions Research Inc.が開発したもの。
* GEO界隈ではデファクトのデータベース
* PostgreSQLに地理空間情報を扱うための拡張機能。
  * PostgreSQLにExtension(postgis)を追加する
* データベースにGEOMETRY型が追加される
  * POINT(点)、LINESTRING(線), POLYGON(面)が基本となるる
* 幾何関数という空間演算用の関数が追加される(ST\_xxx)
* 空間インデックスをGEOMETRY型につける

### PostGISの空間演算用の関数

* PostGISの地理空間関数。ST\_xxxxとSTで始まるものが多い

  SQL文の例

  > SELECT ST\_Area(geog) FROM somegeogtable; SELECT road\_id, ST\_AsText(road\_geom) AS geom, road\_name FROM roads;

**関数例)**<br>

* ST\_Contains() - AがBを含んでいるのかのかチェックする
* ST\_Intersects() - AとBが重なっているのかチェックする
* ST\_Distance () – AとBの距離を求める
* ST\_Area () – ポリゴンの面積を求める

  \
  &#x20;: <br>

![](/files/-LF0cQdWGPf1ZaylpP6b)

&#x20;\* <https://qiita.com/yellow\\_73/items/dc7c5e1ebe95625aee60\\>
&#x20;\* <https://www.finds.jp/docs/pgisman/1.5.1/reference.html\\>
&#x20;\* <http://cse.naro.affrc.go.jp/yellow/pgisman/2.0.0/postgis.html#Spatial\\_Relationships\\_Measurements>

### PostGISの空間演算用の関数

![](/files/-LF0cQdY4lT09r4g2ojW)

![](/files/-LF0cQd_kEANI87sKwlE)

&#x20;\* <https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoquerysets/\\>
&#x20;\* <https://www.finds.jp/docs/pgisman/1.5.1/reference.html>
