If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

 ingredients (ehm... requirements):

 

model.py

import ppygis

geometry = Field('the_geom', 'text',
    writable = False,
    represent = lambda value,row: '%s ...' % str(ppygis.Geometry.read_ewkb(value))[:50],
    label = 'Geometries',
)

migrate = True
tab_with_geom = db.define_table('tab_with_geom',
    Field('name'),
    geometry,
    migrate = migrate
)

if migrate:
    db.executesql('ALTER TABLE %s ALTER COLUMN %s TYPE geometry;' % ('tab_with_geom', 'the_geom'))

 

Retriving records:

 
geoms = db().select(db.tab_with_geom.the_geom)
geom = ppygis.Geometry.read_ewkb(geoms.first().the_geom)

inserting and updating:

db.tab_with_geom.insert(the_geom=my_geom.write_ewkb())
db(db.tab_with_geom.id==1).update(the_geom=my_geom.write_ewkb())
geometric objects can be easily created as explained in ppygis documentation
that's all :)
 
alternatively you may want to test the new geo spatial support provided from the newest trunk web2py version as explained in this post

Comments (0)


Hosting graciously provided by:
Python Anywhere