SHP导入POSTGIS数据库
引用
直接导入数据库 shp2pgsql -I -s 2437 -W GBK shop_point.shp public.ntable | psql -U postgres -w -d jwsz 导出sql再导入数据库 shp2pgsql -s "2437" -W "GBK" -I D:\shop_point.shp newTable > D:\shop_point.sql psql -U postgres -f D:/shop_point.sql jwsz -P 123456
POSTGIS数据库导出SHP:生成shp数据 //windows导出乱码解决办法:在环境变量中设置 PGCLIENTENCODING=GBK或PGCLIENTENCODING=GB18030,然后执行pgsql2shp,导出的shape文件中,属性数据编码正确是GBK的,没有显示乱码。
引用
pgsql2shp -f shop_point -h localhost -u postgres -P 123456 jwsz public.shop_point pgsql2shp -g the_geom -f D:\shp.shp -u postgres -P 123456 -h 127.0.0.1 jwsz "select the_geom,name from shop_point" pgsql2shp -f shop_point -h localhost -u postgres -P 123456 jwsz "select the_geom,name from shop_point"
引用
@echo -d 删除现有的表,并重新创建进行插入 @echo -a 向现有的表中插入,表必须存在 @echo -c 创建表并进行插入 @echo -p 只进行表的创建
shp2pgsql -s 4326 -W GBK CheckWell_point.shp public.CheckWell_point>CheckWell_point.sql
shp2pgsql -s 4326 -W GBK CheckWell_point.shp public.CheckWell_point psql -U postgres -w -d jwsz
@echo 导入 shp2pgsql -s 4326 -a -W GBK CheckWell_point.shp public.CheckWell_point>CheckWell_point.sql psql -U postgres -w -d jwsz -f CheckWell_point.sql -e @echo 导出 pgsql2shp.exe -f CheckWell_point -P 123456 -u postgres jwsz public.CheckWell_point
@echo 删除并更新 点数据 shp2pgsql -s 4326 -d -W GBK CheckWell_point.shp public.CheckWell_point|psql -U postgres -w -d jwsz @echo 尝试创建 线数据 shp2pgsql -s 4326 -p -W GBK CableLine_polyline.shp public.CableLine_polyline|psql -U postgres -w -d jwsz @echo 数据追加 线数据 shp2pgsql -s 4326 -a -W GBK CableLine_polyline.shp public.CableLine_polyline|psql -U postgres -w -d jwsz
@echo 尝试创建 面数据 shp2pgsql -s 4326 -p -W GBK Bridge_region.shp public.Bridge_region|psql -U postgres -w -d jwsz @echo 数据追加 面数据 shp2pgsql -s 4326 -a -W GBK Bridge_region.shp public.Bridge_region|psql -U postgres -w -d jwsz pause
shp2pgsql命令相关参数
引用
RCSID: $Id: shp2pgsql-core.h 5983 2010-09-19 11:27:05Z mcayland $ RELEASE: 1.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 USAGE: shp2pgsql [<options>] <shapefile> [<schema>.]<table> OPTIONS: -s <srid> Set the SRID field. Defaults to -1. (-d|a|c|p) These are mutually exclusive options: -d Drops the table, then recreates it and populates it with current shape file data. -a Appends shape file into current table, must be exactly the same table schema. -c Creates a new table and populates it, this is the default if you do not specify any options. -p Prepare mode, only creates the table. -g <geocolumn> Specify the name of the geometry/geography column (mostly useful in append mode). -D Use postgresql dump format (defaults to SQL insert statments. -G Use geography type (requires lon/lat data). -k Keep postgresql identifiers case. -i Use int4 type for all integer dbf fields. -I Create a spatial index on the geocolumn. -S Generate simple geometries instead of MULTI geometries. -W <encoding> Specify the character encoding of Shape‘s attribute column. (default : "WINDOWS-1252") -N <policy> NULL geometries handling policy (insert*,skip,abort) -n Only import DBF file. -? Display this help screen.
pgsql2shp命令相关参数
引用
RCSID: $Id: pgsql2shp.c 5451 2010-03-22 19:38:40Z pramsey $ RELEASE: 1.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 USAGE: pgsql2shp [<options>] <database> [<schema>.]<table> pgsql2shp [<options>] <database> <query>
OPTIONS: -f <filename> Use this option to specify the name of the file to create. -h <host> Allows you to specify connection to a database on a machine other than the default. -p <port> Allows you to specify a database port other than the default. -P <password> Connect to the database with the specified password. -u <user> Connect to the database as the specified user. -g <geometry_column> Specify the geometry column to be exported. -b Use a binary cursor. -r Raw mode. Do not assume table has been created by the loader. This would not unescape attribute names and will not skip the ‘gid‘ attribute. -k Keep postgresql identifiers case. -? Display this help screen.
PostGIS导入导出SHP文件常用命令