numBands, SRID and the corner, scale and skew accessors read the grid of a PostGIS raster; width, height and the band accessors read a raster and a raquet tile alike, and the other accessors read a raquet tile.
A raquet value is self-describing: the accessors below read back the georeferencing and layout it carries, so a tile packaged with the raquet constructor or decoded with raquetRead can be inspected without keeping the loose columns it was built from.
Return the first, the last, or the nth distinct cell identifier of a temporal value
startValue(tcell) → cell endValue(tcell) → cell valueN(tcell,integer) → cell
valueN counts from one and returns NULL when n is out of range.
SELECT startValue(th3index '831c02fffffffff@2001-01-01');
-- 831c02fffffffff
SELECT endValue(th3index '{831c02fffffffff@2001-01-01, 831c00fffffffff@2001-01-02}');
-- 831c00fffffffff
SELECT valueN(th3index '{831c02fffffffff@2001-01-01, 831c00fffffffff@2001-01-02}', 1);
-- 831c02fffffffff
SELECT startValue(tquadbin '48a6227affffffff@2001-01-01');
-- 48a6227affffffff
SELECT endValue(tquadbin '{48a6227affffffff@2001-01-01, 485623ffffffffff@2001-01-02}');
-- 485623ffffffffff
SELECT valueN(tquadbin '{48a6227affffffff@2001-01-01, 485623ffffffffff@2001-01-02}', 1);
-- 48a6227affffffff
SELECT startValue(ts2cell '47c3c@2001-01-01');
-- 47c3c
SELECT endValue(ts2cell '{47c3c@2001-01-01, 47c4@2001-01-02}');
-- 47c4
SELECT valueN(ts2cell '{47c3c@2001-01-01, 47c4@2001-01-02}', 1);
-- 47c3c
Return the set of distinct cell identifiers the trajectory takes
getValues(tcell) → cellset
SELECT getValues(th3index '831c02fffffffff@2001-01-01');
-- {"831c02fffffffff"}
SELECT getValues(th3index '{831c02fffffffff@2001-01-01, 831c00fffffffff@2001-01-02}');
-- {"831c00fffffffff", "831c02fffffffff"}
SELECT getValues(tquadbin '48a6227affffffff@2001-01-01');
-- {"48a6227affffffff"}
SELECT getValues(tquadbin '{48a6227affffffff@2001-01-01, 485623ffffffffff@2001-01-02}');
-- {"485623ffffffffff", "48a6227affffffff"}
SELECT getValues(ts2cell '47c3c@2001-01-01');
-- {"47c3c"}
SELECT getValues(ts2cell '{47c3c@2001-01-01, 47c4@2001-01-02}');
-- {"47c3c", "47c4"}
Return the cell identifier at a given timestamp, using step interpolation
valueAtTimestamp(tcell,timestamptz) → cell
SELECT valueAtTimestamp(th3index '[831c02fffffffff@2001-01-01, 831c00fffffffff@2001-01-05]', '2001-01-03'); -- 831c02fffffffff SELECT valueAtTimestamp(tquadbin '[48a6227affffffff@2001-01-01, 485623ffffffffff@2001-01-05]', '2001-01-03'); -- 48a6227affffffff SELECT valueAtTimestamp(ts2cell '[47c3c@2001-01-01, 47c4@2001-01-05]', '2001-01-03'); -- 47c3c
Return the number of bands of a raster
numBands(raster) → integer
The band number accepted by rasterValue and by the operators built on it ranges from 1 to this value.
WITH rast1 AS (
SELECT ST_AddBand(ST_MakeEmptyRaster(3, 3, 0.0, 3.0, 1.0, -1.0, 0.0, 0.0, 4326),
'32BF'::text, 0.0::float8, NULL::float8 ) AS r ), rast2 AS (
SELECT ST_AddBand(r, '32BF'::text, 0.0::float8, NULL::float8) AS r FROM rast1 )
SELECT numBands((SELECT r FROM rast1)) AS num_bands_one,
numBands((SELECT r FROM rast2)) AS num_bands_two;
-- 1 | 2
Return the spatial reference system identifier of a raster
SRID(raster) → integer
SELECT SRID(ST_MakeEmptyRaster(3, 2, 0.0, 2.0, 1.0, -1.0, 0.0, 0.0, 3857)); -- 3857
Return the X or the Y coordinate of the upper left corner of a raster
upperLeftX(raster) → float8 upperLeftY(raster) → float8
The corner is the origin the geotransform states, which the skew rotates the grid about, so it is a corner of the extent only when both skews are zero.
SELECT upperLeftX(r), upperLeftY(r) FROM (SELECT ST_MakeEmptyRaster(3, 2, 10.0, 20.0, 1.5, -2.0, 0.5, 0.25, 3857) AS r) t; -- 10 | 20
Return the pixel width or the pixel height of a raster, that is, the X or the Y component of its scale
scaleX(raster) → float8 scaleY(raster) → float8
The pixel height is negative for a grid whose rows run north to south, which is how a raster is ordinarily written.
SELECT scaleX(r), scaleY(r) FROM (SELECT ST_MakeEmptyRaster(3, 2, 10.0, 20.0, 1.5, -2.0, 0.5, 0.25, 3857) AS r) t; -- 1.5 | -2
Return the X or the Y component of the skew of a raster
skewX(raster) → float8 skewY(raster) → float8
A raster whose two skews are zero is axis-aligned.
SELECT skewX(r), skewY(r) FROM (SELECT ST_MakeEmptyRaster(3, 2, 10.0, 20.0, 1.5, -2.0, 0.5, 0.25, 3857) AS r) t; -- 0.5 | 0.25
Return the QUADBIN cell of a Raquet tile
quadbin(raquet) → quadbin
SELECT quadbin(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff', 'uint8'));
-- 4817ffffffffffff
Return the width in pixels of a raster or a Raquet tile
width({raster,raquet}) → integer
SELECT width(ST_MakeEmptyRaster(3, 2, 0.0, 2.0, 1.0, -1.0, 0.0, 0.0, 4326));
-- 3
SELECT width(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff', 'uint8'));
-- 2
Return the height in pixels of a raster or a Raquet tile
height({raster,raquet}) → integer
SELECT height(ST_MakeEmptyRaster(3, 2, 0.0, 2.0, 1.0, -1.0, 0.0, 0.0, 4326));
-- 2
SELECT height(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff', 'uint8'));
-- 2
Return the name of the pixel data type of a raster band or of a Raquet tile
bandPixelType(raster,band integer=1) → text bandPixelType(raquet) → text
The returned name is the one the constructors accept, that is, one of uint8, int8, uint16, int16, uint32, int32, uint64, int64, float16, float32, or float64. The constructors read the name without regard to case, so the name PostGIS raster gives a pixel type carries into them as it stands; the name returned here is the lower-case spelling the RaQuet specification gives a tile's type field, for a PostGIS band as for a tile, so a band and a tile of the same type report the same name.
SELECT bandPixelType(ST_AddBand(ST_MakeEmptyRaster(1, 1, 0, 0, 1), '16BSI'));
-- int16
-- Read back the layout of a packaged tile
SELECT quadbin(tile), width(tile), height(tile), bandPixelType(tile)
FROM (SELECT raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff', 'uint8')
AS tile) t;
-- 4817ffffffffffff | 2 | 2 | uint8
Return whether a raster band or a Raquet tile states a nodata value
bandHasNoDataValue(raster,band integer=1) → boolean bandHasNoDataValue(raquet) → boolean
A band that states none has no pixel to exclude, so every pixel it holds carries a value.
SELECT bandHasNoDataValue(ST_AddBand(ST_MakeEmptyRaster(1, 1, 0, 0, 1), '16BSI'::text,
0::float8, -9999::float8));
-- true
SELECT bandHasNoDataValue(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff',
'uint8'));
-- false
Return the nodata value of a raster band or of a Raquet tile
bandNoDataValue(raster,band integer=1) → float8 bandNoDataValue(raquet) → float8
A band that states no nodata value answers NULL.
SELECT bandNoDataValue(ST_AddBand(ST_MakeEmptyRaster(1, 1, 0, 0, 1), '16BSI'::text,
0::float8, -9999::float8));
-- -9999
SELECT bandNoDataValue(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff',
'uint8', 255));
-- 255
-- A tile built without a nodata value states none
SELECT bandNoDataValue(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff',
'uint8'));
-- NULL
Return the pixel bytes of a Raquet tile
pixels(raquet) → bytea
The bytes are row-major and packed, width × height pixels of the size of bandPixelType each, little-endian when a pixel is wider than one byte, which is the layout the constructors accept. A tile therefore round trips through its own accessors.
SELECT pixels(raquet('\x01020304'::bytea, 2, 2, quadbin '4817ffffffffffff', 'uint8'));
-- \x01020304