使用 shapefile_to_dataframe() 帮助程序函数将形状文件转换为数据帧 - fiona 相关错误



我正在尝试使用Palantir Foundry辅助函数shapefile_to_dataframe()来摄取shapefile以供以后在地理位置功能中使用。

我已经在单个数据集中手动导入了shapefile(.shp,.shx和.dbf)(通过文件系统API没有访问问题)。

根据文档,我已经导入了地理空间工具和GEOSPARK配置文件+在transforms-python build.gradle中包含依赖项。

这是我的转换代码,主要从文档中提取:

from transforms.api import transform, Input, Output, configure
from geospatial_tools import geospatial
from geospatial_tools.parsers import shapefile_to_dataframe
@geospatial()
@transform(
raw = Input("ri.foundry.main.dataset.0d984138-23da-4bcf-ad86-39686a14ef21"),
output = Output("/Indhu/InDhu/Vincent/geo_energy/datasets/extract_coord/raw_df")
)
def compute(raw, output):
return output.write_dataframe(shapefile_to_dataframe(raw))

然后代码辅助加载变得非常慢,然后我终于得到以下错误:

AttributeError: partially initialized module 'fiona' has no attribute '_loading' (most likely due to a circular import)
Traceback (most recent call last):
File "/myproject/datasets/shp_to_df.py", line 3, in <module>
from geospatial_tools.parsers import shapefile_to_dataframe
File "/scratch/standalone/3a553998-623b-48f5-9c3f-03de7e64f328/code-assist/contents/transforms-python/build/conda/env/lib/python3.8/site-packages/geospatial_tools/parsers.py", line 11, in <module>
from fiona.drvsupport import supported_drivers
File "/scratch/standalone/3a553998-623b-48f5-9c3f-03de7e64f328/code-assist/contents/transforms-python/build/conda/env/lib/python3.8/site-packages/fiona/__init__.py", line 85, in <module>
with fiona._loading.add_gdal_dll_directories():
AttributeError: partially initialized module 'fiona' has no attribute '_loading' (most likely due to a circular import)

非常感谢您的帮助, 文森特

我能够重现此错误,似乎它只发生在预览中 - 运行完整构建似乎工作正常。最简单的解决方法是将导入移动到函数内部:

from transforms.api import transform, Input, Output, configure
from geospatial_tools import geospatial
@geospatial()
@transform(
raw = Input("ri.foundry.main.dataset.0d984138-23da-4bcf-ad86-39686a14ef21"),
output = Output("/Indhu/InDhu/Vincent/geo_energy/datasets/extract_coord/raw_df")
)
def compute(raw, output):
from geospatial_tools.parsers import shapefile_to_dataframe
return output.write_dataframe(shapefile_to_dataframe(raw))

但是,目前,函数shapefile_to_dataframe无论如何都不会在预览版中工作,因为未实现完整的transforms.api.FileSystemAPI - 具体而言,函数ls不会实现完整转换 API 执行的参数glob

最新更新