Opened 10 years ago
Last modified 7 years ago
#2807 new defect
[raster] ST_MapAlgebra injecting a default NODATA value of 0
Reported by: | strk | Owned by: | dustymugs |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS Fund Me |
Component: | raster | Version: | master |
Keywords: | Cc: |
Description
Both the callback-based and the expression-based ST_MapAlgebra functions are setting the NODATA flag in output and a nodata value of 0, even if the input has no NODATA flag at all.
This is a quick test for the expression based version:
select (ST_BandMetadata(ST_MapAlgebra(ST_AddBand(ST_MakeEmptyRaster(2, 2,0,0,1.0),'8BUI',255.0), 1, '8BUI','0'))).nodatavalue;
And this is a quick test for the callback based version:
create function cb(float8[][][], int[][], text[]) returns float8 as 'select 1::float8' language 'sql'; select (ST_BandMetadata(ST_MapAlgebra(ST_AddBand(ST_MakeEmptyRaster(2, 2,0,0,1.0),'8BUI',255.0), 1, 'cb(float8[][][],int[][],text[])'::regprocedure))).nodatavalue;
I don't think a NODATA should be injected. The documentation doesn't indeed mention anything about such enforcement.
Change History (7)
comment:1 by , 10 years ago
Milestone: | → PostGIS 2.2.0 |
---|
follow-up: 3 comment:2 by , 10 years ago
Humm… I guess ST_MapAlgebra() HAS to produce a raster with a NODATA value because you can never know if the result of the expression could end up being NULL… Make sence?
comment:3 by , 10 years ago
Replying to pracine:
Humm… I guess ST_MapAlgebra() HAS to produce a raster with a NODATA value because you can never know if the result of the expression could end up being NULL… Make sence?
There could be a switch though saying "No NODATA value" if you are sure your expression will never return a NULL, but then if does return NULL you get an unexpected value. If you don't like the fact that the resulting raster has a nodata value just ST_SetBandNoDataValue(rast, NULL) it!
follow-up: 5 comment:4 by , 10 years ago
I think it would make sense to throw an exception if the expression returns NULL and the input has no NODATA. A user should add a NODATA to the input prior to send to ST_MapAlgebra if she wants to allow for nodata.
I'm against adding more parameters (raster world is already over parametrized for my taste).
comment:5 by , 10 years ago
Replying to strk:
I think it would make sense to throw an exception if the expression returns NULL and the input has no NODATA. A user should add a NODATA to the input prior to send to ST_MapAlgebra if she wants to allow for nodata.
Agreed.
I'm against adding more parameters (raster world is already over parametrized for my taste).
I beg for more simple signatures offering the same flexibility.
comment:6 by , 10 years ago
Milestone: | PostGIS 2.2.0 → PostGIS Future |
---|
After reviewing the code, it looks like the decision to force a NODATA value was something decided a long time ago with Pierre and David Zwarg. By default, ST_MapAlgebra attempts to get the NODATA value from band referred to by the extent parameter. If the band has no NODATA value, it gets set to the minimum possible value for the pixel-type.
I have no problems with the output raster having no NODATA value if the input band has no NODATA value. Hopefully Pierre can chime in.