Skip to content

Commit

Permalink
Fix geometry types (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
margrietpalm authored Jan 21, 2025
1 parent 729600a commit 7304a84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog of threedi-schema
0.230.1 (unreleased)
--------------------

- Nothing changed yet.
- Fix invalid geometry types for measure_map, memory_control and table_control


0.230.0 (2025-01-16)
Expand Down
20 changes: 15 additions & 5 deletions threedi_schema/migrations/versions/0230_reproject_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,22 @@ def get_model_srid() -> int:


def get_geom_type(table_name, geo_col_name):
# map geometry numbers to names
geom_type_map = {
1: 'POINT',
2: 'LINESTRING',
3: 'POLYGON',
4: 'MULTIPOINT',
5: 'MULTILINESTRING',
6: 'MULTIPOLYGON',
7: 'GEOMETRYCOLLECTION',
}
connection = op.get_bind()
columns = connection.execute(sa.text(f"PRAGMA table_info('{table_name}')")).fetchall()
for col in columns:
if col[1] == geo_col_name:
return col[2]

# use metadata to determine spatialite version because the geometry type column differs
srs_wkt_exists = connection.execute(sa.text("select count(name) from pragma_table_info('spatial_ref_sys') where name is 'srs_wkt'")).scalar() == 1
geom_type_name = 'type' if srs_wkt_exists else 'geometry_type'
geom_type_num = connection.execute(sa.text(f"SELECT {geom_type_name} from geometry_columns where f_table_name='{table_name}'")).fetchone()[0]
return geom_type_map.get(geom_type_num, 'GEOMETRY')

def add_geometry_column(table: str, name: str, srid: int, geometry_type: str):
# Adding geometry columns via alembic doesn't work
Expand Down

0 comments on commit 7304a84

Please sign in to comment.