[gdal-dev] feature.clone() -> same featuredefn

Martin Landa landa.martin at gmail.com
Mon Aug 4 02:02:41 PDT 2014


Hi Even,

2014-08-02 22:18 GMT+02:00 Even Rouault <even.rouault at mines-paris.org>:

[...]

>> 1) copy features from input layer to output layer
>> 2) modify features in output layer (remove some geometry columns)
>
> You can use the SetFrom() method.

thanks for hint, I found out that input and output layer somehow share
FeatureDefn. Here is sample code:

"""
    # create new layer
    olayer = ods.CreateLayer(layerName, ilayer.GetSpatialRef(),
                             geom_type, options)

    if not olayer:
        fatal("Unable to create layer '%'" % layerName)

    # create attributes
    feat_defn = ilayer.GetLayerDefn()
    for i in range(feat_defn.GetFieldCount()):
        olayer.CreateField(feat_defn.GetFieldDefn(i))

    # create also geometry attributes
    if not geom_name and \
            olayer.TestCapability(ogr.OLCCreateGeomField):
        for i in range(feat_defn.GetGeomFieldCount()):
            geom_defn = feat_defn.GetGeomFieldDefn(i)
            if geom_name and geom_defn.GetName() != geom_name:
                continue
            olayer.CreateGeomField(feat_defn.GetGeomFieldDefn(i))

    print
    print ilayer, ilayer.GetLayerDefn()
    print olayer, olayer.GetLayerDefn()
"""

prints

<osgeo.ogr.Layer; proxy of <Swig Object of type 'OGRLayerShadow *' at
0x7fbf0d95f930> > <osgeo.ogr.FeatureDefn; proxy of <Swig Object of
type 'OGRFeatureDefnShadow *' at 0x7fbf0d95fae0> >
<osgeo.ogr.Layer; proxy of <Swig Object of type 'OGRLayerShadow *' at
0x7fbf0d95fba0> > <osgeo.ogr.FeatureDefn; proxy of <Swig Object of
type 'OGRFeatureDefnShadow *' at 0x7fbf0d95fae0> >

I am not sure why... Thanks for clarification in advance, Martin

-- 
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa


More information about the gdal-dev mailing list