From b19c90b9a65727b1110fca25a0c63c3ee3ee6967 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 31 Jul 2022 22:10:58 +0200 Subject: [PATCH] export centroid to tokenizer May come in handy when developping sanitizers for an area smaller than country size. --- lib-sql/functions/placex_triggers.sql | 6 +++++- nominatim/data/place_info.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib-sql/functions/placex_triggers.sql b/lib-sql/functions/placex_triggers.sql index 29f645cb..70071b2f 100644 --- a/lib-sql/functions/placex_triggers.sql +++ b/lib-sql/functions/placex_triggers.sql @@ -16,7 +16,9 @@ CREATE TYPE prepare_update_info AS ( country_code TEXT, class TEXT, type TEXT, - linked_place_id BIGINT + linked_place_id BIGINT, + centroid_x float, + centroid_y float ); -- Retrieve the data needed by the indexer for updating the place. @@ -71,6 +73,8 @@ BEGIN result.type := p.type; result.country_code := p.country_code; result.rank_address := p.rank_address; + result.centroid_x := ST_X(p.centroid); + result.centroid_y := ST_Y(p.centroid); -- Names of linked places need to be merged in, so search for a linkable -- place already here. diff --git a/nominatim/data/place_info.py b/nominatim/data/place_info.py index ab895352..1bfd512c 100644 --- a/nominatim/data/place_info.py +++ b/nominatim/data/place_info.py @@ -8,7 +8,7 @@ Wrapper around place information the indexer gets from the database and hands to the tokenizer. """ -from typing import Optional, Mapping, Any +from typing import Optional, Mapping, Any, Tuple class PlaceInfo: """ This data class contains all information the tokenizer can access @@ -62,6 +62,15 @@ class PlaceInfo: return self._info.get('rank_address', 0) + @property + def centroid(self) -> Optional[Tuple[float, float]]: + """ A center point of the place in WGS84. May be None when the + geometry of the place is unknown. + """ + x, y = self._info.get('centroid_x'), self._info.get('centroid_y') + return None if x is None or y is None else (x, y) + + def is_a(self, key: str, value: str) -> bool: """ Set to True when the place's primary tag corresponds to the given key and value.