[FWTools] AttributeError: 'NoneType' object has no attribute 'GetGeometryRef'

Frank Warmerdam warmerdam at pobox.com
Thu Oct 14 11:52:37 EST 2010


Susana Iraiis Delgado Rodriguez wrote:
>       shapeData = ogr.Open(filepath)
>       layer = shapeData.GetLayer()
>       feature = layer.GetNextFeature()
>       wksht.row(row).write(7, layer.GetFeatureCount())
>  #Here is the problem, when I want to get the geometry name,
>       geometry = feature.GetGeometryRef()
>       geometryType = geometry.GetGeometryName()
>       wksht.row(row).write(6, geometryType)
>  #
> 
> wrkbk.save('shp.xls')
>  
> When the module gets to the geometryName part, ti throws me the error:
> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit 
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import excel_craw
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "excel_craw.py", line 45, in <module>
>     geometry = feature.GetGeometryRef()
> AttributeError: 'NoneType' object has no attribute 'GetGeometryRef'
>  >>>

Susana,

I don't know why the above didn't work, and running in IDLE did
work.  But I will note that the error message is indicating that
the "feature" is None, that is layer.GetNextFeature() returned None.

Best regards,

> I don't undestand the reason of the error, because I run the next lines 
> in IDLE Python an this is what I got:
>  >>> import os
>  >>> from osgeo import ogr
>  >>> shapeData = ogr.Open('tapalpa_05_plani_point.shp')
>  >>> layer = shapeData.GetLayer()
>  >>> feature = layer.GetNextFeature()
>  >>> geometry = feature.GetGeometryRef()
>  >>> geometryType = geometry.GetGeometryName()
>  >>> print geometryType
> POINT
>  
> Why is my other code wrong?
>  
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FWTools mailing list
> FWTools at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/fwtools
> http://fwtools.maptools.org/


-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the FWTools mailing list