IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

MySQLでのGeometry型のselect

テキストで取得

mysql-sql> select st_astext(geo) from geo_tbl;
+--------------------------------------------------------------------+
| st_astext(geo)                                                     |
+--------------------------------------------------------------------+
| POINT(30 10)                                                       |
| LINESTRING(30 10,10 30,40 40)                                      |
| POLYGON((30 10,40 40,20 40,10 20,30 10))                           |
| POLYGON((35 10,45 45,15 40,10 20,35 10),(20 30,35 35,30 20,20 30)) |
| POINT(1.5 2.5)                                                     |
| POINT(1.5 2.5)                                                     |
| POINT(1.5 2.5)                                                     |
| POINT(1.5 2.5)                                                     |
| POINT(1.5 2.5)                                                     |
+--------------------------------------------------------------------+
9 rows in set (0.01 sec)
mysql-sql>

GeoJSONで取得

mysql-sql> select st_asGeojson(geo) from geo_tbl;
+------------------------------------------------------------------------------------------------------------------------------------+
| st_asGeojson(geo)                                                                                                                  |
+------------------------------------------------------------------------------------------------------------------------------------+
| {"type": "Point", "coordinates": [30, 10]}                                                                                         |
| {"type": "LineString", "coordinates": [[30, 10], [10, 30], [40, 40]]}                                                              |
| {"type": "Polygon", "coordinates": [[[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]]}                                           |
| {"type": "Polygon", "coordinates": [[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]]]} |
| {"type": "Point", "coordinates": [1.5, 2.5]}                                                                                       |
| {"type": "Point", "coordinates": [1.5, 2.5]}                                                                                       |
| {"type": "Point", "coordinates": [1.5, 2.5]}                                                                                       |
| {"type": "Point", "coordinates": [1.5, 2.5]}                                                                                       |
| {"type": "Point", "coordinates": [1.5, 2.5]}                                                                                       |
+------------------------------------------------------------------------------------------------------------------------------------+
9 rows in set (0.02 sec)