繁体   English   中英

是否可以从psql内部导入OSM数据?

[英]Is it possible to import OSM data from inside psql?

我正在为Dockerfile开发此Bash脚本:

#!/bin/bash
set -e

gosu postgres postgres --single -jE <<-EOL
  CREATE USER "$OSM_USER";
EOL

gosu postgres postgres --single -jE <<-EOL
  CREATE DATABASE "$OSM_DB";
EOL

gosu postgres postgres --single -jE <<-EOL
  GRANT ALL ON DATABASE "$OSM_DB" TO "$OSM_USER";
EOL

# Postgis extension cannot be created in single user mode.
# So we will do it the kludge way by starting the server,
# updating the DB, then shutting down the server so the
# rest of the docker-postgres init scripts can finish.

gosu postgres pg_ctl -w start
gosu postgres psql "$OSM_DB" <<-EOL
  CREATE EXTENSION postgis;
  CREATE EXTENSION hstore;
  ALTER TABLE geometry_columns OWNER TO "$OSM_USER";
  ALTER TABLE spatial_ref_sys OWNER TO "$OSM_USER";
EOL
gosu postgres pg_ctl stop

我想在ALTER TABLE之后添加两个导入命令:

shp2pgsql -I -s 4326 -W "latin1" post_pl.shp post_pl  > post_pl.sql
psql -h 172.17.0.2 -U postgres -d gis -f post_pl.sql

osm2pgsql -H 172.17.0.2  -U postgres -d gis --hstore -s -S `./osm_stylesheet ./hessen-latest.osm.pbf`

我的问题是,行得通吗? 进入psql时可以导入数据吗? 如果是的话,我该怎么办?

TNX

安德烈·拉姆尼科夫(Andrey Ramnikov)

您可以使用\\i将其包含在here-document中(您可能需要将反斜杠加倍),假设post_pl.sql位于当前目录中(否则指定完整路径名)

gosu postgres pg_ctl -w start
gosu postgres psql "$OSM_DB" <<-EOL
  CREATE EXTENSION postgis;
  CREATE EXTENSION hstore;
  ALTER TABLE geometry_columns OWNER TO "$OSM_USER";
  ALTER TABLE spatial_ref_sys OWNER TO "$OSM_USER";
  \\connect gis -- Assuming a different DB is needed here ...
  \\i post_pl.sql
EOL
gosu postgres pg_ctl stop

我在这里假设shp2pgsql不需要数据库。 确实需要数据库的osm2pgsql可以放在EOL ,就在pg_ctl stop之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM