PostGIS匯入匯出SHP檔案常用命令
阿新 • • 發佈:2019-01-27
SHP匯入POSTGIS資料庫
[quote][color=red]直接匯入資料庫
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
[/color][/quote]POSTGIS資料庫匯出SHP:生成shp資料
//windows匯出亂碼解決辦法:在環境變數中設定 PGCLIENTENCODING=GBK或PGCLIENTENCODING=GB18030,然後執行pgsql2shp,匯出的shape檔案中,屬性資料編碼正確是GBK的,沒有顯示亂碼。
[quote][color=red]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"
[/color][/quote]
[color=red][b][quote]@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[/quote][/b][/color]
shp2pgsql命令相關引數
[quote][color=green]
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.
[/color][/quote]
pgsql2shp命令相關引數
[quote] [color=green]
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.
[/color][/quote]
[quote][color=red]直接匯入資料庫
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
[/color][/quote]POSTGIS資料庫匯出SHP:生成shp資料
//windows匯出亂碼解決辦法:在環境變數中設定 PGCLIENTENCODING=GBK或PGCLIENTENCODING=GB18030,然後執行pgsql2shp,匯出的shape檔案中,屬性資料編碼正確是GBK的,沒有顯示亂碼。
[quote][color=red]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"
[/color][/quote]
[color=red][b][quote]@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[/quote][/b][/color]
shp2pgsql命令相關引數
[quote][color=green]
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.
[/color][/quote]
pgsql2shp命令相關引數
[quote] [color=green]
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.
[/color][/quote]