I just started using gdal. I'm trying to get longitude and latitudes from pictures. This is what I have so far. This gives me an attribute error. Anyone know how to fix the attribute error?

    from osgeo import osr
    import numpy
    import gdal
    ds = gdal.Open(r"path")
    prj = ds.GetProjectionRef()
    oldcs = osr.SpatialReference()


AttributeError                            Traceback (most recent call last)
<ipython-input-1-b32399e41073> in <module>
      7 prj = ds.GetProjectionRef()
      8 oldcs = osr.SpatialReference()
----> 9 oldcs.ImportfromWkt(prj)

D:\Anaconda\lib\site-packages\osgeo\osr.py in <lambda>(self, name)
    354     __setattr__ = lambda self, name, value: _swig_setattr(self, SpatialReference, name, value)
    355     __swig_getmethods__ = {}
--> 356     __getattr__ = lambda self, name: _swig_getattr(self, SpatialReference, name)
    357     __repr__ = _swig_repr

D:\Anaconda\lib\site-packages\osgeo\osr.py in _swig_getattr(self, class_type, name)
     78     if method:
     79         return method(self)
---> 80     raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))

AttributeError: 'SpatialReference' object has no attribute 'ImportfromWkt'

1 Answer 1


You have a typo. The method is ImportFromWkt() (note the capitalized F).


It is a good idea to use an IDE that offers autocomplete features so you can easily avoid this type of mistakes in the future as well as check all the methods that a specific object can call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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