LoginSignup
20
18

More than 5 years have passed since last update.

HomebrewでPostGISをインストール、利用するまで

Posted at

PostGISのインストール

Homebrewからインストールを行う。

$ brew install postgis

なお、このサイトを参考にした。

データベースの作成

$ createdb -E utf8 -O postgres -U postgres gisdb

作成したデータベースは、以下のコマンドから確認できる。

$ psql -l

データベースへの接続確認

$ psql -U postgres -d gisdb

PostGISを有効化する

Extensionを作成する

-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

PostGISの動作確認

-- Create table with spatial column
CREATE TABLE mytable ( 
  id SERIAL PRIMARY KEY,
  geom GEOMETRY(Point, 26910),
  name VARCHAR(128)
); 

-- Add a spatial index
CREATE INDEX mytable_gix
  ON mytable 
  USING GIST (geom); 

-- Add a point
INSERT INTO mytable (geom) VALUES (
  ST_GeomFromText('POINT(0 0)', 26910)
);

-- Query for nearby points
SELECT id, name
FROM mytable
WHERE ST_DWithin(
  geom, 
  ST_GeomFromText('POINT(0 0)', 26910),
  1000
); 

上記をQGIS等で確認し、正しく表示されればOK。

20
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
18