Skip to content

Instantly share code, notes, and snippets.

@nbessi
Created October 7, 2011 15:42
Show Gist options
  • Save nbessi/1270572 to your computer and use it in GitHub Desktop.
Save nbessi/1270572 to your computer and use it in GitHub Desktop.
GeoEngine Relational ORM support
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', Polygon([(3, 0), (4, 1), (4, 0)]))])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', 0)])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': []})])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': [('name','!=','Vallorbe')]})])
#will generate
"""
SELECT "res_better_zip".id FROM "res_better_zip" WHERE (res_better_zip."name" ilike E'%Lausanne%') AND ST_Area(res_better_zip.the_geom) > ST_Area(ST_GeomFromText('POLYGON ((3.0000000000000000 0.0000000000000000, 4.0000000000000000 1.0000000000000000, 4.0000000000000000 0.0000000000000000, 3.0000000000000000 0.0000000000000000))')) ORDER BY priority;
SELECT "res_better_zip".id FROM "res_better_zip" WHERE (res_better_zip."name" ilike E'%Lausanne%') AND ST_Area(res_better_zip.the_geom) > 0 ORDER BY priority;
SELECT "res_better_zip".id FROM "res_better_zip", geoengine_demo_automatic_retailing_machine WHERE (res_better_zip."name" ilike E'%Lausanne%') AND ( ST_Intersects(res_better_zip.the_geom, geoengine_demo_automatic_retailing_machine.the_point)) ORDER BY priority;
SELECT "res_better_zip".id FROM "res_better_zip", geoengine_demo_automatic_retailing_machine WHERE (res_better_zip."name" ilike E'%Lausanne%') AND ((geoengine_demo_automatic_retailing_machine."name" != E'Vallorbe') AND ST_Intersects(res_better_zip.the_geom, geoengine_demo_automatic_retailing_machine.the_point)) ORDER BY priority; """
@xrg
Copy link

xrg commented Oct 7, 2011

well, what if you could write : domain=[('name', 'ilike', 'Lausanne'), ('the_geom', '>', Polygon(...))] ??

stay tuned! ;)

@nbessi
Copy link
Author

nbessi commented Oct 7, 2011

That was the first idea, but we had two problems, first we have to manage the fact that any object in the ERP can be linked only by spatial relation, second expression.py did not allow us to du so … ;)

@nbessi
Copy link
Author

nbessi commented Oct 7, 2011

Sorry I did not get your point at first but I agree with you we can do better and only have one named parameter domain. I'm waiting for your patch ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment