菲奥娜:名称 'rec' 未定义

Fiona: name 'rec' is not defined

我正在学习 Python GIS 操作,我想用 Fiona 复制一个 shapefile。

我正在尝试重新制作 official example

import fiona

input_folder = '../test-input/'
input_data_name = 'input.shp'
input_data = input_folder+input_data_name

output_folder = '../test-output/'
output_data_name = 'output.shp'
output_data = output_folder+output_data_name


with fiona.open(input_data, 'r') as src:
    source_driver = src.driver
    source_crs = src.crs
    source_schema = src.schema

with fiona.open(
        output_data,
        'w',
        driver=source_driver,
        crs=source_crs,
        schema=source_schema
) as dup:
    dup.write(rec)
    dup.close()

当我使用这段代码时,我看到了这个错误:

NameError: name 'rec' is not defined

除文件名和数据文件夹外,代码与示例相同。

您缺少文档示例的开头:

with fiona.open('docs/data/test_uk.shp') as c:
    rec = next(c)