Functions / PostGIS / ST_XMax
PostGISBounding Box

ST_XMax

What is ST_XMax?

ST_XMax is a PostGIS accessor that returns the maximum X (easting / longitude) coordinate of a geometry's bounding box.

SQL
1ST_XMax(geometry geom)float
2ST_XMax(box3d box)float

When would you use ST_XMax?

Use ST_XMax (together with ST_XMin, ST_YMin, ST_YMax) whenever you need the raw numeric extent of a geometry — for computing aspect ratios of map viewports, partitioning data by longitude bands, writing exports to formats that require explicit min/max coordinates, or generating WMS/WMTS BBOX strings.

SQL
1SELECT id,
2       ST_XMin(geom) AS xmin,
3       ST_YMin(geom) AS ymin,
4       ST_XMax(geom) AS xmax,
5       ST_YMax(geom) AS ymax
6FROM parcels;

FAQs

Does ST_XMax reflect coordinate values or vertex-max?

It returns the maximum X among all coordinates of the geometry — equivalent to the right edge of the 2D bounding box. It does not look at individual vertices beyond what's needed to compute the bbox.

What does ST_XMax return for an empty geometry?

Empty geometries have no bounding box and ST_XMax returns NULL. Use COALESCE or NOT ST_IsEmpty(geom) filters when aggregating.

Can ST_XMax accept a box3d?

Yes — there is an overload that takes box3d directly, returning the maximum X component. This is useful when you already have a box3d from ST_3DExtent or Box3D.

Does ST_XMax care about SRID?

No — it simply returns the numeric coordinate. If your data is in EPSG:4326, the value is longitude in degrees; in a projected CRS it is the easting in whatever unit the CRS uses. Interpretation is up to you.