> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 地理的オブジェクトや位置を表現するために ClickHouse で使用される幾何データ型に関するドキュメント

# 幾何

ClickHouse は、位置や土地などの地理的オブジェクトを表現するためのデータ型をサポートしています。

**関連項目**

* [シンプルな地理的地物の表現](https://en.wikipedia.org/wiki/GeoJSON).

<div id="point">
  ## Point
</div>

`Point` は X 座標と Y 座標で表され、[Tuple](/ja/reference/data-types/tuple)([Float64](/ja/reference/data-types/float), [Float64](/ja/reference/data-types/float)) として格納されます。

**例**

```sql title="Query" theme={null}
CREATE TABLE geo_point (p Point) ENGINE = Memory();
INSERT INTO geo_point VALUES((10, 10));
SELECT p, toTypeName(p) FROM geo_point;
```

```text title="Response" theme={null}
┌─p───────┬─toTypeName(p)─┐
│ (10,10) │ Point         │
└─────────┴───────────────┘
```

<div id="ring">
  ## Ring
</div>

`Ring` は、穴のない単純な多角形を点の配列として格納したものです: [Array](/ja/reference/data-types/array)([Point](#point)).

**例**

```sql title="Query" theme={null}
CREATE TABLE geo_ring (r Ring) ENGINE = Memory();
INSERT INTO geo_ring VALUES([(0, 0), (10, 0), (10, 10), (0, 10)]);
SELECT r, toTypeName(r) FROM geo_ring;
```

```text title="Response" theme={null}
┌─r─────────────────────────────┬─toTypeName(r)─┐
│ [(0,0),(10,0),(10,10),(0,10)] │ Ring          │
└───────────────────────────────┴───────────────┘
```

<div id="linestring">
  ## LineString
</div>

`LineString` は、点の配列として格納される線形データです: [Array](/ja/reference/data-types/array)([Point](#point))。

**例**

```sql title="Query" theme={null}
CREATE TABLE geo_linestring (l LineString) ENGINE = Memory();
INSERT INTO geo_linestring VALUES([(0, 0), (10, 0), (10, 10), (0, 10)]);
SELECT l, toTypeName(l) FROM geo_linestring;
```

```text title="Response" theme={null}
┌─r─────────────────────────────┬─toTypeName(r)─┐
│ [(0,0),(10,0),(10,10),(0,10)] │ LineString    │
└───────────────────────────────┴───────────────┘
```

<div id="multilinestring">
  ## MultiLineString
</div>

`MultiLineString` は、複数の線を `LineString` の配列として格納する型です: [Array](/ja/reference/data-types/array)([LineString](#linestring))。

**例**

```sql title="Query" theme={null}
CREATE TABLE geo_multilinestring (l MultiLineString) ENGINE = Memory();
INSERT INTO geo_multilinestring VALUES([[(0, 0), (10, 0), (10, 10), (0, 10)], [(1, 1), (2, 2), (3, 3)]]);
SELECT l, toTypeName(l) FROM geo_multilinestring;
```

```text title="Response" theme={null}
┌─l───────────────────────────────────────────────────┬─toTypeName(l)───┐
│ [[(0,0),(10,0),(10,10),(0,10)],[(1,1),(2,2),(3,3)]] │ MultiLineString │
└─────────────────────────────────────────────────────┴─────────────────┘
```

<div id="polygon">
  ## Polygon
</div>

`Polygon` は、リングの配列 [Array](/ja/reference/data-types/array)([Ring](#ring)) として格納される、穴を含む多角形です。外側の配列の最初の要素が多角形の外周を表し、それ以降のすべての要素が穴を表します。

**例**

これは穴を 1 つ持つ多角形です:

```sql title="Query" theme={null}
CREATE TABLE geo_polygon (pg Polygon) ENGINE = Memory();
INSERT INTO geo_polygon VALUES([[(20, 20), (50, 20), (50, 50), (20, 50)], [(30, 30), (50, 50), (50, 30)]]);
SELECT pg, toTypeName(pg) FROM geo_polygon;
```

```text title="Response" theme={null}
┌─pg────────────────────────────────────────────────────────────┬─toTypeName(pg)─┐
│ [[(20,20),(50,20),(50,50),(20,50)],[(30,30),(50,50),(50,30)]] │ Polygon        │
└───────────────────────────────────────────────────────────────┴────────────────┘
```

<div id="multipolygon">
  ## MultiPolygon
</div>

`MultiPolygon` は複数のポリゴンで構成され、ポリゴンの配列として格納されます: [Array](/ja/reference/data-types/array)([Polygon](#polygon))。

**例**

このマルチポリゴンは 2 つの独立したポリゴンで構成されており、1 つ目には穴がなく、2 つ目には 1 つの穴があります:

```sql title="Query" theme={null}
CREATE TABLE geo_multipolygon (mpg MultiPolygon) ENGINE = Memory();
INSERT INTO geo_multipolygon VALUES([[[(0, 0), (10, 0), (10, 10), (0, 10)]], [[(20, 20), (50, 20), (50, 50), (20, 50)],[(30, 30), (50, 50), (50, 30)]]]);
SELECT mpg, toTypeName(mpg) FROM geo_multipolygon;
```

```text title="Response" theme={null}
┌─mpg─────────────────────────────────────────────────────────────────────────────────────────────┬─toTypeName(mpg)─┐
│ [[[(0,0),(10,0),(10,10),(0,10)]],[[(20,20),(50,20),(50,50),(20,50)],[(30,30),(50,50),(50,30)]]] │ MultiPolygon    │
└─────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┘
```

<div id="geometry">
  ## Geometry
</div>

`Geometry` は、上記すべての型に共通する型です。これらの型からなる Variant 型と同等です。

**例**

```sql title="Query" theme={null}
CREATE TABLE IF NOT EXISTS geo (geom Geometry) ENGINE = Memory();
INSERT INTO geo VALUES ((1, 2));
SELECT * FROM geo;
```

```text title="Response" theme={null}
   ┌─geom──┐
1. │ (1,2) │
   └───────┘
```

```sql title="Query" theme={null}
CREATE TABLE IF NOT EXISTS geo_dst (geom Geometry) ENGINE = Memory();

CREATE TABLE IF NOT EXISTS geo (geom String, id Int) ENGINE = Memory();
INSERT INTO geo VALUES ('POLYGON((1 0,10 0,10 10,0 10,1 0),(4 4,5 4,5 5,4 5,4 4))', 1);
INSERT INTO geo VALUES ('POINT(0 0)', 2);
INSERT INTO geo VALUES ('MULTIPOLYGON(((1 0,10 0,10 10,0 10,1 0),(4 4,5 4,5 5,4 5,4 4)),((-10 -10,-10 -9,-9 10,-10 -10)))', 3);
INSERT INTO geo VALUES ('LINESTRING(1 0,10 0,10 10,0 10,1 0)', 4);
INSERT INTO geo VALUES ('MULTILINESTRING((1 0,10 0,10 10,0 10,1 0),(4 4,5 4,5 5,4 5,4 4))', 5);
INSERT INTO geo_dst SELECT readWKT(geom) FROM geo ORDER BY id;

SELECT * FROM geo_dst;
```

```text title="Response" theme={null}
   ┌─geom─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
1. │ [[(1,0),(10,0),(10,10),(0,10),(1,0)],[(4,4),(5,4),(5,5),(4,5),(4,4)]]                                            │
2. │ (0,0)                                                                                                            │
3. │ [[[(1,0),(10,0),(10,10),(0,10),(1,0)],[(4,4),(5,4),(5,5),(4,5),(4,4)]],[[(-10,-10),(-10,-9),(-9,10),(-10,-10)]]] │
4. │ [(1,0),(10,0),(10,10),(0,10),(1,0)]                                                                              │
5. │ [[(1,0),(10,0),(10,10),(0,10),(1,0)],[(4,4),(5,4),(5,5),(4,5),(4,4)]]                                            │
   └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

<div id="related-content">
  ## 関連コンテンツ
</div>

* [大規模な実世界データセットを探る：ClickHouseで見る100年以上の気象記録](https://clickhouse.com/blog/real-world-data-noaa-climate-data)
