Hi,

I am working on the extension GeoAlchemy [1]. Currently GeoAlchemy
always fetches the data for the mapped geometry attributes in the
database internal format. I am trying to force GeoAlchemy to use the
format WKB for the communication with the database.

@compiles(MyColumn)
def compile_mycolumn(element, compiler, **kw):
    return "AsBinary(%s)" % element.name

I am using the compiler extension to query for the geometry in WKB. So
far this works fine for loading and inserting/updating mapped objects,
but it is getting a bit ugly for queries. Please consider to following
query:

session.query(MyPoint).filter(MyPoint.the_geom.within(polygon.the_geom)).first()

After modifying the SpatialComparator, the query send to the database
looks like this:

SELECT AsBinary(the_geom) AS tests_the_geom, tests.id AS tests_id,
tests.name AS tests_name
FROM tests
WHERE Within(GeomFromWKB(AsBinary(the_geom)), GeomFromWKB(%s))
 LIMIT 0, 1

For this query the method compile_mycolumn(..) is called two times:
one time for the select clause and one time for the where clause. The
first time it is intended, but the second time I have to do this round-
trip "GeomFromWKB(AsBinary(the_geom))" to make it work.


My question is: Is there a way to determine if the attribute is used
in the select clause, so that only then the name is surrounded by the
function call?

Or is there another possibility to use a different format than the
database internal?


Thank you,
Tobias


[1]: http://geoalchemy.org/

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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