Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question

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


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.