postgresql 使用 shp2pgsql 转换 shapefile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6665572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:08:13  来源:igfitidea点击:

Converting shapefiles using shp2pgsql

postgresqlpostgis

提问by John

I know where shp2pgsqlis in the postgresql directory but I'm not sure what commands to use after that. I've read the manual thoroughly, and I am aware of all the arguments and options for the shp2pgsqlcommand. I get the error:

我知道shp2pgsqlpostgresql 目录中的位置,但我不确定在那之后要使用哪些命令。我已经彻底阅读了手册,并且知道该shp2pgsql命令的所有参数和选项。我收到错误:

-bash: shp2pgsql: command not found

Is it a permissions problem perhaps?

也许是权限问题?

采纳答案by John

Solution is to export the path of the program and put it into $PATH variable. Another option is to move the command into directories already contained in PATH such as /usr/bin.

Example

export PATH=/Library/Postgresql/9.0/bin/:$PATH

or

解决方法是将程序的路径导出,放入$PATH变量中。另一种选择是将命令移动到 PATH 中已经包含的目录中,例如 /usr/bin。

示例

导出 PATH=/Library/Postgresql/9.0/bin/:$PATH


  1. echo $PATH to find directories already there

  2. Go to directory with the program in it

  3. mv shp2pgsql /usr/bin for example
  1. echo $PATH 查找已经存在的目录

  2. 转到包含程序的目录

  3. 例如 mv shp2pgsql /usr/bin

回答by Vincent

The right command is ?shp2pgsql?, you have got a typo.

正确的命令是?shp2pgsql?,你有一个错字。

Usage example :

用法示例:

# shp2pgsql -c -D -s 4269 -I shaperoads.shp myschema.roadstable > roads.sql
# psql -d roadsdb -f roads.sql
  • -c creates the table
  • -I creates an index on geometry
  • -D uses dump format
  • -s specify projection srid
  • -c 创建表
  • -我在几何上创建索引
  • -D 使用转储格式
  • -s 指定投影srid

You first generate a sql file, which you then load into your database.

首先生成一个 sql 文件,然后将其加载到数据库中。