pythongeospatialfiona

Fiona: name 'rec' is not defined


I'm learning Python for GIS operations and I would like to duplicate a shapefile with Fiona.

I'm trying to reproduct the 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()

When I use this code I see this error:

NameError: name 'rec' is not defined

It is the same code from the example except for file name and data folder.


Solution

  • You are missing the beginning of the documentation examples:

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