[mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]
Tellez-Arenas Agnes
a.tellez-arenas at brgm.fr
Thu Jan 4 07:08:41 PST 2018
Thanks a lot for this answer, I will certainly find a solution with your suggestions, will probably try both!
Thanks
Agnès
De : Rahkonen Jukka (MML) [mailto:jukka.rahkonen at maanmittauslaitos.fi]
Envoyé : jeudi 4 janvier 2018 16:04
À : Tellez-Arenas Agnes <a.tellez-arenas at brgm.fr>; mapserver-users at lists.osgeo.org
Objet : Re: [mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]
Hi,
You have an interesting theoretical challenge but I would still make it in another way. First, it would be easier to use single band 16-bit png instead of 3-band 8-bit png. And second, compressed tiff is not much bigger than png. Use the deflate method which is the same method that png is using. For DEMs I would recommend to use the option "predictor=2".
Here are numbers from a quick test with 16-bit DEM file.
gdal_translate -of GTiff -co compress=deflate -co tiled=yes -co predictor=2 dem.png dem.tif
png: 1326381 bytes
tiff: 1394597 bytes
Tiled tiff with overviews added with the gdaladdo utility is also much better (=faster) format for MapServer that png files. Overviews add 25% to the file size but it is worth it.
-Jukka Rahkonen-
Lähettäjä: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] Puolesta Tellez-Arenas Agnes
Lähetetty: 4. tammikuuta 2018 16:40
Vastaanottaja: mapserver-users at lists.osgeo.org<mailto:mapserver-users at lists.osgeo.org>
Aihe: [mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]
Dear all,
I am trying to classify a PNG (could be a tiff) which has the 3 bands (red, green, blue), each from 0..255.
I need to classify (not just display it as it is), because I have used those 3 bands to "code" elevation values (it's a hightmap).
I am using a PNG to encode the elevation value on those r,g,b bands, rather than one tiff containing directly the elevation on the pixel, because the size of the PNG is smaller than tiff (and I need to store a big amount of images...).
The formula to "encode" the elevation is
#min=-50, max=1000 ((r * 256 + g + b / 256) * (Zmax-Zmin)/(65536)) + Zmin*
Which I translated as
CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) * (Zmax-Zmin)/(65536)) + Zmin*
EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)
STYLE
COLOR 100 195 215
OPACITY 35
END
END
But, [red]=[green]=[blue]= the value of the first band (red). Always.
In documentation I can see (http://mapserver.org/mapfile/expressions.html<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmapserver.org%2Fmapfile%2Fexpressions.html&data=02%7C01%7Ca.tellez-arenas%40brgm.fr%7Cd44488cb76de42e2c77a08d553846093%7C9610f79254fa49639560a8a822cba6d7%7C1%7C1%7C636506750414087452&sdata=vQyRCrvD0Knl09qLiDTJbNIpTKqeSTyZ0MAlHfF9niI%3D&reserved=0>)
For Raster Data<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmapserver.org%2Finput%2Fraster.html%23raster&data=02%7C01%7Ca.tellez-arenas%40brgm.fr%7Cd44488cb76de42e2c77a08d553846093%7C9610f79254fa49639560a8a822cba6d7%7C1%7C1%7C636506750414087452&sdata=nWPZLmGiKEscjltDru4i%2FhhlurcNeHBqEjurB7fQPJ0%3D&reserved=0> layers special attributes have been defined that can be used for classification, for example:
* [PIXEL] ... will become the pixel value as number
* [RED], [GREEN], [BLUE] ... will become the color value for the red, green and blue component in the pixel value, respectively.
And (http://mapserver.org/el/input/raster.html<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmapserver.org%2Fel%2Finput%2Fraster.html&data=02%7C01%7Ca.tellez-arenas%40brgm.fr%7Cd44488cb76de42e2c77a08d553846093%7C9610f79254fa49639560a8a822cba6d7%7C1%7C1%7C636506750414087452&sdata=5%2F7eafCSMwO0COs7gS2YoWb8O4CHtJP5Bi1bXRDdVsg%3D&reserved=0>)
There is no need to specify a CLASSITEM. The raw pixel value itself ("[pixel]") and, for paletted images, the red, green and blue color associated with that pixel value ("[red]", "[green]" and "[blue]") are available for use in classifications.
Hope someone can help me on that!
Thanks!
Here is my MapFile.
MAP
NAME "test"
STATUS OFF
SIZE 256 256
MAXSIZE 4096
RESOLUTION 96
EXTENT 253999.500 6884000.500 254999.500 6885000.500
UNITS DD
IMAGETYPE png
IMAGECOLOR 255 255 255
PROJECTION
"init=epsg:2154"
END
WEB
TEMPLATE "../etc/html_template/getcapabilities_wms_130.html"
METADATA
(...)
END
END
LAYER
NAME "test"
TYPE RASTER
DATA "/mnt/nemesis_resultats/flood/v3/v4_1m/RGEALTI_FXX_0224_6753_MNT_LAMB93_IGN69_png.png"
#PROCESSING "BANDS=1,2,3" #this line crashes with a "drawGDAL(): Unable to access file. Attempt to classify 24bit image, this is unsupported."
STATUS ON
PROJECTION
"init=epsg:2154"
END
METADATA
(...)
END
CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) * (Zmax-Zmin)/(65536)) + Zmin*
EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)
STYLE
COLOR 100 195 215
OPACITY 35
END
END
END #LAYER
END
# End of MapFile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20180104/a3088351/attachment.htm>
More information about the MapServer-users
mailing list