Skip to content

Instantly share code, notes, and snippets.

@neogis-de
Last active September 4, 2015 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neogis-de/6fcca708020dda4a5fca to your computer and use it in GitHub Desktop.
Save neogis-de/6fcca708020dda4a5fca to your computer and use it in GitHub Desktop.
ogr2ogr merge Ordnance Survey shapefiles from different subfolders together
@echo off
set OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
SETLOCAL ENABLEDELAYEDEXPANSION
rem set your folder which contains the shapefiles and change to this folder:
set verzeichnis=C:\YourShapefileFolder\
cd %verzeichnis%
rem recursive for loop
FOR /R %%b IN (*.shp) DO (
rem get filename without path
set var=%%~nxb
rem cut off the first three characters
echo merging now: !var! to !var:~3!
rem merge the files together
if NOT exist "!var:~3!" (ogr2ogr -f "ESRI Shapefile" "!var:~3!" "%%~fnxb") else (ogr2ogr -append -update -f "Esri Shapefile" "!var:~3!" "%%~fb" )
)
Echo -------------------------------------
Echo merging done!
Echo -------------------------------------
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment