]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/db/sqlalchemy_types.py
fix linting issues
[nominatim.git] / nominatim / db / sqlalchemy_types.py
index 88cae29f3a4e8982c60b32c33efc668ab88d7053..f5ec82bdbc4ef24b46d357c5ea060195b6302e68 100644 (file)
@@ -10,9 +10,11 @@ Custom types for SQLAlchemy.
 from typing import Callable, Any
 
 import sqlalchemy as sa
-import sqlalchemy.types as types
+from sqlalchemy import types
 
-from nominatim.typing import SaColumn
+from nominatim.typing import SaColumn, SaBind
+
+#pylint: disable=all
 
 class Geometry(types.UserDefinedType[Any]):
     """ Simplified type decorator for PostGIS geometry. This type
@@ -28,26 +30,31 @@ class Geometry(types.UserDefinedType[Any]):
         return f'GEOMETRY({self.subtype}, 4326)'
 
 
-    def bind_processor(self, dialect: sa.Dialect) -> Callable[[Any], str]:
+    def bind_processor(self, dialect: 'sa.Dialect') -> Callable[[Any], str]:
         def process(value: Any) -> str:
-            assert isinstance(value, str)
-            return value
+            if isinstance(value, str):
+                return 'SRID=4326;' + value
+
+            return 'SRID=4326;' + value.to_wkt()
         return process
 
 
-    def result_processor(self, dialect: sa.Dialect, coltype: object) -> Callable[[Any], str]:
+    def result_processor(self, dialect: 'sa.Dialect', coltype: object) -> Callable[[Any], str]:
         def process(value: Any) -> str:
             assert isinstance(value, str)
             return value
         return process
 
 
-    def bind_expression(self, bindvalue: sa.BindParameter[Any]) -> SaColumn:
+    def bind_expression(self, bindvalue: SaBind) -> SaColumn:
         return sa.func.ST_GeomFromText(bindvalue, type_=self)
 
 
     class comparator_factory(types.UserDefinedType.Comparator):
 
+        def intersects(self, other: SaColumn) -> 'sa.Operators':
+            return self.op('&&')(other)
+
         def is_line_like(self) -> SaColumn:
             return sa.func.ST_GeometryType(self, type_=sa.String).in_(('ST_LineString',
                                                                        'ST_MultiLineString'))
@@ -81,6 +88,10 @@ class Geometry(types.UserDefinedType[Any]):
             return sa.func.ST_Expand(self, other, type_=Geometry)
 
 
+        def ST_Collect(self) -> SaColumn:
+            return sa.func.ST_Collect(self, type_=Geometry)
+
+
         def ST_Centroid(self) -> SaColumn:
             return sa.func.ST_Centroid(self, type_=Geometry)