GISっ子/コンテナでshp2pgsql
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
* はじめに [#d7dd2c42]
[[空間データベース · GIS実習オープン教材>https://gis...
「PostGIS x.x Shapefile and DBF Loader Exporter」を使わず...
PosgGIS自体もコンテナで起動してしまいます
* PostGIS, pgAdmin, (と Adminer)を立ち上げる [#ne13ae5f]
[[PostGISワークショップをコンテナで試す>GISっ子/PostGISワ...
#prism(bash){{{
# Pod(コンテナ)起動
wget -qO docker-compose.yml 'https://gist.github.com/kema...
podman-compose up -d
}}}
- 5432/tcp: PosgGIS
- 8000/tcp: pgAdmin
- 8080/tcp: Adminer
id / pw はいずれも postgres / example です
ここまで来たら [[空間データベース · GIS実習オープン...
* PostGISに接続するコンテナを起動 [#hb8060f4]
ホストのファイルを操作できるよう、ここではカレントディレ...
#prism(bash){{{
# ホストのカレントディレクトリに shp ファイルがある
$ ls
README.md station.csv station.prj station.shp tokyo...
station.cpg station.dbf station.qpj station.shx tokyo...
# コンテナを起動し、/mnt のファイルを確認
$ podman run --rm -it -v .:/mnt postgis:12-3.0 bash
root@c119a1ba1f99:/# ls /mnt
README.md station.csv station.prj station.shp tokyo...
station.cpg station.dbf station.qpj station.shx tokyo...
}}}
* shp2pgsqlコマンドをインストール [#fea37848]
shp2pgsql は postgis パッケージにあります
#prism(bash){{{
root@c119a1ba1f99:/# apt update
Get:1 http://deb.debian.org/debian buster InRelease [121 ...
(略)
All packages are up to date.
root@c119a1ba1f99:/# apt -y install postgis
Reading package lists... Done
(略)
Setting up postgis (3.0.1+dfsg-4.pgdg100+1) ...
Setting up postgis-doc (3.0.1+dfsg-4.pgdg100+1) ...
}}}
* shpファイルを新しいテーブルにインポート [#fedab580]
#prism(bash){{{
# /mnt に移動
root@c119a1ba1f99:/# cd /mnt
# tokyo.shp をインポート
# -h 192.168.10.151 : PosgGISのIPアドレス(=母艦のIPア...
# -d tokyo : データベース名(GIS実習オープン教...
root@c119a1ba1f99:/mnt# shp2pgsql -s 2451 tokyo.shp pub...
Field area is an FTDouble with width 11 and precision 3
Field density is an FTDouble with width 11 and precision 3
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
SET
SET
BEGIN
CREATE TABLE
ALTER TABLE
addgeometrycolumn
-------------------------------------------------------
public.tokyo.geom SRID:2451 TYPE:MULTIPOLYGON DIMS:2
(1 row)
INSERT 0 1
INSERT 0 1
(略)
INSERT 0 1
COMMIT
ANALYZE
# station.shp をインポート
# -h 192.168.10.151 : PosgGISのIPアドレス(=母艦のIPア...
# -d tokyo : データベース名(GIS実習オープン教...
root@c119a1ba1f99:/mnt# shp2pgsql -s 2451 station.shp pub...
Shapefile type: Point
Postgis type: POINT[2]
SET
SET
BEGIN
CREATE TABLE
ALTER TABLE
addgeometrycolumn
--------------------------------------------------
public.station.geom SRID:2451 TYPE:POINT DIMS:2
(1 row)
INSERT 0 1
INSERT 0 1
(略)
INSERT 0 1
COMMIT
ANALYZE
# コンテナ停止
root@c119a1ba1f99:/mnt# exit
exit
}}}
* 一気に流す方法 [#h892f629]
podman run でシェルを起動し、ヒアドキュメントでシェルスク...
#prism(bash){{{
podman run --rm -i -v .:/mnt postgis:12-3.0 bash -x <<'...'
apt update
apt -y install postgis
shp2pgsql -s 2451 /mnt/tokyo.shp public.tokyo | psql ...
shp2pgsql -s 2451 /mnt/station.shp public.station | psql ...
...
}}}
* おまけ:new_geomカラムの追加 [#mc4c54fd]
[[空間データベース · GIS実習オープン教材>https://gis...
CREATE INDEX new_geom ON station USING GiST(new_geom);を...
これを回避するには、予め new_geom カラムを追加すればOKです
#prism(SQL){{{
ALTER TABLE station ADD new_geom geometry(Point,2451);
}}}
その後 CREATE INDEX new_geom ON station USING GiST(new_ge...
終了行:
* はじめに [#d7dd2c42]
[[空間データベース · GIS実習オープン教材>https://gis...
「PostGIS x.x Shapefile and DBF Loader Exporter」を使わず...
PosgGIS自体もコンテナで起動してしまいます
* PostGIS, pgAdmin, (と Adminer)を立ち上げる [#ne13ae5f]
[[PostGISワークショップをコンテナで試す>GISっ子/PostGISワ...
#prism(bash){{{
# Pod(コンテナ)起動
wget -qO docker-compose.yml 'https://gist.github.com/kema...
podman-compose up -d
}}}
- 5432/tcp: PosgGIS
- 8000/tcp: pgAdmin
- 8080/tcp: Adminer
id / pw はいずれも postgres / example です
ここまで来たら [[空間データベース · GIS実習オープン...
* PostGISに接続するコンテナを起動 [#hb8060f4]
ホストのファイルを操作できるよう、ここではカレントディレ...
#prism(bash){{{
# ホストのカレントディレクトリに shp ファイルがある
$ ls
README.md station.csv station.prj station.shp tokyo...
station.cpg station.dbf station.qpj station.shx tokyo...
# コンテナを起動し、/mnt のファイルを確認
$ podman run --rm -it -v .:/mnt postgis:12-3.0 bash
root@c119a1ba1f99:/# ls /mnt
README.md station.csv station.prj station.shp tokyo...
station.cpg station.dbf station.qpj station.shx tokyo...
}}}
* shp2pgsqlコマンドをインストール [#fea37848]
shp2pgsql は postgis パッケージにあります
#prism(bash){{{
root@c119a1ba1f99:/# apt update
Get:1 http://deb.debian.org/debian buster InRelease [121 ...
(略)
All packages are up to date.
root@c119a1ba1f99:/# apt -y install postgis
Reading package lists... Done
(略)
Setting up postgis (3.0.1+dfsg-4.pgdg100+1) ...
Setting up postgis-doc (3.0.1+dfsg-4.pgdg100+1) ...
}}}
* shpファイルを新しいテーブルにインポート [#fedab580]
#prism(bash){{{
# /mnt に移動
root@c119a1ba1f99:/# cd /mnt
# tokyo.shp をインポート
# -h 192.168.10.151 : PosgGISのIPアドレス(=母艦のIPア...
# -d tokyo : データベース名(GIS実習オープン教...
root@c119a1ba1f99:/mnt# shp2pgsql -s 2451 tokyo.shp pub...
Field area is an FTDouble with width 11 and precision 3
Field density is an FTDouble with width 11 and precision 3
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
SET
SET
BEGIN
CREATE TABLE
ALTER TABLE
addgeometrycolumn
-------------------------------------------------------
public.tokyo.geom SRID:2451 TYPE:MULTIPOLYGON DIMS:2
(1 row)
INSERT 0 1
INSERT 0 1
(略)
INSERT 0 1
COMMIT
ANALYZE
# station.shp をインポート
# -h 192.168.10.151 : PosgGISのIPアドレス(=母艦のIPア...
# -d tokyo : データベース名(GIS実習オープン教...
root@c119a1ba1f99:/mnt# shp2pgsql -s 2451 station.shp pub...
Shapefile type: Point
Postgis type: POINT[2]
SET
SET
BEGIN
CREATE TABLE
ALTER TABLE
addgeometrycolumn
--------------------------------------------------
public.station.geom SRID:2451 TYPE:POINT DIMS:2
(1 row)
INSERT 0 1
INSERT 0 1
(略)
INSERT 0 1
COMMIT
ANALYZE
# コンテナ停止
root@c119a1ba1f99:/mnt# exit
exit
}}}
* 一気に流す方法 [#h892f629]
podman run でシェルを起動し、ヒアドキュメントでシェルスク...
#prism(bash){{{
podman run --rm -i -v .:/mnt postgis:12-3.0 bash -x <<'...'
apt update
apt -y install postgis
shp2pgsql -s 2451 /mnt/tokyo.shp public.tokyo | psql ...
shp2pgsql -s 2451 /mnt/station.shp public.station | psql ...
...
}}}
* おまけ:new_geomカラムの追加 [#mc4c54fd]
[[空間データベース · GIS実習オープン教材>https://gis...
CREATE INDEX new_geom ON station USING GiST(new_geom);を...
これを回避するには、予め new_geom カラムを追加すればOKです
#prism(SQL){{{
ALTER TABLE station ADD new_geom geometry(Point,2451);
}}}
その後 CREATE INDEX new_geom ON station USING GiST(new_ge...
ページ名: