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

GeoPandas读取GML文件报错:跳过字段无效类型(1,0)求解决

解决GeoPandas读取GML时部分列因类型问题被跳过的问题

问题详情

使用GeoPandas的gpd.read_file()方法读取GML文件时,column_13aa、column_13ak、column_14aa、column_14ac这几个字段无法被读取,每个字段都会触发如下警告:

Skipping field attribute_name: invalid type (1, 0)

执行代码:

gdf = gpd.read_file(r'path_to_file/gml-file_neme.gml', driver='GML')

GML文件结构片段:

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs">...</wfs:FeatureCollection>

解决建议

  • 检查字段类型定义
    警告里的(1, 0)对应OGR的类型标识,其中1代表整数类型,但(1,0)通常意味着字段的精度/刻度值定义不符合OGR的解析规则。可以用GDAL的ogrinfo工具查看字段的详细信息:

    ogrinfo -al -so path_to_file/gml-file_neme.gml
    

    重点关注目标字段的Type、Width、Precision参数,确认是否存在异常定义。

  • 手动指定字段类型读取
    如果确认是类型解析的问题,可以通过schema参数强制指定字段类型:

    # 先获取默认schema并修改目标字段类型
    schema = gpd.io.file.infer_schema(r'path_to_file/gml-file_neme.gml', driver='GML')
    # 根据实际数据情况,将字段类型设为'int'或'str'
    target_cols = ['column_13aa', 'column_13ak', 'column_14aa', 'column_14ac']
    for col in target_cols:
        schema['properties'][col] = 'int'
    
    # 用修改后的schema读取文件
    gdf = gpd.read_file(r'path_to_file/gml-file_neme.gml', driver='GML', schema=schema)
    
  • 转换GML格式后读取
    要是上面的方法没用,可以先用GDAL的ogr2ogr工具把GML转成GeoJSON或Shapefile,再读取:

    ogr2ogr -f GeoJSON output.geojson path_to_file/gml-file_neme.gml
    

    读取转换后的文件:

    gdf = gpd.read_file('output.geojson')
    
  • 升级相关库版本
    老版本的GDAL或GeoPandas对部分GML类型的支持可能有缺陷,尝试升级:

    pip install --upgrade geopandas gdal
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 11:53:08