[Gdal-dev] easy ogr question...
Dan Putler
putler at sauder.ubc.ca
Tue Sep 19 12:48:36 EDT 2006
Hi Will,
I add new fields to shapefiles all the time. Although, I do it using
R, which (through Frank's shapelib) handles DBFs beautifully. I can
provide details, but since this is now off list, I can provide
details privately. The main thing is that you only need to muck with
the *.dbf file, not the *.shp file itself.
Dan
On 19-Sep-06, at 9:33 AM, Will Cadell wrote:
> Thanks Frank,
>
> No message I'm afraid but there are features, and I was wondering how
> ogr would handle and 'empty' column. I assumed it would add nulls, but
> hey ho seems like I'll have to make a new shapefile, copy the layer
> definition then add the field then copy all the features to a new
> shapefile... Does seem a bit cumbersome though... is there a better
> way
> people can think of?
>
> will
>
> Frank Warmerdam wrote:
>> Will Cadell wrote:
>>> hi guys... am i just stupid or is there another way to add a
>>> field to a
>>> shapefile other than:
>>> ds = ogr.open("c:\shapefile.shp", True)
>>> new_field = ogr.FieldDefn()
>>> new_field.SetName(new_field_name)
>>> new_field.SetType(new_field_type)
>>> new_field.SetWidth(new_field_width)
>>> layer = ds.GetLayer(0)
>>> layer.CreateField(new_field)
>>> ds.destroy
>>>
>>> because this doesn't work for me...
>>
>> Will,
>>
>> This does seem like the correct approach. Are there any features
>> in the
>> shapefile already? I'm pretty sure that adding a field only works
>> when
>> there are no features yet. If you aren't getting an error message
>> then
>> there is a clear bug here, and a bug report in bugzilla would be
>> appreciated.
>>
>> Best regards,
>
> --
> Will Cadell
> Remote Sensing and GIS Analyst
>
> /\/\
> / \ \
> / Timberline
> / Forest Inventory Consultants
>
> tel:(250) 562 2628 address: 1579 9th Ave,
> skype: geo_will Prince George,
> loc: 53.9135N, 122.7544W BC, Canada
>
> www.timberline.ca
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
More information about the Gdal-dev
mailing list