Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Last active August 29, 2015 14:16
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 NathanW2/691207123db6750890eb to your computer and use it in GitHub Desktop.
Save NathanW2/691207123db6750890eb to your computer and use it in GitHub Desktop.
Import file to SQL Sever using OGR2OGR (drag and drop file onto batch file to import that file)
REM Drag and drop OGR2OGR file for importing a layer into the database
REM Drop a file that OGR supports to kick off import
@ECHO OFF
SET dbserver=localhost\SQLEXPRESS
SET dbname=Test
SET db="MSSQL:server=%dbserver%;database=%dbname%;trusted_connection=yes"
SET ARGS=-s_src EPSG:28356 -progress -overwrite -lco GEOM_NAME:SP_GEOMETRY
SET OSGEO4W_ROOT=C:\OSGeo4W\
CALL %OSGEO4W_ROOT%bin\o4w_env.bat
ECHO Uploading %nln% ...
SET TABLENAME=%~n1
SET /p TABLENAME="New name for layer (default %TABLENAME%):"
ogr2ogr -f MSSQLSpatial %ARGS% %db% %1 -nln %TABLENAME%
ogrinfo -sql "create spatial index on %TABLENAME%" %db%
ECHO Uploaded %TABLENAME% to %dbname%
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment