shapefile导入到pg

导入pg的方法有很多,可以使用常见的GIS软件,如ArcGIS/QGIS。本文使用shp2pgsql导入。

资源

  1. https://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg
  2. https://helpmanual.io/help/shp2pgsql/

帮助

shp2pgsql [OPTIONS] shapefile [schema.]table

参数如下:
在这里插入图片描述
PSQL Connection options:

-h, --host=HOSTNAME      database server host or socket directory
-p, --port=PORT          database server port number
-U, --username=NAME      connect as specified database user
-W, --password           force password prompt (should happen automatically)
-e, --exit-on-error      exit on error, default is to continue

使用示例

这块以Ubuntu16.0.4为例

  1. 生成sql(以root用户执行如下代码)

    shp2pgsql -s 4326:4490 -c  gis_osm_landuse_a_free_1.shp>landuse.shp
    
  2. 导入数据(以postgres用户执行如下代码)

    # 切换到postgres用户
    su - postgres
    # 导入数据
    psql -d osm -U postgres -f /home/yh/Downloads/china-latest-free/landuse.shp -W
    # 输入postgres数据库的密码按回车
    

    执行导入,如图所示:
    在这里插入图片描述

参考:https://www.cnblogs.com/think8848/p/6929351.html

发布了96 篇原创文章 · 获赞 95 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/yh0503/article/details/93894870
今日推荐