2

我有一个简单的程序来处理来自 Geopackage 层的点。在第一次尝试中,我将文件访问封装到一个函数中:

from osgeo import ogr

pointsFile = "points.gpkg"

def getPoints():

    driver = ogr.GetDriverByName("GPKG")
    dataSource = driver.Open(pointsFile, 0)
    layer = dataSource.GetLayer(0)
    print("Returning layer")
    return layer

def main():

    layer = getPoints()
    print("Number of points to process: ", layer.GetFeatureCount())


if __name__ == '__main__': main()

当它返回层对象时,它会因分段错误而失败:

$ python3 testReturn.py
Returning layer
Segmentation fault (core dumped)

但是,通过内部文件访问main

from osgeo import ogr

pointsFile = "points.gpkg"

def main():

    driver = ogr.GetDriverByName("GPKG")
    dataSource = driver.Open(pointsFile, 0)
    layer = dataSource.GetLayer(0)
    print("Number of points to process: ", layer.GetFeatureCount())


if __name__ == '__main__': main()

程序按预期运行:

$ python3 testDirect.py
Number of points to process:  21872

什么可能导致此问题?

4

1 回答 1

2

测试代码,GDB调用时出现分段错误:

layer.GetFeatureCount()

一些额外的调试信息:

启动程序:/usr/bin/python3 testReturn.py

[启用使用 libthread_db 进行线程调试]

使用主机 libthread_db 库“/lib/x86_64-linux-gnu/libthread_db.so.1”。

返回层程序收到信号SIGSEGV,Segmentation fault。/usr/local/lib/libgdal.so.20 (gdb) 中的 OGR_L_GetFeatureCount () 中的 0x00007ffff5c42298

于 2019-01-14T16:04:56.217 回答