Created
July 21, 2017 08:01
-
-
Save sfkeller/92c289e30ecd46658ad384077985b265 to your computer and use it in GitHub Desktop.
Converts lines (PostgreSQL/PostGIS table) to points which are stored in files (Shapefile)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo. | |
echo Converts lines (PostreSQL/PostGIS table) to points which are stored in files (Shapefile) | |
echo. | |
rem If Shapefile (or better) is the original input, load it in PostGIS e.g. using QGIS DB Manager. | |
rem Typical DB Manager options are: Create single-part geometries, and attributes id and geom. | |
if %1.==. goto error | |
set in_file_lines=%1 | |
set db_user="postgres" | |
set db_name="work_gis" | |
set out_dir="out" | |
set in_file_name="algen_lines" | |
echo Processing %in_file_lines% lines... | |
for /L %%i in (1,1,%in_file_lines%) do ( | |
echo Writing f%%i | |
ogr2ogr -f "ESRI Shapefile" %out_dir% PG:"dbname='%db_name%' user=%db_user%" -sql "WITH tmp AS (SELECT DISTINCT ((ST_DumpPoints(geom)).geom) AS geom FROM %in_file_name% WHERE id=%%i) SELECT row_number() OVER () AS ptpos, geom FROM tmp" -nln f%%i -overwrite | |
) | |
echo Done | |
echo. | |
:ok | |
rem ogrinfo %out_dir% -so | |
dir %out_dir%\*.shp /ON | |
echo Ok. | |
goto end | |
:error | |
echo ERROR: Parameter missing for in_file_lines. | |
echo. | |
:usage | |
echo Usage: | |
echo %0 in_file_lines | |
echo. | |
echo Parameter: | |
echo - in_file_lines (a number between 1 and 999) | |
echo. | |
:end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment