2

I am trying to update the metadata on an already written .gdb with n layers. I would like to add the same metadata to each layer. When I read in the file and update the metadata dictionary, the added metadata is not saving.

I have reproduced below:


import geopandas as gpd
import pandas as pd
import fiona
from collections import OrderedDict

philly_layer_1 = gpd.read_file('https://opendata.arcgis.com/datasets/405ec3da942d4e20869d4e1449a2be48_0.geojson')
philly_layer_2 = philly_layer_1.copy()

philly_layer_1.to_file('test.gdb', layer = 'philly_1', driver = 'OpenFileGDB')
philly_layer_2.to_file('test.gdb', layer = 'philly_2', driver = 'OpenFileGDB')

philly_schema = {'properties': OrderedDict([('OBJECTID', 'int'),('SHAPE__AREA', 'float'),('Shape__Length', 'float')]),'geometry':'Polygon'}

df = fiona.open('test.gdb', 'w', layer=0, schema = philly_schema)
df.meta

{'driver': 'OpenFileGDB',
 'schema': {'properties': OrderedDict([('OBJECTID', 'int'),
               ('SHAPE__AREA', 'float'),
               ('Shape__Length', 'float')]),
  'geometry': 'Polygon'},
 'crs': CRS.from_wkt(''),
 'crs_wkt': ''}

When I run:

df.meta.update({'Publication Date': '2023-08-08'})
df.meta['Publication Date']

I am getting an error KeyError: 'Publication Date' because the metadata has not actually been updated.

I am hoping to see

{'driver': 'OpenFileGDB',
 'schema': {'properties': OrderedDict([('OBJECTID', 'int'),
               ('SHAPE__AREA', 'float'),
               ('Shape__Length', 'float')]),
  'geometry': 'Polygon'},
 'crs': CRS.from_wkt(''),
 'crs_wkt': '',
'Publication Date': '2023-08-08'
}

Is there a way to update the metadata in each layer of the geodatabase using an open source library?

1

1 Answer 1

1

fiona dataset .meta and .profile attributes are data source properties (e.g. driver, schema, crs) not content metadata.

Dataset tags can be used for this purpose. However, while they work with geopackages, they don't seem to work with file GDB data sources (for me using gdal 3.7 and fiona 1.9.4)

Example:

import geopandas as gpd
import fiona

philly_layer = gpd.read_file("https://opendata.arcgis.com/datasets/405ec3da942d4e20869d4e1449a2be48_0.geojson")

philly_layer.to_file("test.gpkg", layer="philly", driver="GPKG")
philly_layer.to_file("test.gdb", layer="philly", driver="OpenFileGDB")

with fiona.open("test.gpkg", "a", layer="philly") as df:
    df.update_tags({"Publication Date": "2023-08-08"})

with fiona.open("test.gdb", "a", layer="philly") as df:
    df.update_tags({"Publication Date": "2023-08-08"})

with fiona.open("test.gpkg", "r", layer="philly") as df:
    print(f"geopackage tags: {df.tags()}")

with fiona.open("test.gdb", "r", layer="philly") as df:
    print(f"gdb tags: {df.tags()}")

Output:

geopackage tags: {'Publication Date': '2023-08-08'}
gdb tags: {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.