Skip to Content

Shapely - SQLObject - PostGIS

  1. >>> from sqlobject import *
  2. >>> from shapely.wkb import loads
  3. >>> db='postgres://localhost:5432/testpostgis'
  4. >>> connection = connectionForURI(db)
  5. >>> class testpoly(SQLObject):
  6. ... _connection = connection
  7. ... _fromDatabase = True
  8. ... the_geom = StringCol()
  9. ... def _get_geom(self):
  10. ... value = self._SO_get_the_geom()
  11. ... test = loads(value.decode('hex')).wkt
  12. ... return test
  13. ...
  14. >>> a = testpoly.get(1)
  15. >>> a.geom
  16. 'POLYGON ((0.0909447004608300 0.8075576036866360, 0.1416359447004610 0.8014746543778800, 0.3606221198156680 0.7021198156682030, 0.2409907834101380 0.5480184331797230, 0.0868894009216590 0.5845161290322580, 0.0544470046082950 0.7426728110599080, 0.0909447004608300 0.8075576036866360))'
  17. >>>