# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://homata.gitbook.io/geodjango/hajimeteno/database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
