1

I am looking to update row values within specific fields of a polygon geopackage using an if statement--similar to how Esri users would use an Update Cursor . For example, say there is a text field called campsite with values ranging from 1W - 10W. I would like to change the value 10W to 20.

There is an example provided by @gene which seems to write a single value for each row in the attributes.

for feature in fiona.open(a shapefile): # = for row in cursor:
    feature['properties']['Elevation']= 15 # = row[1] = 15 

However, when I implement the solution using a geopackage the attributes do not change. Here is my attempt:

import fiona

gpkg = r'/path/to/campsites.gpkg'

for feature in fiona.open(gpkg): # = for row in cursor:
    if feature['properties']['Campsite'] == '10W':
        feature['properties']['Campsite'] = '20'

How can I update specific row values within a polygon geopackage using if/else control flow?

Aaron
  • 51,658
  • 28
  • 154
  • 317

0 Answers0