Reading-eScience-Centre / edal-java

Environmental Data Abstraction Layer libraries
Other
39 stars 30 forks source link

Round off on label on using SLD for GetLegendGraphic request on ncwms2 #128

Open suman111sanjel opened 4 years ago

suman111sanjel commented 4 years ago

Hi,

I am fetching GetLegendGraphic on thredds Data server 5 which uses ncWMS2. The problem is while fetching legend it round off 2.5 to 3.0 or so on on Legend i don't want to round off on legend. rain

I want to label 1.0, 1.5, 2.0, 2.5, 3.0, 3.5 and so on link:http://110.34.30.197:8080/thredds/wms/saldasforecast/monthly_std_ens3.ncml?REQUEST=GetLegendGraphic&SLD_BODY=%3C?xml%20version=%221.0%22%20encoding=%22ISO-8859-1%22?%3E%3CStyledLayerDescriptor%20version=%221.1.0%22%20xsi:schemaLocation=%22http://www.opengis.net/sldStyledLayerDescriptor.xsd%22%20xmlns=%22http://www.opengis.net/sld%22%20xmlns:ogc=%22http://www.opengis.net/ogc%22%20xmlns:se=%22http://www.opengis.net/se%22%20xmlns:xlink=%22http://www.w3.org/1999/xlink%22%20xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22%3E%3CNamedLayer%3E%3Cse:Name%3ERainf_f_tavg%3C/se:Name%3E%3CUserStyle%3E%3Cse:Name%3EThesholded%20colour%20scheme%3C/se:Name%3E%3Cse:CoverageStyle%3E%3Cse:Rule%3E%3Cse:RasterSymbolizer%3E%3Cse:Opacity%3E1.0%3C/se:Opacity%3E%3Cse:ColorMap%3E%3Cse:Categorize%20fallbackValue=%22%2300000000%22%3E%3Cse:LookupValue%3ERasterdata%3C/se:LookupValue%3E%3Cse:Value%3E%2300000000%3C/se:Value%3E%3Cse:Threshold%3E-2.5%3C/se:Threshold%3E%3Cse:Value%3E%23C2523C%3C/se:Value%3E%3Cse:Threshold%3E-2%3C/se:Threshold%3E%3Cse:Value%3E%23FFAA01%3C/se:Value%3E%3Cse:Threshold%3E-1.5%3C/se:Threshold%3E%3Cse:Value%3E%23FFD380%3C/se:Value%3E%3Cse:Threshold%3E-1%3C/se:Threshold%3E%3Cse:Value%3E%23FEFF73%3C/se:Value%3E%3Cse:Threshold%3E-0.5%3C/se:Threshold%3E%3Cse:Value%3E%23E1E1E1%3C/se:Value%3E%3Cse:Threshold%3E0%3C/se:Threshold%3E%3Cse:Value%3E%23E1E1E1%3C/se:Value%3E%3Cse:Threshold%3E0.5%3C/se:Threshold%3E%3Cse:Value%3E%23E9FFBE%3C/se:Value%3E%3Cse:Threshold%3E1%3C/se:Threshold%3E%3Cse:Value%3E%237BED01%3C/se:Value%3E%3Cse:Threshold%3E1.5%3C/se:Threshold%3E%3Cse:Value%3E%2321DD00%3C/se:Value%3E%3Cse:Threshold%3E2%3C/se:Threshold%3E%3Cse:Value%3E%230ACC2E%3C/se:Value%3E%3Cse:Threshold%3E2.5%3C/se:Threshold%3E%3Cse:Value%3E%2317B568%3C/se:Value%3E%3Cse:Threshold%3E3%3C/se:Threshold%3E%3Cse:Value%3E%231E9B89%3C/se:Value%3E%3Cse:Threshold%3E3.5%3C/se:Threshold%3E%3Cse:Value%3E%231A828F%3C/se:Value%3E%3Cse:Threshold%3E4%3C/se:Threshold%3E%3Cse:Value%3E%23135784%3C/se:Value%3E%3Cse:Threshold%3E4.5%3C/se:Threshold%3E%3Cse:Value%3E%2300000000%3C/se:Value%3E%3C/se:Categorize%3E%3C/se:ColorMap%3E%3C/se:RasterSymbolizer%3E%3C/se:Rule%3E%3C/se:CoverageStyle%3E%3C/UserStyle%3E%3C/NamedLayer%3E%3C/StyledLayerDescriptor%3E&VERTICAL=false

Please Help me with this problem

Thank You Suman Sanjel

guygriffiths commented 4 years ago

Thanks for reporting this, it is a bug, I've just fixed it in https://github.com/Reading-eScience-Centre/edal-java/commit/c5dbe5cf4d1cc2af0fb0d2e5133dc9da20fffe7e

ghansham commented 3 years ago

The above fix does not work in following case:

Assuming a range of 477 to 945. The values for labels get calculated as 477, 594, 711, 828, 945. sigfigs value gets calculated as 1. which rounds off 477 to 480 and 945 to 950.

https://github.com/Reading-eScience-Centre/edal-java/blob/1eb2a9231ff0bff342b20e9f8da15969a9204f5e/graphics/src/main/java/uk/ac/rdg/resc/edal/graphics/style/MapImage.java#L466

Can something be done to calculate it correctly?

guygriffiths commented 3 years ago

If that's not accurate enough (and given a range of 500, a precision of 5 should be within the width of the label), you can add the colorBarOnly=true argument and create a legend client-side.

ghansham commented 3 years ago

Thanks.