0

I need to find all Persons which are in radius of some point. Is possible to find on SQLAlchemy query level which persons are inside circle with center c =(x,y) and radius=r ?

class PersonModel(Base):
    x = Column(Float, nullable=False)
    y = Column(Float, nullable=False)
    # other data like name and so on

I can easily find all in square or iterate through all and then in python inside for loop eliminate all which are out but I wonder can I eliminate already at query level, it would be faster?

4

1 回答 1

0

我怀疑您需要sqlalchemy.func在一些数据库内距离函数上使用。一些空间数据库后端直接支持距离函数,例如 SpatiaLite 和 PostGIS,但您需要编写数据库内 SQL 函数才能调用。可以在此答案中找到使用 SQLA for SQLite 执行此操作的一个很好的示例。

于 2013-09-20T14:55:21.243 回答