[GeoAlchemy] BBox from resultset

185 views
Skip to first unread message

Frank Broniewski

unread,
May 18, 2010, 9:37:15 AM5/18/10
to geoal...@googlegroups.com
Hello,

maybe its just my blindness, but how would I query for the bounding box
of a resultset?

resultset:
layer = db_sesion.query(GAClass).all()

I know I can get the bbox by using session.scalar -> envelope, but that
works only on a concrete geometry ...

In postgis one would do
select extent(geom) from table
where extent is a aggregate function and returns a box2d

Many thanks for tipps


Frank




--
Frank BRONIEWSKI

METRICO s.ᅵ r.l.
gᅵomᅵtres
technologies d'information gᅵographique
rue des Romains 36
L-5433 NIEDERDONVEN

tᅵl.: +352 26 74 94 - 28
fax.: +352 26 74 94 99
http://www.metrico.lu

Tobias Sauerwein

unread,
May 18, 2010, 9:54:21 AM5/18/10
to geoal...@googlegroups.com
Hi Frank,

this should do the job:

session.query(func.extent(Spot.spot_location)).first()

With 'func.xyz(..)' you can call any database function, see also:
http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.func


Tobias


On Tue, May 18, 2010 at 3:37 PM, Frank Broniewski <br...@metrico.lu> wrote:
> Hello,
>
> maybe its just my blindness, but how would I query for the bounding box of a
> resultset?
>
> resultset:
> layer = db_sesion.query(GAClass).all()
>
> I know I can get the bbox by using session.scalar -> envelope, but that
> works only on a concrete geometry ...
>
> In postgis one would do
> select extent(geom) from table
> where extent is a aggregate function and returns a box2d
>
> Many thanks for tipps
>
>
> Frank
>
>
>
>
> --
> Frank BRONIEWSKI
>
> METRICO s.à r.l.
> géomètres
> technologies d'information géographique
> rue des Romains 36
> L-5433 NIEDERDONVEN
>
> tél.: +352 26 74 94 - 28

Frank Broniewski

unread,
May 19, 2010, 9:58:52 AM5/19/10
to geoal...@googlegroups.com
Hi Tobias,

your tip worked like a charm ... and helped me with just another
problem: restricting queries by bbox. Here's my code for this, which
makes use of the custom operator function from sqlalchemy.sql.operators

from sqlalchemy.sql.operators import op

winzer = db_session.query(LemoWinzer).filter(
LemoWinzer.geom.op('&&')(
func.setsrid(
func.box2d('BOX(90771 69171, 103118 81518)'), 2169
)
)
).count()
print winzer

Just for the archives and others who might be interested


Frank


Am 18.05.2010 15:54, schrieb Tobias Sauerwein:
> Hi Frank,
>
> this should do the job:
>
> session.query(func.extent(Spot.spot_location)).first()
>
> With 'func.xyz(..)' you can call any database function, see also:
> http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.func
>
>
> Tobias
>
>
> On Tue, May 18, 2010 at 3:37 PM, Frank Broniewski<br...@metrico.lu> wrote:
>> Hello,
>>
>> maybe its just my blindness, but how would I query for the bounding box of a
>> resultset?
>>
>> resultset:
>> layer = db_sesion.query(GAClass).all()
>>
>> I know I can get the bbox by using session.scalar -> envelope, but that
>> works only on a concrete geometry ...
>>
>> In postgis one would do
>> select extent(geom) from table
>> where extent is a aggregate function and returns a box2d
>>
>> Many thanks for tipps
>>
>>
>> Frank
>>
>>
>>
>>
>> --
>> Frank BRONIEWSKI
>>
>> METRICO s.� r.l.
>> g�om�tres
>> technologies d'information g�ographique
>> rue des Romains 36
>> L-5433 NIEDERDONVEN
>>
>> t�l.: +352 26 74 94 - 28
--
Frank BRONIEWSKI

METRICO s.� r.l.
g�om�tres
technologies d'information g�ographique
rue des Romains 36
L-5433 NIEDERDONVEN

t�l.: +352 26 74 94 - 28
Reply all
Reply to author
Forward
0 new messages