[Gdal-dev] easy ogr question...
Bryan Keith
bryan at geomega.com
Wed Sep 20 10:31:22 EDT 2006
Will, Frank, Dan,
I tested Will's code on a shapefile that had features and received this
error:
ERROR 6: Can't create fields on a Shapefile layer with features.
Clear enough.
Then I deleted the features from the shapefile, ran the code again, and
received this error:
ERROR 1: Can't create field test in Shape DBF file, reason unknown.
Not so clear.
Dan, I'm interested in the R code using dbflib because I wrote something
a while ago in Python using dbflib and my technique was like Will
described: make a new dbf with an additional field, populate with the
data from the old one, delete the old dbf and replace it with the new one.
Bryan
Dan Putler wrote:
> 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
>
> _______________________________________________
> 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