ST_PixelWidth — Returns the pixel width in geometric units of the spatial reference system.
double precision ST_PixelWidth(raster rast);
Returns the width of a pixel in geometric units of the spatial reference system. In the common case where there is no skew, the pixel width is just the scale ratio between geometric coordinates and raster pixels.
The following executable example draws the two pixel basis
vectors on the same coordinate frame as a skewed raster footprint.
The i direction vector is
(scaleX, skewY); the j direction
vector is (skewX, scaleY).
Pixel basis vectors and footprint for a raster with non-zero skew.
WITH raster AS (
SELECT ST_MakeEmptyRaster(
3, 3, 0, 0,
2, -3, 1, 0.5,
0
) AS rast
)
SELECT
ST_ConvexHull(rast) AS footprint,
ST_MakeLine(
ST_Point(0, 0),
ST_Point(ST_ScaleX(rast), ST_SkewY(rast))
) AS "i direction (scaleX, skewY)",
ST_MakeLine(
ST_Point(0, 0),
ST_Point(ST_SkewX(rast), ST_ScaleY(rast))
) AS "j direction (skewX, scaleY)"
FROM raster;
POLYGON((0 0,6 1.5,9 -7.5,3 -9,0 0)) | LINESTRING(0 0,2 0.5) | LINESTRING(0 0,1 -3)
Rasters with no skew.
SELECT ST_Width(rast) As rastwidth, ST_PixelWidth(rast) As pixwidth, ST_ScaleX(rast) As scalex, ST_ScaleY(rast) As scaley, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy FROM dummy_rast;
rastwidth | pixwidth | scalex | scaley | skewx | skewy -----------+----------+--------+--------+-------+---------- 10 | 2 | 2 | 3 | 0 | 0 5 | 0.05 | 0.05 | -0.05 | 0 | 0
Rasters with skew different than 0.
SELECT ST_Width(rast) As rastwidth, ST_PixelWidth(rast) As pixwidth, ST_ScaleX(rast) As scalex, ST_ScaleY(rast) As scaley, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy FROM (SELECT ST_SetSkew(rast, 0.5, 0.5) As rast FROM dummy_rast) As skewed;
rastwidth | pixwidth | scalex | scaley | skewx | skewy -----------+-------------------+--------+--------+-------+---------- 10 | 2.06155281280883 | 2 | 3 | 0.5 | 0.5 5 | 0.502493781056044 | 0.05 | -0.05 | 0.5 | 0.5