[MapServer-users] Distinguish between pixels outside of SCALE range and nodata pixels

Rahkonen Jukka jukka.rahkonen at maanmittauslaitos.fi
Mon Nov 28 09:24:48 PST 2022


Hi,

What is your nodata value and the datatype of the source raster? If you deal with byte or int16 data and the nodata value is 0, you can keep it unaltered in your LUT, then map values 1-9 into 1 that is almost black, range 10-19 as you wish, and 20 and above into white.

-Jukka Rahkonen-

Lähettäjä: Mallinger, Bernhard <bernhard.mallinger at eox.at>
Lähetetty: maanantai 28. marraskuuta 2022 16.53
Vastaanottaja: Rahkonen Jukka <jukka.rahkonen at maanmittauslaitos.fi>
Kopio: mapserver-users at lists.osgeo.org
Aihe: Re: [MapServer-users] Distinguish between pixels outside of SCALE range and nodata pixels

Thank you for the suggestion, I have tried it now.
Since the values below the minimum scale is mapped to 0, i tried using the following instruction:

PROCESSING "LUT=0:1"
This actually maps the values below the minimum to 1, but also the no data values. Do you know if there's a way where I can distinguish between those two using LUT?
Best,
Bernhard


On Mon, Nov 28, 2022 at 3:26 PM Rahkonen Jukka <jukka.rahkonen at maanmittauslaitos.fi<mailto:jukka.rahkonen at maanmittauslaitos.fi>> wrote:
Hi,

Have you tried the LUT processing option https://mapserver.org/input/raster.html<https://eur06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmapserver.org%2Finput%2Fraster.html&data=05%7C01%7Cjukka.rahkonen%40maanmittauslaitos.fi%7C046212920572444ef6f008dad1504c07%7Cc4f8a63255804a1c92371d5a571b71fa%7C0%7C0%7C638052440048006207%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hvl4h66%2BfJZhlIiyZKx10SqqwPXyFdyfIZgEooRMqjY%3D&reserved=0>?

-Jukka Rahkonen-

Lähettäjä: MapServer-users <mapserver-users-bounces at lists.osgeo.org<mailto:mapserver-users-bounces at lists.osgeo.org>> Puolesta Mallinger, Bernhard
Lähetetty: maanantai 28. marraskuuta 2022 15.35
Vastaanottaja: mapserver-users at lists.osgeo.org<mailto:mapserver-users at lists.osgeo.org>
Aihe: [MapServer-users] Distinguish between pixels outside of SCALE range and nodata pixels

Hello,
We have maps where we want the color scale go from e.g. 10 to 20, so we are using this directive:

PROCESSING "SCALE_1=10.0,20.0"
This works great by itself, however it also means that pixels with values of e.g. 5 are rendered as transparent, which is the same as the nodata pixels. So in the final image, you can't tell if data is present but the values are too low, or if there just isn't any data.
So the behaviour we would like is that values below 10 are rendered as black and values over 20 are rendered as white.
Is this somehow possible with mapscript?


We tried to have a look in the source code, and there is this line, which effectively assigns 0 to pixels below the minimum:
https://github.com/MapServer/MapServer/blob/main/mapdrawgdal.c#L1555<https://eur06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMapServer%2FMapServer%2Fblob%2Fmain%2Fmapdrawgdal.c%23L1555&data=05%7C01%7Cjukka.rahkonen%40maanmittauslaitos.fi%7C046212920572444ef6f008dad1504c07%7Cc4f8a63255804a1c92371d5a571b71fa%7C0%7C0%7C638052440048006207%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eGNr6SWL6I0yQbse%2F5SAuV7QjISOBoyi30BxYB13C9Y%3D&reserved=0>

It turns out that this small code change actually produces the desired behavior:

       fScaledValue = (float) ((pafRawData[i]-dfScaleMin)*dfScaleRatio);



       if( fScaledValue < 0.0 )

-        pabyBuffer[i] = 0;

+        if (pafRawData[i] > 0) {

+            pabyBuffer[i] = 1;

+        } else {

+            pabyBuffer[i] = 0;

+        }

(I.e. if the original value was greater than 0, then assign 1 to this pixel such that it will be black and not transparent.)

If this behavior can't yet be configured via mapscript, we could work on a pull request to implement this behavior, which would then be activated via a new configuration option.
Do you have any thoughts on this? Does this make sense to you as a feature?

Best regards,
Bernhard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20221128/955ed261/attachment-0001.htm>


More information about the MapServer-users mailing list