bat脚本自动扫描制定文件夹下shp文件,并导入数据库,然后执行空间操作

时间:2023-02-01 09:15:27

GIS地图功能是现在越来越多项目的标配,但是商业的的arcgis软件太贵,开源的又有各种复杂的配置,如何简化这种配置呢,那就是使用脚本扫描知道文件夹下的文件,把扫描到的shp数据导入指定的空间数据库,然后对数据库中的不同表格执行不同的空间操作。

@echo off
echo pms map data input
set PSQLPATH="C:\Program Files (x86)\PostgreSQL\9.2\bin"
echo %PSQLPATH%
set filePath="F:\map\filePath"

for /r %filePath% %%i in (*.shp) do (
%PSQLPATH%\shp2pgsql.exe -c -W "GBK" %%~dpni %%~ni | %PSQLPATH%\psql.exe "dbname=dbName port=5432 user=postgres password=******"
)


for /r %filePath% %%i in (*daolu.shp) do (
echo ALTER TABLE %%~ni ADD COLUMN source integer; > topology.sql
echo ALTER TABLE %%~ni ADD COLUMN target integer; >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN length double precision; >> topology.sql
echo CREATE INDEX %%~ni_sidx ON %%~ni^("source"^); >> topology.sql
echo CREATE INDEX %%~ni_tidx ON %%~ni^("target"^); >> topology.sql
echo update %%~ni set length = st_length^(geom^); >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN reverse_cost double precision; >> topology.sql
echo UPDATE %%~ni SET reverse_cost = length; >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN x1 double precision; >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN y1 double precision; >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN x2 double precision; >> topology.sql
echo ALTER TABLE %%~ni ADD COLUMN y2 double precision; >> topology.sql
echo UPDATE %%~ni SET x1 = ST_x^(ST_PointN^(geom, 1^)^); >> topology.sql
echo UPDATE %%~ni SET y1 = ST_y^(ST_PointN^(geom, 1^)^); >> topology.sql
echo UPDATE %%~ni SET x2 = ST_x^(ST_PointN^(geom, ST_NumPoints^(geom^)^)^); >> topology.sql
echo UPDATE %%~ni SET y2 = ST_y^(ST_PointN^(geom, ST_NumPoints^(geom^)^)^); >> topology.sql
echo SELECT pgr_createTopology^('%%~ni', 0.00001, 'geom', 'gid'^); >> topology.sql
%PSQLPATH%\psql.exe -h 127.0.0.1 -f topology.sql "dbname=pmsdb port=5433 user=postgres password=ABC1616abc"
)