[gdal-dev] Question about adding features to ESRI Shapefile without Geometry
Even Rouault
even.rouault at mines-paris.org
Wed Jul 25 12:35:35 PDT 2012
Le mercredi 25 juillet 2012 19:27:41, Sebastian D'Agostino a écrit :
> Hi,
>
> I wanted to know if there are any known issues regarding feature addition
> from an ESRI Shapefile without a geometry.
>
> I'm having problems adding features without any geometry after deleting
> features.
Sebastian,
What would be helpful would be a minimum code sample (standalone) that could
enable us to reproduce that.
I have just tried the following python script :
~~~~~~~~~~~~~
from osgeo import ogr
ds = ogr.GetDriverByName('ESRI Shapefile').CreateDataSource('test.shp')
lyr = ds.CreateLayer('test')
lyr.CreateField(ogr.FieldDefn('foo', ogr.OFTString))
# Create a feature with geometry
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField('foo', 'bar')
feat.SetGeometry(ogr.CreateGeometryFromWkt('POINT(0 1)'))
lyr.CreateFeature(feat)
# deletes the feature that we have just created
lyr.DeleteFeature(0)
# Creates a new feature without geometry
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField('foo', 'baz')
lyr.CreateFeature(feat)
ds = None
~~~~~~~~~~~~~
and I get as expected (with both trunk and GDAL 1.9) :
$ ogrinfo test.shp -al
INFO: Open of `test.shp'
using driver `ESRI Shapefile' successful.
Layer name: test
Geometry: Point
Feature Count: 2
Extent: (0.000000, 1.000000) - (0.000000, 1.000000)
Layer SRS WKT:
(unknown)
foo: String (80.0)
OGRFeature(test):1
foo (String) = baz
But I'm not sure to have the whole context of what you tried....
Best regards,
Even
More information about the gdal-dev
mailing list