[GIS] How to call ogr2ogr from command line with Python 2.7 from ArcGIS 10.2 for Desktop

arcgis-desktopgdalogr2ogrpythonpythonxy

I am trying to access ogr2ogr in the command line, and this is the message I receive:

 'ogr2ogr' is not recognized as an internal or external command, operable program or batch file. 

This is current python setup-up. I am using the python version installed with arcgis 10.2 (aka. python 2.7). I have installed and linked Python(x,y) to python itself. I call on arcgis and a variety of python gis function using the Spyder editor, which comes with the Python(x,y) editor.

I installed a compiled gdal package from:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Now I am able to call the gdal function inside of Spyder, but I am unable to call ogr2ogr from the command line. I did not create a environmental variable for windows yet. My primary issue is that I dont know how create a enviornmental variable for gdal that allows me to call ogr2ogr in the command line, given that I am using the compiled gdal package.

Does anyone know what to do?

Here is the location of the ogr2ogr on my installation:

C:\Python27\Lib\site-packages\osgeo\ogr2ogr.exe

Best Answer

You need to have admin privileges on the box.

For Windows 7:

  1. Click on the start menu.
  2. Right click on "Computer"
  3. Click "Properties"
  4. Click "Advanced system settings on the left menu bar
  5. You may have to type in a password here.
  6. The second box is titled "system variables" on of them is "PATH"
  7. Select path, click edit.
  8. Go to the end of the PATH variable and add the string (the semicolon isrequired)

    ;C:\Python27\Lib\site-packages\osgeo\
    
  9. Ok/Save your way back out and close the window.

  10. The windows command line loads the system path at start up, so you'll need to reopen any open terminal to access the change.