How do you obtain the bounding box for a postgis database in terms of degrees (latitude in degrees and longitude in degrees)?
-
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.– elrobisAug 6, 2015 at 13:57
-
I was looking for the entire database.– suhas bhairavAug 7, 2015 at 9:44
Add a comment
|
1 Answer
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.
-
3I would reverse the order of the
ST_Transform
andST_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