Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geometry types #173

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
spatial_ref_sys_cols = [item[0] for item in connection.execute(sa.text("select name from pragma_table_info('spatial_ref_sys')")).fetchall()]
geom_type_name = 'type' if "srs_wkt" in spatial_ref_sys_cols else 'geometry_type'
margrietpalm marked this conversation as resolved.
Show resolved Hide resolved
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
Loading