-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to uv, Fix typing issues, Use AIOHttp for improved performance
- Loading branch information
Showing
24 changed files
with
1,840 additions
and
3,063 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,61 @@ | ||
from shapely import MultiPolygon, Point, Polygon, from_wkb, get_coordinates | ||
from abc import ABC | ||
from typing import override | ||
|
||
from shapely import from_wkb, get_coordinates | ||
from shapely.geometry.base import BaseGeometry | ||
from sqlalchemy import BindParameter | ||
from sqlalchemy.sql import func | ||
from sqlalchemy.types import UserDefinedType | ||
|
||
|
||
class PointType(UserDefinedType): | ||
cache_ok = True | ||
class _GeometryType(UserDefinedType, ABC): | ||
geometry_type: str | ||
|
||
def get_col_spec(self, **kw): | ||
return 'geometry(Point, 4326)' | ||
|
||
def bind_expression(self, bindvalue: BindParameter): | ||
return func.ST_GeomFromText(bindvalue, 4326, type_=self) | ||
return f'geometry({self.geometry_type}, 4326)' | ||
|
||
@override | ||
def bind_processor(self, dialect): | ||
def process(value: Point | None): | ||
def process(value: BaseGeometry | None): | ||
if value is None: | ||
return None | ||
|
||
x, y = get_coordinates(value)[0] | ||
return f'POINT({x} {y})' # WKT | ||
return value.wkt | ||
|
||
return process | ||
|
||
def column_expression(self, col): | ||
return func.ST_AsBinary(col, type_=self) | ||
@override | ||
def bind_expression(self, bindvalue: BindParameter): | ||
return func.ST_GeomFromText(bindvalue, 4326, type_=self) | ||
|
||
@override | ||
def column_expression(self, colexpr): | ||
return func.ST_AsBinary(colexpr, type_=self) | ||
|
||
@override | ||
def result_processor(self, dialect, coltype): | ||
def process(value: bytes | None): | ||
if value is None: | ||
return None | ||
|
||
return from_wkb(value) | ||
|
||
return process | ||
|
||
|
||
class PolygonType(UserDefinedType): | ||
class PointType(_GeometryType): | ||
geometry_type = 'Point' | ||
cache_ok = True | ||
|
||
def get_col_spec(self, **kw): | ||
return 'geometry(Geometry, 4326)' | ||
|
||
def bind_expression(self, bindvalue: BindParameter): | ||
return func.ST_GeomFromText(bindvalue, 4326, type_=self) | ||
|
||
@override | ||
def bind_processor(self, dialect): | ||
def process(value: Polygon | MultiPolygon | None): | ||
def process(value: BaseGeometry | None): | ||
if value is None: | ||
return None | ||
|
||
return value.wkt | ||
x, y = get_coordinates(value)[0] | ||
return f'POINT({x} {y})' # WKT | ||
|
||
return process | ||
|
||
def column_expression(self, col): | ||
return func.ST_AsBinary(col, type_=self) | ||
|
||
def result_processor(self, dialect, coltype): | ||
def process(value: bytes | None): | ||
if value is None: | ||
return None | ||
|
||
return from_wkb(value) | ||
|
||
return process | ||
class PolygonType(_GeometryType): | ||
geometry_type = 'Polygon' | ||
cache_ok = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from typing import NamedTuple | ||
|
||
from shapely import MultiPolygon, Polygon | ||
from shapely.geometry import Point | ||
from shapely.geometry.base import BaseGeometry | ||
|
||
|
||
class OSMCountry(NamedTuple): | ||
tags: dict[str, str] | ||
geometry: BaseGeometry | ||
geometry: Polygon | MultiPolygon | ||
representative_point: Point | ||
timestamp: float |
Oops, something went wrong.