Thanks, will test it tomorrow. Examples with long/lat inserts, extracts and distance comparisons would also be handy for the book.
On Sun, Dec 23, 2012 at 4:50 AM, Massimo Di Pierro < massimo.dipie...@gmail.com> wrote: > I made some changes to the DAL geo APIs. This is an experimental feature > so we are allowed to make changes. Anyway, the changes should be backward > compatible. The only issue is that I am documenting the geodal api in the > book and I would not want to change them later. > > Can you please check them: > > The DAL supports geographical APIs using PostGIS (for PostgreSQL), > spatialite (for SQLite), and MSSQL and Spatial Extensions. > > DAL provides geometry and geography fields types and the following > functions: > > st_asgeojson (PostGIS only) > st_astext > st_contained > st_contains > st_distance > st_equals > st_intersects > st_overlaps > st_simplify (PostGIS only) > st_touches > st_within > > examples: > > >>> from gluon.dal import DAL, Field, geoPoint, geoLine, geoPolygon > >>> db = DAL("mssql://user:pass@host:db") > >>> sp = db.define_table('spatial',Field('loc','geometry()')) > > >>> sp.insert(loc=geoPoint(1,1)) > >>> sp.insert(loc=geoLine((100,100),(20,180),(180,180))) > >>> sp.insert(loc=geoPolygon((0,0),(150,0),(150,150),(0,150),(0,0))) > > > >>> print db(sp.id>0).select() > spatial.id,spatial.loc > 1, POINT (1 2)" > 2, LINESTRING (100 100, 20 180, 180 180) > 3, POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0)) > > >>> query = sp.loc.st_intersects(geoLine((20,120),(60,160))) > >>> query = > sp.loc.st_overlaps(geoPolygon((1,1),(11,1),(11,11),(11,1),(1,1))) > >>> query = sp.loc.st_contains(geoPoint(1,1)) > >>> print db(query).select(sp.id,sp.loc) > spatial.id,spatial.loc > 3,"POLYGNON ((0 0, 150 0, 150 150, 0 150, 0 0))" > > >>> dist = sp.loc.st_distance(geoPoint(-1,2)).with_alias('dist') > >>> print db(sp.id>0).select(sp.id, dist) > spatial.id, dist > 1 2.0 > 2 140.714249456 > 3 1.0 > > -- > > > > --