I have made a batch file containing a list of two commands. The first (-clipsrc) works properly, but the second not (-s_srs EPSG:4326 -t_srs EPSG:3857).

Could anyone tell me where is the fail?.

This is the batch file:

cd /d c:\data\PhiladelphiaBaseLayers 
set ogr2ogrPath="c:\program files\QGIS Dufour\bin\ogr2ogr.exe" 
for %%X in (.shp) do %ogr2ogrPath% -skipfailures -clipsrc c:\data\PhiladelphiaBaseLayers\clipFeature\city_limits.shp c:\data\PhiladelphiaBaseLayers\clipped\%%X c:\data\PhiladelphiaBaseLayers\%%X 
for %%X in (.shp) do %ogr2ogrPath% -skipfailures -s_srs EPSG:4326 -t_srs EPSG:3857 c:\data\PhiladelphiaBaseLayers\clippedAndProjected\%%X c:\data\PhiladelphiaBaseLayers\clipped\%%X
  • Have you created the subfolders before? ogr2ogr might not do that. – AndreJ May 25 '15 at 12:46
  • What is the problem exactly? Do you get some error message or is the result wrong somehow? – user30184 May 25 '15 at 13:34
  • Hi, yes, I've created the subfolders before. The problem is the second command doesn't create nothing. Thanks for your time. – jfaneca May 25 '15 at 16:36

For the first command line, you moved to the folder where the shapefiles are. You have to do the same for the second command line.

My sample command line looks like:

for %%N in (D:\Karten\gdal\ogr2ogr\*.csv) DO ogr2ogr D:\Karten\gdal\ogr2ogr\%%~nN.shp %%N 

giving full path for in and destination file.


Testing your batch, it fails for me already with the first loop. Changing from (.shp) to (*.shp) made it running both loops, with the right target projection. If it does not work for you, try without -skipfailures to get error messages.

  • Batch file should be OK. It reads the name of the shapefile from the base directory into %%X and after executing the first row a shapefile c:\data\PhiladelphiaBaseLayers\clipped\%%Xshould be found just fine because %%X is still also in the base directory. – user30184 May 25 '15 at 13:32

I found the solution. The error was that I didn't set GDAL_DATA environment variable:

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.

I managed environment variables in Windows and the command works right.

  • Using OSGEO4W or gisinternals SDK shell, the environment variables are always set as needed. And everything is back to normal when you leave the shell. – AndreJ May 29 '15 at 13:09

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.