PG_FUNCTION_INFO_V1(RASTER_out);
Datum RASTER_out(PG_FUNCTION_ARGS)
{
- elog(WARNING, "RASTER_out: Starting...");
rt_pgraster *pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
rt_raster raster = NULL;
uint32_t hexwkbsize = 0;
}
assert(0 <= (nband - 1));
- /* Validate pixel coordinates are in range */
- if (PG_ARGISNULL(2)) {
- elog(NOTICE, "X coordinate can not be NULL when getting pixel value. Returning NULL");
- PG_RETURN_NULL();
- }
x = PG_GETARG_INT32(2);
- if (PG_ARGISNULL(3)) {
- elog(NOTICE, "Y coordinate can not be NULL when getting pixel value. Returning NULL");
- PG_RETURN_NULL();
- }
y = PG_GETARG_INT32(3);
- if (!PG_ARGISNULL(4))
- hasnodata = PG_GETARG_BOOL(4);
+ hasnodata = PG_GETARG_BOOL(4);
POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
/* Set the pixel value */
if (PG_ARGISNULL(4)) {
if (!rt_band_get_hasnodata_flag(ctx, band)) {
- elog(NOTICE, "Raster do not have a nodata value defined. Pixel value not set. Returning raster");
+ elog(NOTICE, "Raster do not have a nodata value defined. Nodata value not set. Returning raster");
}
else {
pixvalue = rt_band_get_nodata(ctx, band);
Datum RASTER_copyband(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
- rt_raster raster1 = NULL;
- rt_raster raster2 = NULL;
- int nband1 = 0;
- int nband2 = 0;
- int oldnumbands = 0;
- int numbands = 0;
+ rt_raster torast = NULL;
+ rt_raster fromrast = NULL;
+ int toindex = 0;
+ int fromband = 0;
+ int oldtorastnumbands = 0;
+ int newtorastnumbands = 0;
int index = 0;
- int max = 0;
rt_context ctx = NULL;
- /* Get band numbers */
- nband1 = PG_GETARG_UINT16(2);
- nband2 = PG_GETARG_UINT16(3);
-
- if (nband1 < 1 || nband2 < 1) {
- elog(ERROR, "RASTER_copyband: Invalid band index (must be 1-based)");
+ /* Deserialize torast */
+ if (PG_ARGISNULL(0))
PG_RETURN_NULL();
- }
-
- /* Check if raster1 has the given band */
-
- /* Deserialize raster1 */
pgraster = (rt_pgraster *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
ctx = get_rt_context(fcinfo);
- raster1 = rt_raster_deserialize(ctx, pgraster);
- if ( ! raster1 ) {
- elog(ERROR, "RASTER_copyband: Could not deserialize raster");
+ torast = rt_raster_deserialize(ctx, pgraster);
+ if ( ! torast ) {
+ elog(ERROR, "RASTER_copyband: Could not deserialize first raster");
PG_RETURN_NULL();
}
- /* Make sure index (1 based) is in range */
- max = rt_raster_get_num_bands(ctx, raster1);
- if (nband1 > max) {
- elog(WARNING, "RASTER_copyband: Band index number exceed possible values, truncated to "
- "number of band (%u) + 1", max);
- nband1 = max;
- }
+ /* Deserialize fromrast */
+ if (!PG_ARGISNULL(1)) {
+ pgraster = (rt_pgraster *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
+ ctx = get_rt_context(fcinfo);
- /* Deserialize raster2 */
- pgraster = (rt_pgraster *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
- ctx = get_rt_context(fcinfo);
+ fromrast = rt_raster_deserialize(ctx, pgraster);
+ if ( ! fromrast ) {
+ elog(ERROR, "RASTER_copyband: Could not deserialize second raster");
+ PG_RETURN_NULL();
+ }
- raster2 = rt_raster_deserialize(ctx, pgraster);
- if ( ! raster2 ) {
- elog(ERROR, "RASTER_copyband: Could not deserialize raster");
- PG_RETURN_NULL();
- }
+ oldtorastnumbands = rt_raster_get_num_bands(ctx, torast);
+
+ if (PG_ARGISNULL(2))
+ fromband = 1;
+ else
+ fromband = PG_GETARG_UINT16(2);
- /* Copy band from raster1 to raster2 */
- oldnumbands = rt_raster_get_num_bands(ctx, raster2);
+ if (PG_ARGISNULL(3))
+ toindex = oldtorastnumbands + 1;
+ else
+ toindex = PG_GETARG_UINT16(2);
- index = rt_raster_copy_band(ctx, raster1, raster2, nband1, nband2);
+ /* Copy band fromrast torast */
+ index = rt_raster_copy_band(ctx, torast, fromrast, fromband - 1, toindex - 1);
- numbands = rt_raster_get_num_bands(ctx, raster2);
- if (numbands == oldnumbands || index == -1) {
- elog(ERROR, "RASTER_copyband: Could not add band to raster. Returning NULL");
- PG_RETURN_NULL();
+ newtorastnumbands = rt_raster_get_num_bands(ctx, torast);
+ if (newtorastnumbands == oldtorastnumbands || index == -1) {
+ elog(NOTICE, "RASTER_copyband: Could not add band to raster. Returning original raster.");
+ }
}
-
- /* Serialize and return raster2 */
- pgraster = rt_raster_serialize(ctx, raster2);
+ else
+ elog(NOTICE, "RASTER_copyband: Second raster is NULL. Returning original raster.");
+ /* Serialize and return torast */
+ pgraster = rt_raster_serialize(ctx, torast);
if (!pgraster) PG_RETURN_NULL();
SET_VARSIZE(pgraster, pgraster->size);
st_srid($1),
st_numbands($1)
$$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Constructors ST_MakeEmptyRaster and ST_AddBand
CREATE OR REPLACE FUNCTION st_makeemptyraster(width int, height int, upperleftx float8, upperlefty float8, scalex float8, scaley float8, skewx float8, skewy float8, srid int4)
RETURNS RASTER
AS 'MODULE_PATHNAME', 'RASTER_makeEmpty'
- LANGUAGE 'C' IMMUTABLE;
+ LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_makeemptyraster(width int, height int, upperleftx float8, upperlefty float8, scale float8)
RETURNS raster
AS 'select st_makeemptyraster($1, $2, $3, $4, $5, $5, 0, 0, -1)'
- LANGUAGE 'SQL' IMMUTABLE;
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_makeemptyraster(width int, height int, upperleftx float8, upperlefty float8, scalex float8, scaley float8, skewx float8, skewy float8)
RETURNS raster
AS 'select st_makeemptyraster($1, $2, $3, $4, $5, $6, $7, $8, -1)'
- LANGUAGE 'SQL' IMMUTABLE;
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_makeemptyraster(rast raster)
RETURNS raster
AS 'select st_makeemptyraster(st_width($1), st_height($1), st_upperleftx($1), st_upperlefty($1), st_scalex($1), st_scaley($1), st_skewx($1), st_skewy($1), st_srid($1))'
LANGUAGE 'SQL' IMMUTABLE STRICT;
+-- This function can not be STRICT, because nodataval can be NULL indicating that no nodata value should be set
CREATE OR REPLACE FUNCTION st_addband(rast raster, index int, pixeltype text, initialvalue float8, nodataval float8)
RETURNS RASTER
AS 'MODULE_PATHNAME', 'RASTER_addband'
CREATE OR REPLACE FUNCTION st_addband(rast raster, pixeltype text)
RETURNS raster
- AS 'select st_addband($1, NULL, $2, NULL, NULL)'
- LANGUAGE 'SQL' IMMUTABLE;
+ AS 'select st_addband($1, 1, $2, 0, NULL)'
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_addband(rast raster, pixeltype text, initialvalue float8)
RETURNS raster
- AS 'select st_addband($1, NULL, $2, $3, NULL)'
- LANGUAGE 'SQL' IMMUTABLE;
+ AS 'select st_addband($1, 1, $2, $3, NULL)'
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
+-- This function can not be STRICT, because nodataval can be NULL indicating that no nodata value should be set
CREATE OR REPLACE FUNCTION st_addband(rast raster, pixeltype text, initialvalue float8, nodataval float8)
RETURNS raster
- AS 'select st_addband($1, NULL, $2, $3, $4)'
+ AS 'select st_addband($1, 1, $2, $3, $4)'
LANGUAGE 'SQL' IMMUTABLE;
CREATE OR REPLACE FUNCTION st_addband(rast raster, index int, pixeltype text)
RETURNS raster
- AS 'select st_addband($1, $2, $3, NULL, NULL)'
- LANGUAGE 'SQL' IMMUTABLE;
+ AS 'select st_addband($1, $2, $3, 0, NULL)'
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_addband(rast raster, index int, pixeltype text, initialvalue float8)
RETURNS raster
AS 'select st_addband($1, $2, $3, $4, NULL)'
- LANGUAGE 'SQL' IMMUTABLE;
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
-CREATE OR REPLACE FUNCTION st_addband(raster1 raster, raster2 raster, nband1 int, nband2 int)
+-- This function can not be STRICT, because torastindex can not be determined (could be st_numbands(raster) though)
+CREATE OR REPLACE FUNCTION st_addband(torast raster, fromrast raster, fromband int, torastindex int)
RETURNS RASTER
AS 'MODULE_PATHNAME', 'RASTER_copyband'
- LANGUAGE 'C' IMMUTABLE STRICT;
-
-CREATE OR REPLACE FUNCTION st_addband(raster1 raster, raster2 raster, nband int)
- RETURNS RASTER
- AS 'select st_addband($1, $2, st_numbands($1), $3)'
- LANGUAGE 'SQL' IMMUTABLE;
+ LANGUAGE 'C' IMMUTABLE;
-CREATE OR REPLACE FUNCTION st_addband(raster1 raster, raster2 raster)
- RETURNS RASTER
- AS 'select st_addband($1, $2, st_numbands($1), st_numbands($2) + 1)'
- LANGUAGE 'SQL' IMMUTABLE;
+CREATE OR REPLACE FUNCTION st_addband(torast raster, fromrast raster, fromband int)
+ RETURNS raster
+ AS 'select st_addband($1, $2, $3, NULL)'
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
+CREATE OR REPLACE FUNCTION st_addband(torast raster, fromrast raster)
+ RETURNS raster
+ AS 'select st_addband($1, $2, 1, NULL)'
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- MapAlgebra
-----------------------------------------------------------------------
+-- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though)
+-- or pixeltype can not be determined (could be st_bandpixeltype(raster, band) though)
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, band integer,
expression text, nodatavalueexpr text, pixeltype text)
RETURNS raster
expression text)
RETURNS raster
AS $$ SELECT st_mapalgebra($1, $2, $3, NULL, NULL) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, expression text,
pixeltype text)
RETURNS raster
AS $$ SELECT st_mapalgebra($1, 1, $2, NULL, $3) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, expression text)
RETURNS raster
AS $$ SELECT st_mapalgebra($1, 1, $2, NULL, NULL) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
+-- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though)
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, band integer,
expression text, nodatavalueexpr text)
RETURNS raster
AS $$ SELECT st_mapalgebra($1, $2, $3, $4, NULL) $$
LANGUAGE SQL;
-
+-- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though)
+-- or pixeltype can not be determined (could be st_bandpixeltype(raster, band) though)
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, expression text,
nodatavalueexpr text, pixeltype text)
RETURNS raster
AS $$ SELECT st_mapalgebra($1, 1, $2, $3, $4) $$
LANGUAGE SQL;
+-- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though)
CREATE OR REPLACE FUNCTION st_mapalgebra(rast raster, expression text,
nodatavalueexpr text)
RETURNS raster
CREATE OR REPLACE FUNCTION st_hasnoband(rast raster)
RETURNS boolean
AS 'select st_hasnoband($1, 1)'
- LANGUAGE 'SQL' IMMUTABLE;
+ LANGUAGE 'SQL' IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Raster Band Accessors
CREATE OR REPLACE FUNCTION st_bandnodatavalue(raster)
RETURNS float4
AS $$ SELECT st_bandnodatavalue($1, 1) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandisnodata(rast raster, band integer,
forceChecking boolean)
CREATE OR REPLACE FUNCTION st_bandisnodata(rast raster, forceChecking boolean)
RETURNS boolean
AS $$ SELECT st_bandisnodata($1, 1, $2) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandisnodata(rast raster, band integer)
RETURNS boolean
AS $$ SELECT st_bandisnodata($1, $2, FALSE) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandisnodata(rast raster)
RETURNS boolean
AS $$ SELECT st_bandisnodata($1, 1, FALSE) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandpath(rast raster, band integer)
RETURNS text
CREATE OR REPLACE FUNCTION st_bandpath(raster)
RETURNS text
AS $$ SELECT st_bandpath($1, 1) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandpixeltype(rast raster, band integer)
RETURNS text
CREATE OR REPLACE FUNCTION st_bandpixeltype(raster)
RETURNS text
AS $$ SELECT st_bandpixeltype($1, 1) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandmetadata(rast raster,
band int,
st_bandpath($1, $2) IS NOT NULL,
st_bandpath($1, $2)
$$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_bandmetadata(rast raster,
OUT pixeltype text,
st_bandpath($1, 1) IS NOT NULL,
st_bandpath($1, 1)
$$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Raster Pixel Accessors
CREATE OR REPLACE FUNCTION st_value(rast raster, band integer, x integer, y integer, hasnodata boolean)
RETURNS float8
AS 'MODULE_PATHNAME','RASTER_getPixelValue'
- LANGUAGE 'C' IMMUTABLE;
+ LANGUAGE 'C' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, band integer, x integer, y integer)
RETURNS float8
- AS $$ SELECT st_value($1, $2, $3, $4, NULL) $$
- LANGUAGE SQL;
+ AS $$ SELECT st_value($1, $2, $3, $4, TRUE) $$
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, x integer, y integer, hasnodata boolean)
RETURNS float8
AS $$ SELECT st_value($1, 1, $2, $3, $4) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, x integer, y integer)
RETURNS float8
- AS $$ SELECT st_value($1, 1, $2, $3, NULL) $$
- LANGUAGE SQL;
+ AS $$ SELECT st_value($1, 1, $2, $3, TRUE) $$
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, band integer, pt geometry, hasnodata boolean)
RETURNS float8 AS
hasnodata);
END;
$$
- LANGUAGE 'plpgsql' IMMUTABLE;
+ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, band integer, pt geometry)
RETURNS float8
- AS $$ SELECT st_value($1, $2, $3, NULL) $$
- LANGUAGE SQL;
+ AS $$ SELECT st_value($1, $2, $3, TRUE) $$
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, pt geometry, hasnodata boolean)
RETURNS float8
AS $$ SELECT st_value($1, 1, $2, $3) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_value(rast raster, pt geometry)
RETURNS float8
- AS $$ SELECT st_value($1, 1, $2, NULL) $$
- LANGUAGE SQL;
+ AS $$ SELECT st_value($1, 1, $2, TRUE) $$
+ LANGUAGE SQL IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Raster Accessors ST_Georeference()
-- Raster Band Editors
-----------------------------------------------------------------------
--- The function can not be strict, because allows NULL as nodata
+-- This function can not be STRICT, because nodatavalue can be NULL indicating that no nodata value should be set
CREATE OR REPLACE FUNCTION st_setbandnodatavalue(rast raster, band integer,
nodatavalue float8, forceChecking boolean)
RETURNS raster
AS 'MODULE_PATHNAME','RASTER_setBandNoDataValue'
LANGUAGE 'C' IMMUTABLE;
+-- This function can not be STRICT, because nodatavalue can be NULL indicating that no nodata value should be set
CREATE OR REPLACE FUNCTION st_setbandnodatavalue(rast raster, band integer, nodatavalue float8)
RETURNS raster
AS $$ SELECT st_setbandnodatavalue($1, $2, $3, FALSE) $$
LANGUAGE SQL;
+-- This function can not be STRICT, because nodatavalue can be NULL indicating that no nodata value should be set
CREATE OR REPLACE FUNCTION st_setbandnodatavalue(rast raster, nodatavalue float8)
RETURNS raster
AS $$ SELECT st_setbandnodatavalue($1, 1, $2, FALSE) $$
CREATE OR REPLACE FUNCTION st_setbandisnodata(rast raster)
RETURNS raster
AS $$ SELECT st_setbandisnodata($1, 1) $$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Raster Pixel Editors
-----------------------------------------------------------------------
+-- This function can not be STRICT, because newvalue can be NULL for nodata
CREATE OR REPLACE FUNCTION st_setvalue(rast raster, band integer, x integer, y integer, newvalue float8)
RETURNS raster
AS 'MODULE_PATHNAME','RASTER_setPixelValue'
LANGUAGE 'C' IMMUTABLE;
+-- This function can not be STRICT, because newvalue can be NULL for nodata
CREATE OR REPLACE FUNCTION st_setvalue(rast raster, x integer, y integer, newvalue float8)
RETURNS raster
AS $$ SELECT st_setvalue($1, 1, $2, $3, $4) $$
LANGUAGE SQL;
+-- This function can not be STRICT, because newvalue can be NULL for nodata
CREATE OR REPLACE FUNCTION st_setvalue(rast raster, band integer, pt geometry, newvalue float8)
RETURNS raster AS
$$
$$
LANGUAGE 'plpgsql' IMMUTABLE;
+-- This function can not be STRICT, because newvalue can be NULL for nodata
CREATE OR REPLACE FUNCTION st_setvalue(rast raster, pt geometry, newvalue float8)
RETURNS raster
AS $$ SELECT st_setvalue($1, 1, $2, $3) $$
);
END;
$$
- LANGUAGE 'plpgsql';
+ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION st_pixelaspolygon(rast raster, x integer, y integer)
RETURNS geometry AS
$$
SELECT st_pixelaspolygon($1, 1, $2, $3)
$$
- LANGUAGE SQL;
+ LANGUAGE SQL IMMUTABLE STRICT;
-----------------------------------------------------------------------
LANGUAGE 'plpgsql' IMMUTABLE STRICT;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(geometry, raster, integer)
RETURNS boolean AS
$$ SELECT $1 && $2 AND _st_intersects($1, $2, $3, TRUE);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(raster, integer, geometry)
RETURNS boolean AS
$$ SELECT st_intersects($3, $1, $2);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(geometry, raster)
RETURNS boolean AS
$$ SELECT st_intersects($1, $2, 1);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(raster, geometry)
RETURNS boolean AS
$$ SELECT st_intersects($2, $1, 1);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(geometry, raster, integer, boolean)
RETURNS boolean AS
$$ SELECT $1 && $2 AND _st_intersects($1, $2, $3, $4);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(raster, integer, boolean, geometry)
RETURNS boolean AS
$$ SELECT st_intersects($4, $1, $2, $3);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(geometry, raster, boolean)
RETURNS boolean AS
$$ SELECT st_intersects($1, $2, 1, $3);
$$ LANGUAGE 'SQL' IMMUTABLE;
+-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_intersects(raster, boolean, geometry)
RETURNS boolean AS
$$ SELECT st_intersects($3, $1, 1, $2);