Discussion:
[gdal-dev] OGR features list - python bindings
Nicol Hermann
2021-05-16 15:07:54 UTC
Permalink
Hello,

I am facing difficulties returning a list of ogr features from a python
function.
For each entry I am getting an error message like this:

[<osgeo.ogr.Feature; proxy of <Swig Object of type 'OGRFeatureShadow *'
at 0x7f75e870d4b0> >

This is the code I am using:


def generateRecordFormSplit( ogr, dblayer, dblayerDefn, sessionid ):
cnt = 1
featureList = []

for feature in dblayer:
geom = feature.GetGeometryRef()
dblayerFeature = ogr.Feature(feature_def = dblayerDefn)
dblayerFeature.SetGeometry( geom )
dblayerFeature.SetField("sessionid", sessionid + "_" + str(cnt)
)
featureList.append( dblayerFeature )
feature.Destroy()
cnt += 1

return( featureList ) # <<-- Issue


Any hints what I am doing wrong and how to fix it.

Thanks
Nicol
Even Rouault
2021-05-16 15:20:24 UTC
Permalink
Post by Nicol Hermann
Hello,
I am facing difficulties returning a list of ogr features from a python
function.
[<osgeo.ogr.Feature; proxy of <Swig Object of type 'OGRFeatureShadow *'
at 0x7f75e870d4b0> >
This doesn't look like an error message to me, but as the expected
not-so-sexy representation of a ogr.Feature object. Do you get an actual
exception ?

Even
--
http://www.spatialys.com
My software is free, but my time generally not.
Nicol Hermann
2021-05-16 15:44:20 UTC
Permalink
Hello,
Post by Even Rouault
Post by Nicol Hermann
Hello,
I am facing difficulties returning a list of ogr features from a python
function.
[<osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *'
at 0x7f75e870d4b0> >
This doesn't look like an error message to me, but as the expected
not-so-sexy representation of a ogr.Feature object. Do you get an actual
exception ?
No, but the execution terminates after that.
This is the function call followed by a simple print statement which
does not get printed

featureList = generateRecordFormSplit( ogr, dblayer, dblayerDefn,
'12345' )
print( featureList )


Thanks
Nicol
Post by Even Rouault
Even
Nicol Hermann
2021-05-16 16:45:56 UTC
Permalink
Hallo,
Post by Nicol Hermann
Hello,
No, but the execution terminates after that.
This is the function call followed by a simple print statement which
does not get printed
featureList = generateRecordFormSplit( ogr, dblayer, dblayerDefn,
'12345' )
print( featureList )
Thanks
Nicol
As Even has pointed out, this is the output of the print statement,
though it appears to be truncated - the closing "]" is missing (and
possibly more as well).
To convince yourself that the function has indeed returned try
something like
print ("Function has returned")
If you want to see the actual features in a recognizable way, you
will need to iterate through the featureList and print some property
of each feature that has a human-readable representation.
done and solved.
Thanks for your help!

Nicol

Loading...