]> git.openstreetmap.org Git - nominatim.git/commitdiff
export centroid to tokenizer
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 31 Jul 2022 20:10:58 +0000 (22:10 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 31 Jul 2022 20:10:58 +0000 (22:10 +0200)
May come in handy when developping sanitizers for an area smaller
than country size.

lib-sql/functions/placex_triggers.sql
nominatim/data/place_info.py

index 29f645cb005af85b607b2c2a5ef1eab3f8a89755..70071b2f592f0c6a38f1a19a02bb0f7ddd95b8f1 100644 (file)
@@ -16,7 +16,9 @@ CREATE TYPE prepare_update_info AS (
   country_code TEXT,
   class TEXT,
   type TEXT,
   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.
 );
 
 -- 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.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.
 
   -- Names of linked places need to be merged in, so search for a linkable
   -- place already here.
index ab895352314581bacb84e23f13ebfa6aada2fe70..1bfd512c38e169e318373ff61a04aab3cd122f4f 100644 (file)
@@ -8,7 +8,7 @@
 Wrapper around place information the indexer gets from the database and hands to
 the tokenizer.
 """
 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
 
 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)
 
 
         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.
     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.