So, in addition to st_transform, I would add st_aswkb. This isn't an 
official Postgis command - it provides a method to bypass the automatic 
conversion to WKT found in here:

https://github.com/web2py/pydal/blob/master/pydal/adapters/base.py#L550

With a suitably modified PostgreRepresenter, that then allows this:


from pydal import geoPoint, geoLine, geoPolygon

trans_test = db.define_table('transform_test', 
                             Field('point', 'geometry()'), 
                             Field('point_wec', 'geometry(public, 4087, 2)'
))

trans_test.bulk_insert([{'point': geoPoint(0,0)}, {'point': geoPoint(3,0)}])
# [1L, 2L]

db(db.transform_test).select().as_list()
# [{'id': 1L, 'point': 'POINT(0 0)', 'point_wec': None},
#  {'id': 2L, 'point': 'POINT(3 0)', 'point_wec': None}]

copy_wkb = db(db.transform_test.id == 1).select(db.transform_test.point.
st_aswkb().with_alias('wkb')).first()

rec = db.transform_test[2]
rec.update_record(point=copy_wkb['wkb'])
# <Row {'point_wec': None, 'id': 2L, 'point': 
'0101000020E610000000000000000000000000000000000000'}>

db(db.transform_test).select().as_list()
# [{'id': 1L, 'point': 'POINT(0 0)', 'point_wec': None},
#  {'id': 2L, 'point': 'POINT(0 0)', 'point_wec': None}]

This avoids the round trip through WKT. 

Note also that the extended WKB provided by PostGIS contains a reference to 
the geometry SRID, so trying to update a field with a different SRID gets 
caught, as you might hope.

In [10]: rec.update_record(point_wec=copy_wkb['wkb'])
---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)
# <snip>
ProgrammingError: ('ERROR', '22023', 'Geometry SRID (4326) does not match 
column SRID (4087)')

I don't think this breaks any existing functions. 

Cheers,
David



-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to