Thursday, September 29, 2016

GDAL/python: How to install python binding for gdal in windows? Essential Tips and Links collected.

I was having problem of installing gdal for my windows and with python versions. I have faced several issues during installation and it takes me three days to work it out.

Important isuues was  finding proper links of downloading windows binaries.  It was missing some elements from folder.

The requirements for geting gdal with python:
Firstly if you do not have python install python.You can install latest version of python from here.

Check the python installation versions: Start>python 27>IDL(Python GUI)>Run>Python Shell

Take a look on the screen shot of Python Shell. It contains important information [MSC v.1500 32 bit (Intel)] on win32 what you need to download for your Computer.

 





Links to dowload GDAL and python binding for Gdal. Click the picture to access to the the link.
http://www.gisinternals.com/release.php 
Note that you have to download GDAL and python binding for GDAL from same folder. Other wise it will not be sucessful at the end.
I have windows7 and I have python 2.7.10: I need to download from first links.
Then I have Downloaded the following files:
  1. gdal-111-1500-oracle.msi
  2. GDAL-1.11.4.win32-py2.7.msi---> this file contains your python version.
Install first GDAL and then GDAL-1.11.4.win32-py2.7.msi .

System Path Variable: 
The installation is not only the core thing, you must have to change /add or update your sytem path to let python recognize Gdal packages.

How to change or add in System Path?

Sytem variable to work:
  1. path
  2. PYTHONPATH
  3. GDALDATA
Add python path and GDAL path to your path variable.For this you need to edit Path variable to add the folder path to existing Path. Please do not delete anything from Path.
Example:
path=C:\Python27\ArcGIS10.4\Lib;C:\Program Files (x86)\GDAL (change to add this to location more)

You have to locate  python lib folder in PYTHONPATH system variable. I am using python with ArcGIS. So for me it look like the following:

PYTHONPATH=C:\Python27\ArcGIS10.4\Lib

 It is very important to add GDALDATA system variable to make sure gdal work properly.  

Here for my case gdal data:
GDALDATA= C:\Program Files (x86)\GDAL\gdal-data

After completing installation you will get a osgeo folder in your site-packagesfolder.

Example:
C:\Python27\ArcGIS10.4\Lib\site-packages\osgeo 

To check gdal is properly installed run the folowing lines in your python shell:
from osgeo import ogr
from osgeo import osr
from gdalconst import *
from osgeo import gdal
If it works properly you are done!!!! Otherwise recheck the process.....


Online helpful Tutorials/discussions:
How to Install Gdal in Windows Machine
Install gdal on windows
stackexchange helpful question and answers 
https://sandbox.idre.ucla.edu/sandbox/tutorials/installing-gdal-for-windows