GDAL on Windows

From Wildsong
Jump to navigationJump to search

ArcGIS 9.3 + Python + GDAL using OSGeo4W

2010-Jul-25

Install [1] just gdal 1.7 and python using the Advanced option. Asking for gdal turns on the other dependencies we need including proj4.

This looks promising since it installs python 2.5 which is what we use with ArcGIS 9.3


Python packages are installed in OSGEO4WROOT/apps/Python25/Lib/site-packages

ArcGIS 10 + Python + GDAL using OSGeo4W

2010-June-something

First install the installer. Get the Windows version for Python 2.6 and run it. See http://pypi.python.org/pypi/setuptools Add the C:\Python26\ArcGIS10.0\Scripts directory to your PATH. That allows your command shell to find and run easy_install.

Next install OSGeo4W for this. See http://trac.osgeo.org/osgeo4w/ Along with GDAL and PROJ4 which is what we're looking for right now, this installs lots of cool stuff like QGIS and uDig. (You can uncheck boxes if you are in a hurry or don't want the whole thing.)

You have to have gdal 1.7 installed before you install Python gdal. Turns out that's part of the OSGeo4W installation done in the previous section, so now all I have to do is figure out how to reference those files.

I can't figure that out yet.

Next step WOULD be to go install the Python packages using the installer. The easy_install GDAL" fails because it can't find the cpl_ports.h file that's installed with gdal in C:\OSGeo4W\

--

I got a little further along, I was able to get it to build and install and now it can't find _gdal.py I think possibly either it's not loading gdal17.dll or that's wrong and it really needs gdal171.dll

I downloaded source for gdal 171 (GDAL-1.7.1.tar.gz) and edited the file setup.cfg, adding the last two lines so it could find where OSGeo4W put things.

[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0

[build_ext] gdal_config = ../../apps/gdal-config include_dirs = C:/OSGeo4W/include library_dirs = C:/OSGeo4W/lib

import osgeo.gdal gives

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import osgeo.gdal

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>
 File "osgeo\__init__.py", line 21, in <module>
   _gdal = swig_import_helper()
 File "osgeo\__init__.py", line 13, in swig_import_helper
   import _gdal

ImportError: No module named _gdal

--- GOT IT (I've been making some notes here: http://wildsong.biz/index.php?title=Geoprocessing#Open_source)

Trying the Pypi

See http://pypi.python.org/pypi/GDAL/

Add "C:\Python26\ArcGIS10.0;C:\Python26\ArcGIS10.0\Scripts" to your PATH. Make sure it's ahead of OSGeo4W so that it does not find Python2.5 instead.

You have to have gdal 1.7 installed before you install Python gdal. Turns out that's part of the OSGeo4W installation done in the previous section, so now all I have to do is figure out how to reference those files.

I could not use "easy_install". I had to run build and install steps so that the compiler could find the right include and lib files.

I downloaded and unpacked the source file from the PyPi link above. Then I edited the config file! Here is mine:

[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

[build_ext]
gdal_config = ../../apps/gdal-config
include_dirs = C:/OSGeo4W/include
library_dirs = C:/OSGeo4W/lib

I added the last two lines, to tell it where I put the OSGeo4W files.

After that I was able to type this

python setup.py build
python setup.py install

and it WORKED. Then I was able to do this:

python
import osgeo.osr










To get the import to happen I had to set the environment, and there is a script to help me do that in c:\OSGeo4W\bin called gdal17.bat

In a cmd window I run that then I start python....

C:\OSGeo4W\bin>python

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import osgeo.osr >>> dir(osgeo.osr) ['CoordinateTransformation', 'CoordinateTransformation_swigregister', 'DontUseEx ceptions', 'GetProjectionMethods', 'GetUserInputAsWKT', 'GetWellKnownGeogCSAsWKT ', 'SRS_DN_NAD27', 'SRS_DN_NAD83', 'SRS_DN_WGS72', 'SRS_DN_WGS84', 'SRS_PM_GREEN WICH', 'SRS_PP_AZIMUTH', 'SRS_PP_CENTRAL_MERIDIAN', 'SRS_PP_FALSE_EASTING', 'SRS _PP_FALSE_NORTHING', 'SRS_PP_FIPSZONE', 'SRS_PP_LANDSAT_NUMBER', 'SRS_PP_LATITUD E_OF_1ST_POINT', 'SRS_PP_LATITUDE_OF_2ND_POINT', 'SRS_PP_LATITUDE_OF_CENTER', 'S RS_PP_LATITUDE_OF_ORIGIN', 'SRS_PP_LATITUDE_OF_POINT_1', 'SRS_PP_LATITUDE_OF_POI NT_2', 'SRS_PP_LATITUDE_OF_POINT_3', 'SRS_PP_LONGITUDE_OF_1ST_POINT', 'SRS_PP_LO NGITUDE_OF_2ND_POINT', 'SRS_PP_LONGITUDE_OF_CENTER', 'SRS_PP_LONGITUDE_OF_ORIGIN ', 'SRS_PP_LONGITUDE_OF_POINT_1', 'SRS_PP_LONGITUDE_OF_POINT_2', 'SRS_PP_LONGITU DE_OF_POINT_3', 'SRS_PP_PATH_NUMBER', 'SRS_PP_PERSPECTIVE_POINT_HEIGHT', 'SRS_PP _PSEUDO_STD_PARALLEL_1', 'SRS_PP_RECTIFIED_GRID_ANGLE', 'SRS_PP_SATELLITE_HEIGHT ', 'SRS_PP_SCALE_FACTOR', 'SRS_PP_STANDARD_PARALLEL_1', 'SRS_PP_STANDARD_PARALLE L_2', 'SRS_PP_ZONE', 'SRS_PT_ALBERS_CONIC_EQUAL_AREA', 'SRS_PT_AZIMUTHAL_EQUIDIS TANT', 'SRS_PT_BONNE', 'SRS_PT_CASSINI_SOLDNER', 'SRS_PT_CYLINDRICAL_EQUAL_AREA' , 'SRS_PT_ECKERT_I', 'SRS_PT_ECKERT_II', 'SRS_PT_ECKERT_III', 'SRS_PT_ECKERT_IV' , 'SRS_PT_ECKERT_V', 'SRS_PT_ECKERT_VI', 'SRS_PT_EQUIDISTANT_CONIC', 'SRS_PT_EQU IRECTANGULAR', 'SRS_PT_GALL_STEREOGRAPHIC', 'SRS_PT_GAUSSSCHREIBERTMERCATOR', 'S RS_PT_GEOSTATIONARY_SATELLITE', 'SRS_PT_GNOMONIC', 'SRS_PT_GOODE_HOMOLOSINE', 'S RS_PT_HOTINE_OBLIQUE_MERCATOR', 'SRS_PT_HOTINE_OBLIQUE_MERCATOR_TWO_POINT_NATURA L_ORIGIN', 'SRS_PT_IMW_POLYCONIC', 'SRS_PT_KROVAK', 'SRS_PT_LABORDE_OBLIQUE_MERC ATOR', 'SRS_PT_LAMBERT_AZIMUTHAL_EQUAL_AREA', 'SRS_PT_LAMBERT_CONFORMAL_CONIC_1S P', 'SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP', 'SRS_PT_LAMBERT_CONFORMAL_CONIC_2SP_BE LGIUM', 'SRS_PT_MERCATOR_1SP', 'SRS_PT_MERCATOR_2SP', 'SRS_PT_MILLER_CYLINDRICAL ', 'SRS_PT_MOLLWEIDE', 'SRS_PT_NEW_ZEALAND_MAP_GRID', 'SRS_PT_OBLIQUE_STEREOGRAP HIC', 'SRS_PT_ORTHOGRAPHIC', 'SRS_PT_POLAR_STEREOGRAPHIC', 'SRS_PT_POLYCONIC', ' SRS_PT_ROBINSON', 'SRS_PT_SINUSOIDAL', 'SRS_PT_STEREOGRAPHIC', 'SRS_PT_SWISS_OBL IQUE_CYLINDRICAL', 'SRS_PT_TRANSVERSE_MERCATOR', 'SRS_PT_TRANSVERSE_MERCATOR_MI_ 21', 'SRS_PT_TRANSVERSE_MERCATOR_MI_22', 'SRS_PT_TRANSVERSE_MERCATOR_MI_23', 'SR S_PT_TRANSVERSE_MERCATOR_MI_24', 'SRS_PT_TRANSVERSE_MERCATOR_MI_25', 'SRS_PT_TRA NSVERSE_MERCATOR_SOUTH_ORIENTED', 'SRS_PT_TUNISIA_MINING_GRID', 'SRS_PT_TWO_POIN T_EQUIDISTANT', 'SRS_PT_VANDERGRINTEN', 'SRS_PT_WAGNER_I', 'SRS_PT_WAGNER_II', ' SRS_PT_WAGNER_III', 'SRS_PT_WAGNER_IV', 'SRS_PT_WAGNER_V', 'SRS_PT_WAGNER_VI', ' SRS_PT_WAGNER_VII', 'SRS_UA_DEGREE', 'SRS_UA_DEGREE_CONV', 'SRS_UA_RADIAN', 'SRS _UL_CHAIN', 'SRS_UL_CHAIN_CONV', 'SRS_UL_FOOT', 'SRS_UL_FOOT_CONV', 'SRS_UL_LINK ', 'SRS_UL_LINK_CONV', 'SRS_UL_METER', 'SRS_UL_NAUTICAL_MILE', 'SRS_UL_NAUTICAL_ MILE_CONV', 'SRS_UL_ROD', 'SRS_UL_ROD_CONV', 'SRS_UL_US_FOOT', 'SRS_UL_US_FOOT_C ONV', 'SRS_WGS84_INVFLATTENING', 'SRS_WGS84_SEMIMAJOR', 'SRS_WKT_WGS84', 'Spatia lReference', 'SpatialReference_swigregister', 'UseExceptions', '__builtins__', ' __doc__', '__file__', '__name__', '__package__', '_newclass', '_object', '_osr',

'_swig_getattr', '_swig_property', '_swig_repr', '_swig_setattr', '_swig_setatt

r_nondynamic']