geometry型をちょっと試してみる
geometry型をちょっと使ってみたかったので、以下のサイトよりdownload
Postgres.app – the easiest way to get started with PostgreSQL on the Mac
Download後、Postgres.appを起動、以下の画面で「Open psql」ボタンをクリック
最初にはまったのが、そのままではgeometry型が使えなかったことです。
以下のコマンドでPostGISを使えるようにしないといけないようです。
create extension postgis;
- まずテーブルを作成
create table Address( country_code smallint, address varchar(300), geo_point geometry(Point) );
- 作成したテーブルを確認
\d Address
- データを登録
大阪城の経度、緯度を使用、「4326」はSRID
空間参照 ID(SRID)は、特定の座標系、許容値、および解像度に関連付けられた一意の ID です(ここArcGIS ヘルプ 10.1を参考)
INSERT INTO Address VALUES ( 81, ‘osaka’, ST_GeomFromText('POINT(34.6872 135.5258)’, 4326) );
- データを検索
select country_code,address,point(geo_point) from address;