メイン

postgis アーカイブ

2006年11月09日

PostGISへのシェープファイルの追加方法

メモ。


■1. シェープファイルからSQLファイルに変換する
※ -sは座標系SRIDを指定するオプション。4326だとwgs84を指す。

$ shp2pgsql -s 4326 /path/to/hoge_shapefile.shp gis_table gisdb > gis_table.sql


■2. 作成されたSQLファイルをDBに流し込む

$ psql -U postgres -d gisdb -f gis_table.sql
(略)
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
COMMIT


で完了。


2007年03月16日

Mac OS XへのPostGISインストール

Mac OS X(10.4.9)にPostGISを入れたときのログ。
要Darwinports。


■入れるもの
・PostgreSQL 8.1.8
・PostGIS 1.2.1
・PostGISに必要なライブラリ(geos, proj)


■手順1:portで一旦PostGIS及びPostgres及び必要なライブラリを入れる。


$ sudo port install postgis


■手順2:必要なライブラリ以外(=PostGIS & Postgresql)を消す。


$ sudo port uninstall postgis

$ sudo port uninstall postgresql82


■手順3:Postgresqlを入れる


eric$ cd /usr/local/src

eric$ sudo mv postgresql-8.1.8.tar.gz .

eric$ sudo tar xvfz postgresql-8.1.8.tar.gz

eric$ sudo mkdir /usr/local/pgsql-8.1.8

eric$ sudo chown -R postgres:postgres /usr/local/pgsql-8.1.8/

eric$ cd /usr/local/src/postgresql-8.1.8

eric$ sudo ./configure --prefix=/usr/local/pgsql-8.1.8 --with-perl --with-python

eric$ sudo make

eric$ sudo make install


ここで一旦インストールは終了。
続いて管理しやすいようにシンボリックリンクを作成。



eric$ cd /

eric$ sudo mkdir app

eric$ sudo ln -s /usr/local/pgsql-8.1.8 /app/pgsql

eric$ sudo chown -R postgres:postgres /app/pgsql


ユーザpostgresの環境変数をいじる(.zshrcや.bash_profileなど)。



eric$ su postgres

postgres$ vi ~/.zshrc

# setting for postgres
export PATH="$PATH":/app/pgsql/bin
export POSTGRES_HOME=/app/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
:x

postgres$ source ~/.zshrc

postgres$ initdb --no-locale --encoding=UTF-8

postgres$ vi /app/pgsql/data/postgresql.conf
listen_addresses = 'localhost'
port = 5432
:x

postgres$ pg_ctl -w start

postgres$ createdb mygisdb


で一旦オッケイ。


■手順4:PostGISを入れる。PostGISはPostgresのソースディレクトリ内のcontrib内で展開しなければいけないことに注意。また、configure時には明示的に--with-geos=/opt/localと書かなくても、勝手に見つけてくれた。というか--with-geosオプションをつけたらconfigureできなかった。

eric$ cd /usr/local/src/postgresql-8.1.8/contrib
eric$ pwd
/usr/local/src/postgresql-8.1.8/contrib
eric$ sudo wget http://postgis.refractions.net/download/postgis-1.2.1.tar.gz
eric$ sudo tar xvfz postgis-1.2.1.tar.gz
eric$ cd postgis-1.2.1
eric$ sudo ./configure --with-proj=/opt/local
eric$ sudo make
eric$ sudo make install


以降、インストール後にすべきこと。



eric$ su postgres

postgres$ cd /usr/local/src/postgresql-8.1.8/contrib/postgis-1.2.1

postgres$ createlang plpgsql mygisdb

postgres$ psql -d mygisdb -f lwpostgis.sql

postgres$ psql -d mygisdb -f spatial_ref_sys.sql


以上で完了。
自分にオツカレと言いながらコーヒーを飲みましょう。

About postgis

ブログ「what a bringdown」のカテゴリ「postgis」に投稿されたすべてのエントリーのアーカイブのページです。過去のものから新しいものへ順番に並んでいます。

前のカテゴリはmysqlです。

次のカテゴリはrubyです。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。