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: Bborie Park
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 Bborie Park, 10 years ago

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 by pracine, 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?

in reply to:  2 comment:3 by pracine, 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!

comment:4 by strk, 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).

in reply to:  4 comment:5 by pracine, 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 Bborie Park, 9 years ago

Milestone: PostGIS 2.2.0PostGIS Future

comment:7 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.