Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Oct 22, 2024
2 parents 28ca148 + 6a237a4 commit d76e326
Show file tree
Hide file tree
Showing 6 changed files with 1,584 additions and 851 deletions.
2,348 changes: 1,498 additions & 850 deletions data/accessibility_rules.csv

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
)
from services.utils import check_valid_concrete_field, strtobool
from services.utils.geocode_address import geocode_address
from services.utils.height_profile_geom import multilinestring_to_linestring_features

if settings.REST_FRAMEWORK and settings.REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"]:
DEFAULT_RENDERERS = [
Expand Down Expand Up @@ -913,6 +914,13 @@ def to_representation(self, obj):
elif "geometry_3d" in ret:
del ret["geometry_3d"]

if qparams.get("heightprofilegeom", "").lower() in ("true", "1"):
if obj.geometry_3d:
geometry = munigeo_api.geom_to_json(obj.geometry_3d, self.srs)
ret["height_profile_geom"] = multilinestring_to_linestring_features(
geometry.get("coordinates")
)

if qparams.get("accessibility_description", "").lower() in ("true", "1"):
ret["accessibility_description"] = shortcomings.accessibility_description

Expand Down
49 changes: 49 additions & 0 deletions services/tests/test_unit_view_set_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,52 @@ def test_provider_type_not_filter(api_client):
response = get(api_client, reverse("unit-list"), data={"provider_type__not": 2})
assert response.status_code == 200
assert response.data["count"] == 4


@pytest.mark.django_db
def test_heightprofilegeom_parameter(api_client):
create_units()
wkt = "MULTILINESTRING Z ((1 2 3, 4 5 6, 7 8 9), (10 11 12, 13 14 15, 16 17 18))"
geometry_3d = GEOSGeometry(wkt, srid=PROJECTION_SRID)
unit = Unit.objects.get(id=1)
unit.geometry_3d = geometry_3d
unit.save()

# When heightprofilegeom parameter is not given, height_profile_geom is not returned
response = get(api_client, reverse("unit-list"))
results = response.data["results"]
assert response.status_code == 200
assert "height_profile_geom" not in results

response = get(api_client, reverse("unit-list"), data={"heightprofilegeom": True})
results = response.data["results"]
assert response.status_code == 200
assert results[4]["id"] == 1
assert results[4]["height_profile_geom"]["type"] == "FeatureCollection"
assert (
results[4]["height_profile_geom"]["features"][0]["geometry"]["type"]
== "LineString"
)
assert (
results[4]["height_profile_geom"]["features"][0]["geometry"]["coordinates"]
== munigeo_api.geom_to_json(geometry_3d, DEFAULT_SRS)["coordinates"][0]
)
assert (
results[4]["height_profile_geom"]["features"][0]["properties"]["attributeType"]
== "flat"
)
assert (
results[4]["height_profile_geom"]["features"][1]["geometry"]["coordinates"]
== munigeo_api.geom_to_json(geometry_3d, DEFAULT_SRS)["coordinates"][1]
)
assert (
results[4]["height_profile_geom"]["features"][1]["properties"]["attributeType"]
== "flat"
)

assert results[4]["height_profile_geom"]["properties"]["summary"] == "Height"
assert results[4]["height_profile_geom"]["properties"]["label"] == "Height profile"
assert (
results[4]["height_profile_geom"]["properties"]["label_fi"] == "Korkeusprofiili"
)
assert results[4]["height_profile_geom"]["properties"]["label_sv"] == "Höjdprofil"
5 changes: 5 additions & 0 deletions services/utils/accessibility_shortcoming_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"en": "Service point",
},
"playground": {"fi": "Leikkipuisto", "sv": "Lekpark", "en": "Playground"},
"nature_site": {
"fi": "Luontokohde",
"sv": "Naturobjektet",
"en": "The nature site",
},
}


Expand Down
23 changes: 23 additions & 0 deletions services/utils/height_profile_geom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def multilinestring_to_linestring_features(coords):
if coords is None:
return None

return {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "LineString", "coordinates": line},
"properties": {
"attributeType": "flat"
}, # TODO: Add support for other types
}
for line in coords
],
"properties": {
"summary": "Height",
"label": "Height profile",
"label_fi": "Korkeusprofiili",
"label_sv": "Höjdprofil",
},
}
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="241015",
version="241022",
license="AGPLv3",
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit d76e326

Please sign in to comment.