]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/db/sqlalchemy_types.py
band-aid for SQLAlchemy 1.4
[nominatim.git] / nominatim / db / sqlalchemy_types.py
index 5131dad3fd5bb7e4b09621187a75e094c0417908..c54d339e6d903b202ec1ad7e551ee881681c8856 100644 (file)
@@ -28,21 +28,23 @@ 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: 'sa.BindParameter[Any]') -> SaColumn:
         return sa.func.ST_GeomFromText(bindvalue, type_=self)
 
 
@@ -84,6 +86,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)