TransWikia.com

GDAL code does not work on anaconda interpreter

Geographic Information Systems Asked on August 18, 2021

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

from osgeo import gdal

filename = r"C:UsersrslDesktopNew folderSN228122015_mosaic.tif"
input_raster = gdal.Open(filename)
output_raster = r"C:UsersrslDesktopNew folderSN228122015_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:UsersrslDesktopNew folderSN228122015_mosaic_p.tif"
----> 6 gdal.Warp(output_raster,input_raster,dstSRS='EPSG:4326')
      7 

C:UsersrslAnaconda2libsite-packagesosgeogdal.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?

2 Answers

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

e.g. GDAL_DATA=C:Python35Libsite-packagesosgeodatagdal

Answered by Pablo on August 18, 2021

If setting the GDAL_DATA environment variable does not work then you may have to replace dstSRS='EPSG:4326' with gdal.WarpOptions(dstSRS='EPSG:4326') to get rid of the error that you are getting. You are supplying an keyword object where a gdal.WarpOptions object is needed.

Check out the docs for more information: https://gdal.org/python/osgeo.gdal-module.html#WarpOptions

Answered by blizzardus on August 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP