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

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Thu Oct 14 12:33:18 EST 2010


2010/10/14 Susana Iraiis Delgado Rodriguez <susana.delgado_s at utzmg.edu.mx>

> Thanks for the help Frank, but do you have any idea how to fix it? See I
> have to do the for cicle in order to fill alll my file with information, if
> some of miy shapes don't have feature, how can I fix the code so it keeps
> execuitng? What I need is the name of the geometry : poitn, line, polygon.
>
>
>
> 2010/10/14 Frank Warmerdam <warmerdam at pobox.com>
>
>  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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20101014/1328c754/attachment.htm 


More information about the FWTools mailing list