6

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 1

10

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

3
  • I see your point, and I can use the Maximum and Minimum coordinates returned to calculate the width and length. Thanks! Jun 28, 2014 at 13:49
  • what if your rectangle was tilted at an angle? The max x - min x would give a measurement that is too long.
    – Theo F
    Jul 29, 2022 at 13:30
  • The question is about an extent of points, the rectangle is the extent and therefore will not be tilted. Jul 29, 2022 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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