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

R语言sf包st_write写入Shapefile遇警告:要素未成功写入

问题:Shapefile保存时出现数值写入失败警告的原因

我保存Shapefile时执行了以下R代码:

# 数据信息
Simple feature collection with 337152 features and 35 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -137.9625 ymin: 5.495833 xmax: -52.61605 ymax: 62.74232
Geodetic CRS:  WGS 84

# 导出代码
st_write(sf_dat, 'temp.shp')

执行后收到50条类似如下的警告:

Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  ... :
  GDAL Message 1: Value 7120014530 of field hybas_id of feature 0 not successfully written. 
Possibly due to too larger number with respect to field width

警告原因解释

  • Shapefile格式的字段限制:Shapefile的属性字段有严格的类型和长度约束。其中32位有符号整数类型的最大值为2147483647,而你数据中的hybas_id字段值7120014530远超出这个范围。
  • GDAL写入校验机制:当GDAL尝试将超出字段存储范围的数值写入Shapefile时,会触发该警告,对应数值无法被正确写入到目标字段中。
  • 字段类型推断偏差:sf包导出Shapefile时会自动推断字段类型,若数据包含超大整数,sf可能默认设置了普通整数类型字段,未适配大整数的存储需求,进而引发写入失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 23:15:33