[gdal-dev] adding a new method to OGRFieldDefn & gdalautotest

Alan Stewart astewart at terragotech.com
Tue Nov 6 13:16:04 PST 2018


I'm working in Windows 7 with VS 2017 and Python 2.7.15.

I've added a new method to this class,  and wish to add tests for it to gdalautotest. I found and added the new method to swig/python/osgeo/ogr.py. Is there anything else I need to do to add python support for my new class method?

The current errors I get when calling it from my new test seems to indicate I need to do something further to get swig to recognize it, though after rebuilding the new method does appear in my python's Lib/site-packages/GDAL-2.3.0-py2.7-win32.egg/osgeo/ogr.py.

The test (so far):

def ogr_fgdb_26():

    try:
        shutil.rmtree('tmp/aliasname.gdb')
    except OSError:
        pass
    gdaltest.unzip('tmp', 'data/aliasname.gdb.zip')
    if not os.path.exists('data/aliasname.gdb'):
        gdaltest.post_reason('failure to unzip archive')
        return 'fail'

    ds = ogr.Open('data/aliasname.gdb')
    if not ds:
        gdaltest.post_reason('failure to open dataset')
        return 'fail'

    ## retrieve and test table
    table00 = ds.GetLayerByName('table00')
    layerDefn = table00.GetLayerDefn()
    fieldDfn = layerDefn.GetFieldDefn(layerDefn.GetFieldIndex('has_alias'))
    name = fieldDfn.GetName()
    alias = fieldDfn.GetAliasName()
    print('name: {0} alias: {1}'.format(name, alias))

The runtime error:

Traceback (most recent call last):
  File "../pymod\gdaltest_python2.py", line 43, in run_func
    result = func()
  File "C:\devel\GitHub\gdal\autotest\ogr\ogr_fgdb.py", line 2626, in ogr_fgdb_26
    alias = fieldDfn.GetAliasName()
  File "C:\Python27\lib\site-packages\gdal-2.3.0-py2.7-win32.egg\osgeo\ogr.py", line 5415, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, FieldDefn, name)
  File "C:\Python27\lib\site-packages\gdal-2.3.0-py2.7-win32.egg\osgeo\ogr.py", line 74, in _swig_getattr
    return _swig_getattr_nondynamic(self, class_type, name, 0)
  File "C:\Python27\lib\site-packages\gdal-2.3.0-py2.7-win32.egg\osgeo\ogr.py", line 69, in _swig_getattr_nondynamic
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'


Alan Stewart
Senior Software Engineer
TerraGo Technologies
3200 Windy Hill Road, Suite 1550W
Atlanta, GA 30339 USA
O.  +1 678.391.9615

www.terragotech.com<applewebdata://B24C0762-C7C9-4431-8518-ACC915448B89/www.terragotech.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20181106/982b0efd/attachment.html>


More information about the gdal-dev mailing list