Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
japauliina committed Nov 14, 2024
2 parents d76e326 + 595f480 commit 4cc1b59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
15 changes: 10 additions & 5 deletions services/management/commands/lipas_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,19 @@ def clean_name(name):
self._save_geometries(geometries, units_by_lipas_id)

def _save_geometries(self, geometries, units_by_lipas_id):
# Add all geometries we found to the db
logger.info("Updating geometries in the database...")
for lipas_id, geometry in geometries.items():
unit = units_by_lipas_id[lipas_id]
# FIXME: make sports map UI support simplified
# geometries and bring back simplification
# from commit 6cff46e0399fedbbc8266efa5230cd4ccb8a8485
unit.geometry = geometry
try:
line_geometry = geometry.merged
if isinstance(line_geometry, LineString):
line_geometry = MultiLineString([line_geometry])
unit.geometry = line_geometry
except TypeError as e:
logger.warning(
f"Failed to merge geometry for unit {unit.name_fi}: {e}",
)
unit.geometry = geometry
unit.save()

def _get_types(self):
Expand Down
17 changes: 15 additions & 2 deletions services/management/commands/lipas_import_3d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from django.contrib.gis.geos import LineString, MultiLineString

from services.management.commands import lipas_import

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -27,7 +29,18 @@ def _save_geometries(self, geometries, units_by_lipas_id):
for lipas_id, geometry in geometries.items():
unit = units_by_lipas_id[lipas_id]
if self._has_z_coordinate(geometry):
unit.geometry_3d = geometry
try:
line_geometry = geometry.merged
if isinstance(line_geometry, LineString):
line_geometry = MultiLineString([line_geometry])
unit.geometry_3d = line_geometry
if len(line_geometry) == 0:
unit.geometry_3d = geometry
except TypeError as e:
logger.warning(
f"Failed to merge 3D geometry for unit {unit.name_fi}: {e}",
)
unit.geometry_3d = geometry
unit.save()
else:
logger.warning(
Expand All @@ -41,4 +54,4 @@ def _has_z_coordinate(self, geometry):
"""
Check if a geometry has a Z-coordinate (3D).
"""
return "Z" in geometry.ewkt
return geometry.hasz
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="smbackend",
version="241022",
version="241114",
license="AGPLv3",
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit 4cc1b59

Please sign in to comment.