【问题标题】:Shapefile output形状文件输出
【发布时间】:2025-11-27 15:45:01
【问题描述】:

我有制作 shapefile 的代码,但字段的数量取决于某些因素。目前我正在测试它的输入,我知道它会产生 3 个字段,所以有这个代码。

output = shapefile.Writer(shapefile.POINT)
for i in range(1,(input.fieldcount+1)):
     fieldname = "field" + str(i)
     output.field(fieldname,'C','40')

for i in range(len(output.item)):
       output.point(input.item[i].x,input.item[i].y)
        graphshp.record(input.field[0],input.field[1],input.field[2])

但我想改变这一行:

        graphshp.record(input.field[0],input.field[1],input.field[2])

所以它不是硬编码的。

【问题讨论】:

    标签: python shapefile


    【解决方案1】:

    the pyshp source:

    您可以提交一系列字段值或关键字参数 字段名称和值。

    要提交一系列字段值,您应该这样做:

        graphshp.record( *input.field )
    

    如果您有兴趣,Python 的excellent documentation 中涵盖了任意参数列表。

    【讨论】: