1

I wrote a code that projects a raster to a new coordinate system.

from osgeo import gdal

filename = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic.tif"
input_raster = gdal.Open(filename)
output_raster = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic_p.tif"
gdal.Warp(output_raster,input_raster,dstSRS='EPSG:4326')

The code works great on pycharm when the interpreter is OSGEO, but when I run it when the interpreter is anaconda (like on jupyter notebook), I get this message error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-9021d776efc4> in <module>()
      4 input_raster = gdal.Open(filename)
      5 output_raster = r"C:\Users\rsl\Desktop\New folder\SN228122015_mosaic_p.tif"
----> 6 gdal.Warp(output_raster,input_raster,dstSRS='EPSG:4326')
      7 

C:\Users\rsl\Anaconda2\lib\site-packages\osgeo\gdal.pyc in Warp(destNameOrDestDS, srcDSOrSrcDSTab, **kwargs)
    547 
    548     if _is_str_or_unicode(destNameOrDestDS):
--> 549         return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
    550     else:
    551         return wrapper_GDALWarpDestDS(destNameOrDestDS, srcDSTab, opts, callback, callback_data)

TypeError: in method 'wrapper_GDALWarpDestName', argument 4 of type 'GDALWarpAppOptions *'

How can I make my code to work on the anaconda environment?

  • Are the gdal versions the same? You can access that information from the interpreter using gdal.VersionInfo() – Logan Byers Sep 18 '17 at 14:55
1

I had the same problem here, I found that we need to set the GDAL_DATA environment variable.

e.g. GDAL_DATA=C:\Python35\Lib\site-packages\osgeo\data\gdal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.