Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there an easy way to get the bounding box for an entire table in PostGIS?

Thanks

share|improve this question

3 Answers 3

ST_Extent should do the trick.

ST_Extent — an aggregate function that returns the bounding box that bounds rows of geometries.

Applied like this:

SELECT ST_Extent(the_geom) as table_extent FROM your_table;
share|improve this answer

As @underdark post, st_extent will do the job, but be aware that it will not return a geometry. If you need a geometry type you should use something like

SELECT ST_SetSRID(ST_Extent(the_geom),THE_SRID) as table_extent FROM your_table;

Also if what you need is get the bounding box of each of the rows i think that you can use this sentence:

SELECT ST_SetSRID(ST_Extent(the_geom),THE_SRID) as table_extent FROM your_table GROUP BY gid;

Assuming that gid is the primary key of the table

share|improve this answer

Based on that answer I'm trying to create new poygon layer that is extent of base layer (also polygon). But statement doesn't work:

CREATE OR REPLACE VIEW xxx.extent AS SELECT ST_SetSRID(ST_Extent(geom), 2180) as geom from xxx.buildings_2013;

But resulting table isn't spatial. Geometry column in table buildings_2013 is named geom.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.