I am trying to figure out how to best use SA to create a GIS query.
In my application I am actually using ORM objects and mappers, but to
keep my question focused on clauses and python expressions, I am just
trying to test this out without the ORM first.

The SQL query I would like to generate is this:

select AsText(the_geom), *
from pt
where SetSRID('BOX3D(-95.0 28.5, -95.8 28.8)'::box3d,4326) && the_geom and
      contains(SetSRID('BOX3D(-95.0 28.5, -95.8 28.8)'::box3d,4326), the_geom)
limit 100;

So far the best I have been able to come up with is this:

pt.select(
   sa.and_(
    pt.c.pos.op('&&')(func.SetSRID("'BOX3D(-95.0 28.5, -95.8
28.8)'::box3d",4326)),
    func.contains(func.SetSRID("'BOX3D(-95 28.5, -95.8
28.8)'::box3d",4326), pt.c.pos)
  )
)

Not the most readable way to represent it, but it seems to work.  I
have a couple questions though.

- I reuse "func.SetSRID("'BOX3D(-95 28.5, -95.8 28.8)'::box3d",4326)"
twice.  Is there a way to split this out into something I can just
reuse?

- Is there any way to write an extension "operator" or something that
could generate this for me?  If I had my way, I would want the query
to look like this:

pt.select( smart_contains( ((-95 28.5, -95.8 28.82), 4326), pt.c.pos))

- Can anyone point out a better way I could construct this query?  Is
there anything I am missing?


Thanks,
Allen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to