首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用shapefile_to_dataframe()助手函数将shapefiles转换为数据文件- fiona相关错误

使用shapefile_to_dataframe()助手函数将shapefiles转换为数据文件- fiona相关错误
EN

Stack Overflow用户
提问于 2022-09-27 15:42:10
回答 1查看 71关注 0票数 1

我正在尝试使用Palantir函数shapefile_to_dataframe(),以便在以后的地理定位功能中使用shapefiles。

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

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

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

代码语言:javascript
复制
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))

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

代码语言:javascript
复制
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)

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-29 10:40:09

我能够重现这个错误,而且它似乎只发生在预览-运行完整的构建似乎很好。绕过它的最简单的方法是在函数中移动导入:

代码语言:javascript
复制
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.FileSystem API没有实现--具体来说,函数ls没有实现参数glob,这是完全转换的API所做的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73870305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档