首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否可以从psql内部导入OSM数据?

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

Stack Overflow用户
提问于 2016-02-23 14:28:06
回答 1查看 69关注 0票数 1

我正在为Dockerfile编写这个Bash脚本:

代码语言:javascript
运行
复制
#!/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之后添加两个导入命令:

代码语言:javascript
运行
复制
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

安德烈·拉姆尼科夫

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-23 15:41:44

您只需使用\i (可能需要将反斜杠加倍)将其包含到这里的文档中,前提是您的post_pl.sql位于当前目录(否则指定完整的路径名)。

代码语言:javascript
运行
复制
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之前。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35580180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档