Skip to content

Commit 519538d

Browse files
committed
reduce geojson maps precision and remove osm id
1 parent 0b7c2b5 commit 519538d

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

functions-python/helpers/locations.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,27 @@ def get_geopolygons_covers(stop_point: WKTElement, db_session: Session):
231231
).all()
232232
)
233233
return geopolygons
234+
235+
236+
def round_geojson_coords(geometry, precision=5):
237+
"""Recursively round coordinates in a GeoJSON geometry dict to the given precision."""
238+
if isinstance(geometry, dict):
239+
if "coordinates" in geometry:
240+
geometry = geometry.copy()
241+
geometry["coordinates"] = round_coords(geometry["coordinates"], precision)
242+
if "geometries" in geometry: # GeometryCollection
243+
geometry = geometry.copy()
244+
geometry["geometries"] = [
245+
round_geojson_coords(g, precision) for g in geometry["geometries"]
246+
]
247+
return geometry
248+
return geometry
249+
250+
251+
def round_coords(coords, precision):
252+
if isinstance(coords, (list, tuple)):
253+
if coords and isinstance(coords[0], (list, tuple)):
254+
return [round_coords(c, precision) for c in coords]
255+
else:
256+
return [round(float(c), precision) for c in coords]
257+
return coords

functions-python/reverse_geolocation/src/reverse_geolocation_processor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
)
3737
from shared.dataset_service.dataset_service_commons import Status
3838

39-
from shared.helpers.locations import ReverseGeocodingStrategy
39+
from shared.helpers.locations import ReverseGeocodingStrategy, round_geojson_coords
4040
from shared.helpers.logger import get_logger
4141
from shared.helpers.runtime_metrics import track_metrics
4242
from shared.helpers.utils import (
@@ -169,9 +169,10 @@ def create_geojson_aggregate(
169169
"features": [
170170
{
171171
"type": "Feature",
172-
"geometry": mapping(geo_polygon_count[osm_id]["clipped_geometry"]),
172+
"geometry": round_geojson_coords(
173+
mapping(geo_polygon_count[osm_id]["clipped_geometry"])
174+
),
173175
"properties": {
174-
"osm_id": osm_id,
175176
"country_code": geo_polygon_count[osm_id]["group"].iso_3166_1_code,
176177
"subdivision_code": geo_polygon_count[osm_id][
177178
"group"

functions-python/reverse_geolocation/tests/test_reverse_geolocation_processor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ def test_create_geojson_aggregate(self, mock_getenv, mock_storage_client):
329329
self.assertEqual(geojson_data["type"], "FeatureCollection")
330330
self.assertEqual(len(geojson_data["features"]), 1)
331331
feature = geojson_data["features"][0]
332-
self.assertEqual(feature["properties"]["osm_id"], str(geopolygon_1.osm_id))
333332
self.assertEqual(
334333
feature["properties"]["country_code"], geopolygon_1.iso_3166_1_code
335334
)

web-app/src/app/components/PopupTable.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ interface PopupTableProps {
1818
}
1919

2020
const fieldDescriptions: Record<string, { description?: string }> = {
21-
osm_id: {
22-
description: 'OpenStreetMap ID of the geographic area.',
23-
},
2421
stops_in_area: {
2522
description:
2623
'This is the number of stops in stops.txt that are located within this geographic area.',

0 commit comments

Comments
 (0)