# Get the width and height of a rectangular polygon in PostGIS

I have a table with point features saved in the my PostgreSQL database, and I can run the following query to get the extent of the point features and I turned the extent back into a geometry:

SELECT ST_AsText(ST_SetSRID(ST_Extent(pts.geom), 4026)) AS Extent_Geom

FROM Table_w_Point_Features pts


Here is how the output geometry of a rectangle polygon that represents the extent of the point features looks like:

POLYGON((-117.536012078 33.7130048820001,
-117.536012078 34.3860049530001,
-116.825011941 34.3860049530001,
-116.825011941 33.7130048820001,
-117.536012078 33.7130048820001))


Is there any way in PostGIS that I can get the Width and Height of the extent that I created above?

## 1 Answer

I'd go with the Geometry Accessors for X to give width: ST_XMax - ST_XMin, and the related functions for Y for height.

• I see your point, and I can use the Maximum and Minimum coordinates returned to calculate the width and length. Thanks! – Vanni Zhang Jun 28 '14 at 13:49