Fix some bugs

This commit is contained in:
Edward Betts 2023-11-02 09:11:11 +00:00
parent f0677e2468
commit 7603b33b2b

View file

@ -19,6 +19,7 @@ from sqlalchemy.orm import (
backref, backref,
column_property, column_property,
deferred, deferred,
mapped_column,
registry, registry,
relationship, relationship,
) )
@ -473,7 +474,7 @@ def location_objects(
return locations return locations
class MapBase(Base): class MapMixin:
"""Map base class.""" """Map base class."""
@declared_attr @declared_attr
@ -485,7 +486,7 @@ class MapBase(Base):
admin_level = Column(String) admin_level = Column(String)
boundary = Column(String) boundary = Column(String)
tags: Mapped[postgresql.HSTORE] tags: Mapped[postgresql.hstore] = mapped_column(postgresql.HSTORE)
@declared_attr @declared_attr
def way(cls): def way(cls):
@ -494,19 +495,19 @@ class MapBase(Base):
) )
@declared_attr @declared_attr
def kml(cls) -> sqlalchemy.orm.properties.ColumnProperty: def kml(cls) -> Mapped[str]:
"""Get object in KML format.""" """Get object in KML format."""
return column_property(func.ST_AsKML(cls.way), deferred=True) return column_property(func.ST_AsKML(cls.way), deferred=True)
@declared_attr @declared_attr
def geojson_str(cls) -> sqlalchemy.orm.properties.ColumnProperty: def geojson_str(cls) -> Mapped[str]:
"""Get object as GeoJSON string.""" """Get object as GeoJSON string."""
return column_property( return column_property(
func.ST_AsGeoJSON(cls.way, maxdecimaldigits=6), deferred=True func.ST_AsGeoJSON(cls.way, maxdecimaldigits=6), deferred=True
) )
@declared_attr @declared_attr
def as_EWKT(cls) -> sqlalchemy.orm.properties.ColumnProperty: def as_EWKT(cls) -> Mapped[str]:
"""As EWKT.""" """As EWKT."""
return column_property(func.ST_AsEWKT(cls.way), deferred=True) return column_property(func.ST_AsEWKT(cls.way), deferred=True)
@ -568,13 +569,13 @@ class MapBase(Base):
return f"https://www.openstreetmap.org/{self.type}/{self.id}" return f"https://www.openstreetmap.org/{self.type}/{self.id}"
class Point(MapBase): class Point(MapMixin, Base):
"""OSM planet point.""" """OSM planet point."""
type = "node" type = "node"
class Line(MapBase): class Line(MapMixin, Base):
"""OSM planet line.""" """OSM planet line."""
@property @property
@ -588,7 +589,7 @@ class Line(MapBase):
return cls.query.get(src_id) return cls.query.get(src_id)
class Polygon(MapBase): class Polygon(MapMixin, Base):
"""OSM planet polygon.""" """OSM planet polygon."""
way_area = Column(Float) way_area = Column(Float)