In the office I use ogr2ogr to convert several file formats such as KML or ESRI shapefiles. Since the commands are the same almost every time I'd like to run ogr2ogr with a batch. I'm using the GDAL package for Windows from gisinternals. Normally running the SDKShell.bat would set all the PATH variables that are needed to use ogr2ogr through cmd but our IT-department blocks users from changing the PATH. Therefore I can't call ogr2ogr with a batch because cmd doesn't know where to look for it.
My current approach is to start the SDKShell.bat and copy my commands into it each time. But that is not really what i wanted to achieve. Is there a possibility to solve this issue?
1 Answer
I found a solution to my problem: Running a batch that temporarily sets the PATH variable to the GDAL-package and afterwards running a second batch that sets the rest of the variables needed by ogr2ogr and runs the ogr2ogr commands you need.
The first batch looks like this:
rem In this case the gdal package is located in C:
setx PATH "C:\gdal;%PATH%"
After this first batch closes the PATH is set temporarily. This means you have to run it again after a reboot of your computer.
The second batch looks like this:
SET SDK_ROOT=C:\gdal\
SET "PATH=%SDK_ROOT%bin;%SDK_ROOT%bin\gdal\python\osgeo;%SDK_ROOT%bin\proj\apps;%SDK_ROOT%bin\gdal\apps;%SDK_ROOT%bin\ms\apps;%SDK_ROOT%bin\gdal\csharp;%SDK_ROOT%bin\ms\csharp;%SDK_ROOT%bin\curl;%PATH%"
SET "GDAL_DATA=%SDK_ROOT%bin\gdal-data"
SET "GDAL_DRIVER_PATH=%SDK_ROOT%bin\gdal\plugins"
SET "PYTHONPATH=%SDK_ROOT%bin\gdal\python;%SDK_ROOT%bin\ms\python"
SET "PROJ_LIB=%SDK_ROOT%bin\proj\SHARE"
rem You can enter your Code here
What I did was basically taking the path setting commands from the SDKShell.bat and run them in seperated batches because the first command requires to be runned in another process that has to be ended when the second is started.
Since this problem is very specific I thought I'd post it here so others who might encounter this issue can save time by using this approach. If you have a better/easier way to solve this issue please let me know.