st_*() are db engine functions, you should query the db to get the output 
you are looking for. Given that, in your virtual field you should make a 
new query, something like that:

Field.Virtual('latitude', lambda row: db(db.location.id == row.location.id).
select(db.location.point.st_x()).first()[db.location.point.st_x()]

Paolo

On Thursday, January 2, 2014 9:59:14 PM UTC+1, Christian Foster Howes wrote:
>
> i bet that by the time your lambda is running the point has been converted 
> to a string already.  can you see if that is true?  i'm not sure how to 
> invoke db functions in a lambda of a virtual field. :(
>
> On Wednesday, January 1, 2014 5:50:54 PM UTC-8, User wrote:
>>
>> Suppose I have a table like:
>>
>> db.define_table('location',
>>     Field(name, 'string'),
>>     Field('point', 'geometry()')
>> )
>>
>> I want to have the latitude and longitude as attributes also (whose value 
>> can be derived from the point field).  So I try this:
>>
>> db.define_table('location',
>>     Field(name, 'string'),
>>     Field('point', 'geometry()'),
>>     Field.Virtual('latitude', lambda row: row.location.point.st_x()),
>>     Field.Virtual('longitude', lambda row: row.location.point.st_y()),
>> )
>>
>> But it doesn't work and fails silently.  The model just doesn't have 
>> latitude or longitude fields. I also tried with Field.Method but this 
>> complains that 'point' is of typer str.
>>
>> I guess the complication is that st_x() translates into a database 
>> function.  I'm thinking about parsing the point string which is of the form 
>> "POINT(x y)" as a workaround but I'd rather use st_x if someone can show me 
>> how.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to