Use PostGIS geometry types in SQLModel

824 Views Asked by At

Is it possible to use PostGIS geometry types in models created in SQLModel? If yes, how can it be done?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes it is.

Just take advantage of the sqlalchemy package that makes the work underneath SQLModel and the the GeoAlchemy2 package which is compatible with sqlalchemy and has already defined geometry types.

So,

from geoalchemy2 import Geometry
from sqlmodel import SQLModel, Field, Column

class Record(SQLModel, table=True):
    point: Any = Field(sa_column=Column(Geometry('POINT'))) # Here POINT is used but could be other geometries as well