0

I have this working query:

SELECT *
FROM my_table
WHERE my_table.the_geom && ST_MakeEnvelope(-75.97464419082118,39.523869271308314,-72.18532985820512,41.552541030492364);

and this is my (incorrect) attempt to recreate it with geoalchemy:

class ST_MakeEnvelope(GenericFunction):
    name = 'ST_MakeEnvelope'
    type = Geometry

box = "-75.97464419082118,39.523869271308314,-72.18532985820512,41.552541030492364"

results = my_table.query.filter(my_table.the_geom, ST_MakeEnvelope(box)).first()

gives me this error:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) argument of AND must be type boolean, not type geometry

I have not seen any documentation on how you can use the && operator. Is this possible? I really just need to execute the ST_MakeEnvelope function.

2

When you are doing

 filter(expr1, expr2)

you are telling SQLAlchemy to join the two expressions with an AND (see Query#filter). That's why you are getting the error message.

Regarding the operator &&, it can be used with function intersects:

MyModel.geom.intersects(other_geom)

Besides, there is a small issue with ST_MakeEnvelope, the coordinates should not be a string:

box = [-75.97464419082118,39.523869271308314,-72.18532985820512,41.552541030492364]
... .filter(my_table.the_geom.intersects(ST_MakeEnvelope(*box)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.