首页 > 解决方案 > 如何将 Fieldalytics API 检索的数据加载到 GeoPandas 中?

问题描述

我从 Fieldalytics API 检索地理边界数据:

y = getBoundary(fieldboundary)
print(y)

({'type': 'Polygon', 'coordinates': [[[-109.308557510376, 51.5768561748859], [-109.285554885864, 51.5768295045241], [-109.285640716553, 51.562505259384], [-109.308514595032, 51.5624785806018], [-109.308557510376, 51.5768561748859] ]]},<响应 [200]>,'https://api.efcsystems.com/boundary/ff2bf689-908f-4d17-bd59-183c16758e23?format=geojson&srid=4326&api_partner_guid=...&private_key=...')

然后我尝试将其加载到 GeoPandas 中:

import geopandas
d = geopandas.read_file(y[0])

我收到以下错误消息:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-59-0eb61a9b6cc3> in <module>
      1 import geopandas
----> 2 d = geopandas.read_file(y[0])
      3 
      4 
      5 #d.plot()

~/anaconda3/lib/python3.8/site-packages/geopandas/io/file.py in _read_file(filename, bbox, mask, rows, **kwargs)
    158 
    159     with fiona_env():
--> 160         with reader(path_or_bytes, **kwargs) as features:
    161 
    162             # In a future Fiona release the crs attribute of features will

~/anaconda3/lib/python3.8/site-packages/fiona/env.py in wrapper(*args, **kwargs)
    398     def wrapper(*args, **kwargs):
    399         if local._env:
--> 400             return f(*args, **kwargs)
    401         else:
    402             if isinstance(args[0], str):

~/anaconda3/lib/python3.8/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    251             path = ParsedPath(path, archive, scheme)
    252         else:
--> 253             path = parse_path(fp)
    254 
    255         if mode in ('a', 'r'):

~/anaconda3/lib/python3.8/site-packages/fiona/path.py in parse_path(path)
    130         return UnparsedPath(path)
    131 
--> 132     elif path.startswith('/vsi'):
    133         return UnparsedPath(path)
    134 

AttributeError: 'dict' object has no attribute 'startswith'

标签: pythonapidictionarygeospatialgeopandas

解决方案


推荐阅读