I can successfully execute the following command in the OSGeo4W shell:

ogr2ogr -f "PostgreSQL" -a_srs "EPSG:102733" PG:"host=localhost user='postgres' dbname='nameofdb' password='password' port=5433" "Water and Sewer Map.dxf" -nln eastover

but whenever I open up a blank Windows CMD and navigate to the folder where my file is and run the same command, I get this:

Unable to find driver `PostgreSQL'.

But when I run this in the Windows CMD:

ogr2ogr --version

I get this:

GDAL 2.0.1, released 2015/09/15

My goal is to have this as a batch file so I can run it from the native CMD prompt. Why is it saying the I don't have the PostgreSQL driver on the Windows CMD and how to I fix it?


Per AlecZ's recommendation, I have taken the o4w_env.bat script and appended my command to the end to look like this:

REM Make parent of this script location our current directory,
REM converting UNC path to drive letter if needed

pushd %~dp0
cd ..

REM set OSGEO4W_ROOT to short path version
set OSGEO4W_ROOT="C:\OSGeo4W64"

REM start with clean path
set path=%OSGEO4W_ROOT%\bin;%WINDIR%\system32;%WINDIR%;%WINDIR%\WBem;%OSGEO4W_ROOT%\share

for %%f in ("%OSGEO4W_ROOT%\etc\ini\*.bat") do call "%%f"


cd network share:\folder\folder\folder

ogr2ogr -f "PostgreSQL" -a_srs "EPSG:102733" PG:"host=localhost user='username' dbname='databasename' password='password' port=5433" "Water and Sewer Map.dxf" -nln eastover


But now I am getting this error:

ERROR 4: Unable to open EPSG support file gcs.csv.
Try setting the GDAL_DATA environment variable to point to the
directory containing EPSG csv files.
ERROR 1: Failed to process SRS definition: EPSG:102733

I have updated the environment variable as suggested in the error and added ;%OSGEO4W_ROOT%\share to the end of the clean path setting, but neither seems to be working. Any other suggestions?

picture of environment variable

  • Do you mean a non OSGeo4W prompt when you say "blank Windows CMD"? If so, that's your problem. The OSGeo4W bat file sets a number of environment variables, one of which is GDAL_DRIVER_PATH which tells gdal where to find driver plugins. – user2856 Nov 7 '17 at 19:49
  • Yes, that's what I mean, a non-OSGeo promt. So, how would you create a batch file that uses ogr2ogr then? – Matt Nov 7 '17 at 19:56

The easy workaround is to use a .bat file you already have, that automatically sets all the dependencies you need. This is located in your "bin" folder within the main folder for your OSgeo4W installation. The name of the bat is "o4w_env.bat" - simply copy this to any location you please, change the name, and then for any command line calls you can simply add those to the bottom of the text in the bat file, in the line(s) under "popd".

One change that you'll need to make is to hard-code the directory for OSGeo4W (the bat is set to run out of that bin folder, and we're moving it). Change the following line:

for %%i in ("%CD%") do set OSGEO4W_ROOT=%%~fsi

To something like this (but changed to match the install folder on your system):

set OSGEO4W_ROOT="C:\OSGeo4W64"

When you run that, it'll set your environments correctly to include the drivers, and THEN execute your desired ogr2ogr command, as specified.

|improve this answer|||||
  • I get this: ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files. Do I have it pointed to the wrong directory? – Matt Nov 7 '17 at 21:24
  • That's odd, it wouldn't be set in normal OSGeo4W shell but that error wouldn't come up - also it didn't for me testing with a random shape conversion. In any event, if you add ";%OSGEO4W_ROOT%\share" to the end of the line after following "REM start with clean path" in that bat file, it should pick up that (or any related epsg file) without issue. – AlecZ Nov 7 '17 at 21:40
  • I updated the case to show that I am still getting the same error. Any other suggestions at this point? Thanks. – Matt Nov 8 '17 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.