You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从DataFrame行的JSON字符串提取GeoDataFrame时遇AttributeError

解决GeoPandas解析带rings的几何结构报错问题

问题原因

你的GeoJSON数据采用了ArcGIS风格的几何结构(使用rings字段存储坐标),但不符合OGC标准GeoJSON的要求——标准格式下几何对象必须包含type字段(如Polygon),而你的geometry部分缺少该字段,导致GeoPandas解析时触发AttributeError: 'NoneType' object has no attribute 'lower'错误。

解决方案

预处理每个JSON特征,将ArcGIS风格的rings结构转换为标准GeoJSON的Polygon格式,为geometry添加type字段,并将rings的值映射到coordinates字段。

具体代码实现

import geopandas as gpd
import pandas as pd
import json

def convert_arcgis_geom_to_geojson(feature):
    geom = feature.get("geometry")
    if geom and "rings" in geom and "type" not in geom:
        # 将rings结构转为标准Polygon格式
        feature["geometry"] = {
            "type": "Polygon",
            "coordinates": geom["rings"]
        }
    return feature

# 预处理所有特征
processed_features = [convert_arcgis_geom_to_geojson(json.loads(feature)) for feature in dataFrame['value']]
# 生成GeoDataFrame
extractedJSON = gpd.GeoDataFrame.from_features(processed_features)

额外注意事项

检查你的原始JSON字符串是否存在语法错误:示例中OBJECTID的值写成了'ab100cd200(单引号未闭合且与外层双引号冲突),实际数据中需修正为"ab100cd200",否则json.loads会先触发解析错误。

内容的提问来源于stack exchange,提问作者William_Boot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 10:12:04