ST_SetValues — Retorna o raster modificado resultante dos valores de uma dada banda.
raster ST_SetValues(
raster rast, integer nband, integer columnx, integer rowy, double precision[][] newvalueset, boolean[][] noset=NULL, boolean keepnodata=FALSE)
;
raster ST_SetValues(
raster rast, integer nband, integer columnx, integer rowy, double precision[][] newvalueset, double precision nosetvalue, boolean keepnodata=FALSE)
;
raster ST_SetValues(
raster rast, integer nband, integer columnx, integer rowy, integer width, integer height, double precision newvalue, boolean keepnodata=FALSE)
;
raster ST_SetValues(
raster rast, integer columnx, integer rowy, integer width, integer height, double precision newvalue, boolean keepnodata=FALSE)
;
raster ST_SetValues(
raster rast, integer nband, geomval[] geomvalset, boolean keepnodata=FALSE)
;
Retorna o raster modificado resultante dos valores especificados do pixel para novo valor(es) para a banda designada.
Se keepnodata
for VERDADE, aqueles pixeis cujos valores são NODATA não terão o valor correspondente em newvalueset
.
Para Variante 1, os pixeis específicos são determinados pela columnx
, rowy
coordenadas pixel e as dimensões do arranjo newvalueset
. noset
pode ser usado para prevenir pixeis com valores presentes no newvalueset
de serem estabelecidos ( PostgreSQL não permitindo arranjos ragged/jagged). Veja o exemplo de Variante 1.
Variante 2 é como a Variante 1, mas com uma precisão dupla simples nosetvalue
em vez de um arranjo booleano noset
. Elementos no newvalueset
com o valor nosetvalue
são pulados. Veja o exemplo da Variante 2.
Para Variante 3, os pixeis a serem estabelecidos são determinados pelas columnx
, rowy
coordenadas pixel, width
e height
. Veja o exemplo da Variante 3.
A Variante 4 é a mesma que a Variante 3, com a exceção de que ela assume que a primeira banda do pixel de rast
será estabelecida.
Para a Variante 5, um arranjo de geomval é usado para determinar os pixeis específicos. Se todas as geometrias no arranjo forem do tipo PONTO ou MULTIPONTO, a função usa um atalho onde a longitude e latitude de cada ponto é usada para pôr um pixel diretamente. Caso contrário, as geometrias são convertidas para rasters e então iteradas através de um passo. Veja o exemplo de Variante 5.
Disponibilidade: 2.1.0
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 1 | 1 | + - + - + - + + - + - + - + | 1 | 1 | 1 | = > | 1 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 2, 2, ARRAY[[9, 9], [9, 9]]::double precision[][] ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 2 | 1 | 1 2 | 2 | 9 2 | 3 | 9 3 | 1 | 1 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 9 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | = > | 9 | | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 9 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 1, 1, ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][] ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 9 1 | 2 | 9 1 | 3 | 9 2 | 1 | 9 2 | 2 | 2 | 3 | 9 3 | 1 | 9 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 9 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | => | 1 | | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 9 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 1, 1, ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][], ARRAY[[false], [true]]::boolean[][] ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 9 1 | 2 | 1 1 | 3 | 9 2 | 1 | 9 2 | 2 | 2 | 3 | 9 3 | 1 | 9 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | | 1 | 1 | | | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | => | 1 | | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 9 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_SetValue( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 1, 1, NULL ), 1, 1, 1, ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][], ARRAY[[false], [true]]::boolean[][], TRUE ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 | 2 | 1 1 | 3 | 9 2 | 1 | 9 2 | 2 | 2 | 3 | 9 3 | 1 | 9 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 1 | 1 | + - + - + - + + - + - + - + | 1 | 1 | 1 | => | 1 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 1, 1, ARRAY[[-1, -1, -1], [-1, 9, 9], [-1, 9, 9]]::double precision[][], -1 ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 2 | 1 | 1 2 | 2 | 9 2 | 3 | 9 3 | 1 | 1 3 | 2 | 9 3 | 3 | 9
/* This example is like the previous one. Instead of nosetvalue = -1, nosetvalue = NULL The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 1 | 1 | + - + - + - + + - + - + - + | 1 | 1 | 1 | => | 1 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 1, 1, ARRAY[[NULL, NULL, NULL], [NULL, 9, 9], [NULL, 9, 9]]::double precision[][], NULL::double precision ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 2 | 1 | 1 2 | 2 | 9 2 | 3 | 9 3 | 1 | 1 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 1 | 1 | + - + - + - + + - + - + - + | 1 | 1 | 1 | => | 1 | 9 | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 2, 2, 2, 2, 9 ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 2 | 1 | 1 2 | 2 | 9 2 | 3 | 9 3 | 1 | 1 3 | 2 | 9 3 | 3 | 9
/* The ST_SetValues() does the following... + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 1 | 1 | + - + - + - + + - + - + - + | 1 | | 1 | => | 1 | | 9 | + - + - + - + + - + - + - + | 1 | 1 | 1 | | 1 | 9 | 9 | + - + - + - + + - + - + - + */ SELECT (poly).x, (poly).y, (poly).val FROM ( SELECT ST_PixelAsPolygons( ST_SetValues( ST_SetValue( ST_AddBand( ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 1, 0 ), 1, 2, 2, NULL ), 1, 2, 2, 2, 2, 9, TRUE ) ) AS poly ) foo ORDER BY 1, 2; x | y | val ---+---+----- 1 | 1 | 1 1 | 2 | 1 1 | 3 | 1 2 | 1 | 1 2 | 2 | 2 | 3 | 9 3 | 1 | 1 3 | 2 | 9 3 | 3 | 9
WITH foo AS ( SELECT 1 AS rid, ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 0, 0) AS rast ), bar AS ( SELECT 1 AS gid, 'SRID=0;POINT(2.5 -2.5)'::geometry geom UNION ALL SELECT 2 AS gid, 'SRID=0;POLYGON((1 -1, 4 -1, 4 -4, 1 -4, 1 -1))'::geometry geom UNION ALL SELECT 3 AS gid, 'SRID=0;POLYGON((0 0, 5 0, 5 -1, 1 -1, 1 -4, 0 -4, 0 0))'::geometry geom UNION ALL SELECT 4 AS gid, 'SRID=0;MULTIPOINT(0 0, 4 4, 4 -4)'::geometry ) SELECT rid, gid, ST_DumpValues(ST_SetValue(rast, 1, geom, gid)) FROM foo t1 CROSS JOIN bar t2 ORDER BY rid, gid; rid | gid | st_dumpvalues -----+-----+--------------------------------------------------------------------------------------------------------------------------------------------- 1 | 1 | (1,"{{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,1,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL}}") 1 | 2 | (1,"{{NULL,NULL,NULL,NULL,NULL},{NULL,2,2,2,NULL},{NULL,2,2,2,NULL},{NULL,2,2,2,NULL},{NULL,NULL,NULL,NULL,NULL}}") 1 | 3 | (1,"{{3,3,3,3,3},{3,NULL,NULL,NULL,NULL},{3,NULL,NULL,NULL,NULL},{3,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL}}") 1 | 4 | (1,"{{4,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,NULL},{NULL,NULL,NULL,NULL,4}}") (4 rows)
A seguir está demonstrado que geomvals podem, mais tarde, sobrescrever no arranjo geomvals anteriores
WITH foo AS ( SELECT 1 AS rid, ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 0, 0) AS rast ), bar AS ( SELECT 1 AS gid, 'SRID=0;POINT(2.5 -2.5)'::geometry geom UNION ALL SELECT 2 AS gid, 'SRID=0;POLYGON((1 -1, 4 -1, 4 -4, 1 -4, 1 -1))'::geometry geom UNION ALL SELECT 3 AS gid, 'SRID=0;POLYGON((0 0, 5 0, 5 -1, 1 -1, 1 -4, 0 -4, 0 0))'::geometry geom UNION ALL SELECT 4 AS gid, 'SRID=0;MULTIPOINT(0 0, 4 4, 4 -4)'::geometry ) SELECT t1.rid, t2.gid, t3.gid, ST_DumpValues(ST_SetValues(rast, 1, ARRAY[ROW(t2.geom, t2.gid), ROW(t3.geom, t3.gid)]::geomval[])) FROM foo t1 CROSS JOIN bar t2 CROSS JOIN bar t3 WHERE t2.gid = 1 AND t3.gid = 2 ORDER BY t1.rid, t2.gid, t3.gid; rid | gid | gid | st_dumpvalues -----+-----+-----+--------------------------------------------------------------------------------------------------------------------- 1 | 1 | 2 | (1,"{{NULL,NULL,NULL,NULL,NULL},{NULL,2,2,2,NULL},{NULL,2,2,2,NULL},{NULL,2,2,2,NULL},{NULL,NULL,NULL,NULL,NULL}}") (1 row)
Este exemplo é o oposto do exemplo anterior
WITH foo AS ( SELECT 1 AS rid, ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 0, 0) AS rast ), bar AS ( SELECT 1 AS gid, 'SRID=0;POINT(2.5 -2.5)'::geometry geom UNION ALL SELECT 2 AS gid, 'SRID=0;POLYGON((1 -1, 4 -1, 4 -4, 1 -4, 1 -1))'::geometry geom UNION ALL SELECT 3 AS gid, 'SRID=0;POLYGON((0 0, 5 0, 5 -1, 1 -1, 1 -4, 0 -4, 0 0))'::geometry geom UNION ALL SELECT 4 AS gid, 'SRID=0;MULTIPOINT(0 0, 4 4, 4 -4)'::geometry ) SELECT t1.rid, t2.gid, t3.gid, ST_DumpValues(ST_SetValues(rast, 1, ARRAY[ROW(t2.geom, t2.gid), ROW(t3.geom, t3.gid)]::geomval[])) FROM foo t1 CROSS JOIN bar t2 CROSS JOIN bar t3 WHERE t2.gid = 2 AND t3.gid = 1 ORDER BY t1.rid, t2.gid, t3.gid; rid | gid | gid | st_dumpvalues -----+-----+-----+--------------------------------------------------------------------------------------------------------------------- 1 | 2 | 1 | (1,"{{NULL,NULL,NULL,NULL,NULL},{NULL,2,2,2,NULL},{NULL,2,1,2,NULL},{NULL,2,2,2,NULL},{NULL,NULL,NULL,NULL,NULL}}") (1 row)