USE GDAL

1304
2
02-21-2014 02:25 PM
HollyZhang1
New Contributor III
I installed GDAL core and python bingings (ArcGIS10.2). There are no error massage import:

from osgeo import gdal
from osgeo import ogr
from osgeo import osr

But there are errors:

No module named ogr2ogr

ImportError: cannot import name ogr2ogr

What to do to use ogr2ogr?

Thanks.
Tags (2)
0 Kudos
2 Replies
Luke_Pinner
MVP Regular Contributor
ogr2ogr is a commandline program not a python module.  You can run it from a command prompt or you can use the subprocess module to run it from within python.

cmd=["ogr2ogr", "output_dataset", "input_dataset"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout,stderr=proc.communicate()
exit_code=proc.wait()
if exit_code: print stderr
else: print stdout

XanderBakker
Esri Esteemed Contributor
Hi Holly,

I recently did an open source project with Python and found the website below very helpful:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal

I installed the executable "GDAL-1.10.1.win32-py2.7.exe" and was able to use "gdal, ogr and osr" without any further pip or easy_install.

Please pay attention to the note on that page:
This distribution includes all required files. Do not use together with OSGeo4W or gdalwin32.

Kind regards,

Xander
0 Kudos