[FWTools] python ogr - setField attribute error

Frank Warmerdam warmerdam at pobox.com
Mon Oct 23 12:26:47 EDT 2006


David Fawcett wrote:
> I am bastardizing Matt Perry's text2shp.py and running into an error. 
> 
> I am taking values from a text file and building a shapefile.  The error 
> occurs when I try to set the value of first field of a feature.  I am 
> not sure what would cause this error. 
> 
> Below is the shell output.  The first list printed is the column names, 
> the second list is the field types. The last line before the error is 
> the column number and the value to be inserted into that field (print 
> colNum, cols[colNum]). 
> 
> D:\datascripts>python csv2shp.py
> 
> ['stn_type', 'stn_name', 'X', 'Y', 'col_meth', 'col_date', 'org_name', 
> 'org_type
> ', 'gnd_elev', 'uniq_id', 'tos_elev', 'bos_elev', 'comments']
> 
> [4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4]
> 
> 0 Monitoring Well
> 
> Traceback (most recent call last):
>   File "csv2shp.py", line 129, in ?
>     f.setField(colNum, cols[colNum])
>   File "C:\PROGRA~1\FWTOOL~1.5\pymod\ogr.py", line 755, in __getattr__
>     raise AttributeError, name
> AttributeError: setField

David,

I think the problem is that python is case sensitive, and the method is
SetField(), not setField(). Try "f.SetField(colNum,cols[colNum])".

Best regards,
-- 
---------------------------------------+--------------------------------------
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    | President OSGeo, http://osgeo.org



More information about the FWTools mailing list