Skip to content

Commit

Permalink
Fixes, deal with older versions of table definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoelvandenBerg committed Oct 11, 2024
1 parent 7c34bac commit 1e3e060
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions geopackage_validator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ def generate_geopackage_from_table_definition(
srs.ImportFromEPSG(projection)

for table in tables:
columns = {c["name"]: c["type"] for c in table["columns"]}

try:
columns = {c["name"]: c["type"] for c in table["columns"]}
except KeyError:
try:
columns = {c["name"]: c["data_type"] for c in table["columns"]}
except KeyError:
raise ValueError(
f"Table defintion is incomplete or its version is too old"
)
try:
geometry_type = OGR_GEOMETRY_TYPES[columns[table["geometry_column"]]]
except KeyError:
Expand All @@ -139,7 +146,14 @@ def generate_geopackage_from_table_definition(
if column["name"] != table["geometry_column"]
]
except KeyError:
raise ValueError(f"Unknown field type for table {table['name']}")
try:
fields = [
ogr.FieldDefn(column["name"], OGR_FIELD_TYPES[column["data_type"]])
for column in table["columns"]
if column["name"] != table["geometry_column"]
]
except KeyError:
raise ValueError(f"Unknown field type for table {table['name']}")

layer.CreateFields(fields)

Expand Down

0 comments on commit 1e3e060

Please sign in to comment.