[删除字段ogr层后尝试通过特征进行段错误

问题描述 投票:0回答:1

我正在从数据集中的图层中删除一堆字段

但是我发现一旦删除某些字段,如果在删除字段后尝试遍历功能,则会遇到段错误

# If I comment out this for loop that deletes fields everything is fine
    for layer in ds:
        layer_fields = _get_layer_fields(layer)
        for field in layer_fields:
            if field in list_of_fields_to_delete:
                layer.DeleteField(layer.FindFieldIndex(field, True))

# This prints successfully showing the fields have been deleted
    for layer in ds:
        print(layer.GetFeatureCount())
        print(_get_layer_fields(layer))

# but if I do delete feilds it will segfault when I try to itterate through features
    for layer in ds:
        for feature in layer:
            pass


#heres the function were calling for list of feilds
def _get_layer_fields(layer):
    layerDefinition = layer.GetLayerDefn()

    layer_fields = []

    if layerDefinition.GetFieldCount():
        for i in range(layerDefinition.GetFieldCount()):
            layer_fields.append(layerDefinition.GetFieldDefn(i).GetName())

我可以使用GetFeatureCount,GetFieldCount来处理所有这些好东西,但是一旦删除字段,就无法通过这些功能进行操作,得到的结果是“处理结束,退出代码为139(信号11:SIGSEGV中断)”]]

任何人都可以帮助我了解为什么删除字段后我失去了迭代能力吗?

我正在从数据集中的图层中删除一堆字段,但是我发现一旦删除某些字段,如果在删除字段后尝试遍历要素,则会遇到段错误#如果我...

python segmentation-fault layer ogr
1个回答
0
投票

似乎一旦图层具有特征,我就无法删除字段,为了解决这个问题,我在将图层复制到mem数据集中时更早地删除了属性,为此我修改了以下代码。

© www.soinside.com 2019 - 2024. All rights reserved.