问题描述
目前,我被使用 Cython 和 libGEOS 并由它提供的 c_api 引起的特定问题所困扰。 即,在 cython func 中调用 GEOsstRtree_insert_r(...) 不断为我提供:
python: AbstractSTRtree.cpp:118: virtual void geos::index::strtree::AbstractSTRtree::insert(const void*,void*): 断言 `!built' 失败。
查看 AbstractSTRtree.cpp 代码:
GEOsstRtree*
GEOsstRtree_create_r(GEOSContextHandle_t extHandle,std::size_t nodeCapacity)
{
return execute(extHandle,[&]() {
return new GEOsstRtree(nodeCapacity);
});
}
发现'built'标志只在'query'函数中改变,例如:
void
AbstractSTRtree::query(const void* searchBounds,std::vector<void*>& matches)
{
if(!built) {
build();
}
if(itemBoundables->empty()) {
assert(root->getBounds() == nullptr);
return;
}
if(getIntersectsOp()->intersects(root->getBounds(),searchBounds)) {
query(searchBounds,root,&matches);
}
}
上面提到的错误对我来说是没有任何理由的。 如果您能够重现它并提供一点建议,我将不胜感激。 谢谢!
include "./_geos.pxi"
cdef tree_search(array,geometry):
cdef Py_ssize_t idx
cdef unsigned int n = array.size
cdef list uavos_in = []
cdef GEOSGeometry *geom2
cdef uintptr_t geos_geom
cdef GEOSContextHandle_t geos_h
cdef void *obj_ptr
geos_h = get_geos_context_handle()
cdef GEOsstRtree *tree = GEOsstRtree_create_r(geos_h,10)
#fill STRtree
for idx in xrange(n):
obj = array[idx]
obj_ptr = <void *> obj
coords = array[idx].get('position').get('coordinates')
if coords[0] == None or coords[1] == None:
continue
point = shapely.geometry.Point(coords[0],coords[1])
geos_geom = point._geom
geom2 = <GEOSGeometry *>geos_geom
GEOsstRtree_insert_r(geos_h,tree,geom2,obj_ptr) <--- here where problem appears
_geos.pxi 文件在哪里:
cdef extern from "geos_c.h":
ctypedef void *GEOSContextHandle_t
ctypedef struct GEOSGeometry
ctypedef struct GEOSCoordSequence
ctypedef struct GEOSPreparedGeometry
ctypedef struct GEOsstRtree
ctypedef void (*GEOSQueryCallback)(void *,void *)
void register_callback(GEOSQueryCallback func)
[..intentionally skipped]
GEOsstRtree *GEOsstRtree_create_r(GEOSContextHandle_t,size_t) nogil
void GEOsstRtree_insert_r(GEOSContextHandle_t,GEOsstRtree*,const GEOSGeometry*,void*) nogil
void GEOsstRtree_query_r(GEOSContextHandle_t,GEOSQueryCallback,void*) nogil
[..intentionally skipped]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)