2

How do you obtain the bounding box for a postgis database in terms of degrees (latitude in degrees and longitude in degrees)?

2
  • hmm.. are you wanting a bounding box for the entire DATABASE? Or a more granular asset in your database, like a table, collection of geometries, or just a singular geometry? Geometries and collections of geometries aren't so difficult (@alpha-beta-soup gave you the recipe), but getting the envelope of a complete table or of the database as a whole will require a little ingenuity.
    – elrobis
    Aug 6, 2015 at 13:57
  • I was looking for the entire database. Aug 7, 2015 at 9:44

1 Answer 1

4
SELECT ST_Extent(ST_Transform(the_geom,4326)) AS extent FROM sometable;

ST_Extent is an aggregate function.

ST_Transform takes an integer SRID as a second argument, so in this case it returns your geometry as WGS84 coordinates.

2
  • 3
    I would reverse the order of the ST_Transform and ST_Extent calls. Transform each coordinate and then get the extent of the reprojected points. The extreme points in each direction are not necessarily the same for the source and target CRS. Aug 6, 2015 at 14:14
  • Good point @MatthiasKuhn, I have edited the answer to transform before getting the extent. Aug 6, 2015 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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