Opened 3 years ago

Last modified 2 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 Future
Component: raster Version: trunk
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 (6)

comment:1 Changed 3 years ago by dustymugs

Milestone: PostGIS 2.2.0

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.

comment:2 Changed 3 years ago by 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?

comment:3 in reply to:  2 Changed 3 years ago by pracine

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!

comment:4 Changed 3 years ago by 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.

I'm against adding more parameters (raster world is already over parametrized for my taste).

comment:5 in reply to:  4 Changed 3 years ago by pracine

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 Changed 2 years ago by dustymugs

Milestone: PostGIS 2.2.0PostGIS Future
Note: See TracTickets for help on using tickets.