0. 官方文档
1. pg数据库的内容,转出为shpFIle,指定GBK编码
ogr2ogr -f "ESRI Shapefile" ./poi_ttt.shp PG:"host=10.1.641.210 user=postgres dbname=tests password=jffff" -lco ENCODING=GBK -sql "SELECT * FROM poi limit 10"
导出为带有srid prj文件的shp命令:
ogr2ogr -f "ESRI Shapefile" -s_srs EPSG:4326 -t_srs EPSG:4326 G:\\DB\\mapbox_mvts\\buia_mapbox_mvts_2.shp PG:"host=10.12.164.20 user=postgres dbname=db password=wfwefw" -sql "SELECT * FROM mapbox_mvts_2"
其中,执行时可能会报错:
Failed to process SRS definition: EPSG:4326
则需要执行一个配置srid目标位置的命令,来设置环境变量,查看这一篇:
ogr2ogr 读取geojson入pg时,报错: Failed to process SRS definition: EPSG:4326_jfqqqqq的博客-CSDN博客
2. shp数据入库pg
导入pg,并且作为multi的geom
ogr2ogr -f "PostgreSQL" "PG:host=10.168.1.1 dbname=db user=postgres password=gg" china_a.shp -nlt PROMOTE_TO_MULTI