GDAL on Windows: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
Line 1: Line 1:
===Download latest sources===
My notes so far -- what I need to do next is figure out how to tell "easy_install" the include path for gdal which should be "C:\OSGeo4W\include" so that it can find cpl_ports.h


http://download.osgeo.org/gdal/gdal173.zip
THere is probably an environment setting like INCLUDE_DIR but I don't know that for sure.


Unpack someplace convenient. D:/Brian/gdal-1.7.3/


The docs say I don't need swig but the current Windows version of Swig is available here:
ArcGIS 10 + Python + GDAL
Not using OSGeo4W


http://sourceforge.net/projects/swig/files/swigwin/swigwin-2.0.1/swigwin-2.0.1.zip/download
I am looking at using OSGeo4W for this. See http://trac.osgeo.org/osgeo4w/


I unpacked it into D:/Brian/swigwin-2.0.1/
I am installing their version of Python and the GDAL bindings for gdal 1.7 They have 1.8 but no python bindings for it. Typical for Windows stuff. Always incomplete.


'''I probably want to install Expat sources to get support for KML, GPX, and GeoRSS, but not just now.
OH GRAND. OSGeo4W is built on Python 2.5.
'''
Trying the Pypi


===Open in Visual Studio and build===
First install the installer. Get the Windows version for Python 2.6 and run it. See http://pypi.python.org/pypi/setuptools


I had to put the VS2010 disc in and install C++ so that I could open the vcxproj files. When I originally installed, I only loaded up C#.
Add the C:\Python26\ArcGIS10.0\Scripts directory to your PATH. That allows your command shell to find and run easy_install.


Then I can simply doubleclick on makegdal10.sln
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.


Change installation destination. By default it is C:\warmerda\bld
I can't figure that out yet.
I change it to C:\GDAL by editing GDAL_HOME in "Make Files\nmake.opt"


I set this: MSVC_VER=1600
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 am currently using ArcGIS 9.3.1, which installed Python 2.5 for me, so I want to build modules for that. So I edit PYDIR in nmake.opt to set it to C:\Python25
See http://pypi.python.org/pypi/GDAL/


For Swig, I used this: SWIG = "D:\Brian\swigwin-2.0.1\swig.exe"
--


I am building on a 64 bit machine but ArcGIS is only 32-bit. Not sure what to do, so for now I leave WIN64 alone. (Commented out)
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 will need to edit this further to support other formats, MrSid for instance.
I downloaded source for gdal 171 and edited the file setup.cfg, adding the last two lines so it could find where OSGeo4W put things.


Finally, I set the thing in Release mode and say Build.
[egg_info]
Man, it sure does produce a lot of messages. Not much chance I can read all that. Heh. These are the important lines to me:
tag_build =
tag_date = 0
tag_svn_revision = 0


1>------ Rebuild All started: Project: makegdal, Configuration: Release Win32 ------
[build_ext]
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
gdal_config = ../../apps/gdal-config
include_dirs = C:/OSGeo4W/include
library_dirs = C:/OSGeo4W/lib


I now check the output in C:\GDAL\bin, I set GDAL_DATA to C:\GDAL\data, add C:\GDAL\bin to PATH and try running a few of the commands in bin and things appear to work.


===Build ArcObjects plugin===


This lets me access ESRI format data objects like "file geodatabases".
import osgeo.gdal gives


===Build Python modules===


I need swig.exe for this.
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
I need to set the environment appropriately, per Swig docs
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo.gdal


PYTHON_INCLUDE : Set this to the directory that contains python.h
Traceback (most recent call last):
PYTHON_LIB : Set this to the python library including path for linking
  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


Example using Python 2.5:
ImportError: No module named _gdal
PYTHON_INCLUDE: C:\Python25\include
 
PYTHON_LIB: C:\Python25\libs\python25.lib
 
---
GOT IT (I've been making some notes here: http://wildsong.biz/index.php?title=Geoprocessing#Open_source)
 
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']

Revision as of 23:53, 8 July 2011

My notes so far -- what I need to do next is figure out how to tell "easy_install" the include path for gdal which should be "C:\OSGeo4W\include" so that it can find cpl_ports.h

THere is probably an environment setting like INCLUDE_DIR but I don't know that for sure.


ArcGIS 10 + Python + GDAL Not using OSGeo4W

I am looking at using OSGeo4W for this. See http://trac.osgeo.org/osgeo4w/

I am installing their version of Python and the GDAL bindings for gdal 1.7 They have 1.8 but no python bindings for it. Typical for Windows stuff. Always incomplete.

OH GRAND. OSGeo4W is built on Python 2.5. Trying the Pypi

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.

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\

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

--

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 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)

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']