[Geoserver-devel] Legend grahic size policy (was [Geoserver-commits] svn - r3668 - in trunk/geoserver/src/org/vfny/geoserver/wms/responses: . helpers)

Hi dave,

I guess I don't agree in forcing the legend graphic to be exactly the size
requested by the WIDTH and HEIGHT parameters.

rationale:

1- as for the SLD 1.0 spec, page 62, WIDTH and HEIGHT are optional parameters,
and, more than that, they're _hints_. For that, I understand that the width
and height the user sent should be treated as its "preferred" dimensions, but
there is no obligation on fully respecting them, if it makes no sense.
2- I think client applications should be prepared to gracefully treat a legend
graphic larger than the size requested, like, for exaple, putting it on a
(html) table cell that expands as required bu lays out correctly on the
legend widget.
3- Generally, the width and height requested is thought for the size of a
single symbol, but most legend widgets expand vertically to adapt theirselves
to a larger graphic, instead of scaling down the graphic, since it would make
it unuseful for a large number of styling rules applied to a layer.

so, the GeoServer GetLegendGraphic operation was done to create a graphic with
the width requested by the WIDTH parameter, but to expand on height as needed
to meaningfully represent the styling rules without resulting in a illegible
image (i.e., with a lot of too small symbols in a 20x20px graphic)

further, the GetLegendGraphic operation is meant to return a representative
graphic of all the styling applied to a given layer, except if a specific
rule name is provided (through the RULE parameter), in which case the graphic
shall represent the styling of that specific rule.

what do you think?

cheers,

Gabriel.

On Monday 11 July 2005 18:12, dblasby@anonymised.com wrote:

Author: dblasby
Date: 2005-07-11 09:12:19 -0700 (Mon, 11 Jul 2005)
New Revision: 3668

Modified:
  
trunk/geoserver/src/org/vfny/geoserver/wms/responses/DefaultRasterLegendPro
ducer.java
trunk/geoserver/src/org/vfny/geoserver/wms/responses/helpers/WMSCapsTransfo
rmer.java Log:
better support for correctly sized getlegendgraphic capabilities (see
source code comments - this is a bandaid)

Modified:
trunk/geoserver/src/org/vfny/geoserver/wms/responses/DefaultRasterLegendPro
ducer.java
=================================================================== ---
trunk/geoserver/src/org/vfny/geoserver/wms/responses/DefaultRasterLegendPro
ducer.java 2005-07-11 15:54:40 UTC (rev 3667) +++
trunk/geoserver/src/org/vfny/geoserver/wms/responses/DefaultRasterLegendPro
ducer.java 2005-07-11 16:12:19 UTC (rev 3668) @@ -7,6 +7,7 @@
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
@@ -215,10 +216,34 @@
             legendsStack.add(image);
         }

- this.legendGraphic = mergeLegends(legendsStack);
+ this.legendGraphic =
scaleImage(mergeLegends(legendsStack),request); }

     /**
+ * Scales the image so that its the size specified in the request.
+ * @hack -- there should be a much better way to do this. See
handleLegendURL() in WMSCapsTransformer. + * @param image
+ * @return
+ */
+ private BufferedImage scaleImage(BufferedImage
image,GetLegendGraphicRequest request) + {
+ final int w = request.getWidth();
+ final int h = request.getHeight();
+
+ BufferedImage scaledImage = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics =
scaledImage.createGraphics();
+ graphics.setColor(BG_COLOR);
+ graphics.fillRect(0, 0, w, h);
+
+ AffineTransform xform = new AffineTransform();
+ xform.setToScale( ((double)w)/image.getWidth(),
((double)h)/image.getHeight() ); +
+ graphics.drawImage(image,xform,null );
+
+ return scaledImage;
+ }
+
+ /**
      * Recieves a list of <code>BufferedImages</code> and produces a new
one * which holds all the images in <code>imageStack</code> one above the
* other.

Modified:
trunk/geoserver/src/org/vfny/geoserver/wms/responses/helpers/WMSCapsTransfo
rmer.java
=================================================================== ---
trunk/geoserver/src/org/vfny/geoserver/wms/responses/helpers/WMSCapsTransfo
rmer.java 2005-07-11 15:54:40 UTC (rev 3667) +++
trunk/geoserver/src/org/vfny/geoserver/wms/responses/helpers/WMSCapsTransfo
rmer.java 2005-07-11 16:12:19 UTC (rev 3668) @@ -609,6 +609,17 @@
                 AttributesImpl attrs = new AttributesImpl();
                 attrs.addAttribute("", "width", "width", "",
                    
String.valueOf(GetLegendGraphicRequest.DEFAULT_WIDTH)); +
+ //DJB: problem here is that we do not know the size of the
legend apriori - we need + // to make one and find its
height. Not the best way, but it would work quite well. +
// This was advertising a 20*20 icon, but actually producing ones of a
different size. + // An alternative is to just scale the
resulting icon to what the server requested, but this isnt +
// the nicest thing since warped images dont look nice. The client
should do the warping. +
+ //however, to actually estimate the size is a bit
difficult. I'm going to do the scaling + //so it obeys the
what the request says. For people with a problem with that should consider
+ //changing the default size here so that the request is
for the correct size. +
                 attrs.addAttribute("", "height", "height", "",
                    
String.valueOf(GetLegendGraphicRequest.DEFAULT_HEIGHT));

-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar
happening July 14 at 8am PDT/11am EDT. We invite you to explore the latest
in dual core and dual graphics technology at this free one hour event
hosted by HP, AMD, and NVIDIA. To register visit
http://www.hp.com/go/dualwebinar
_______________________________________________
Geoserver-commits mailing list
Geoserver-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-commits

--
Gabriel Roldán <groldan@anonymised.com>
Axios Engineering <http://www.axios.es>
CR/Basurtu-Kastrexana 70, Mod. 14
48002 - Bilbao, Spain
te. (+34) 94 441 63 84
fax (+34) 94 441 64 90

Gabriel Roldán wrote:

Hi dave,

I guess I don't agree in forcing the legend graphic to be exactly the size requested by the WIDTH and HEIGHT parameters.

Eek!

1- as for the SLD 1.0 spec, page 62, WIDTH and HEIGHT are optional parameters, and, more than that, they're _hints_. For that, I understand that the width and height the user sent should be treated as its "preferred" dimensions, but there is no obligation on fully respecting them, if it makes no sense.

My understanding was that they were required?

2- I think client applications should be prepared to gracefully treat a legend graphic larger than the size requested, like, for exaple, putting it on a (html) table cell that expands as required bu lays out correctly on the legend widget.

If I make a request for a certainty size, I expect that size.

3- Generally, the width and height requested is thought for the size of a single symbol

And that is what I am asking for a single symbol.

further, the GetLegendGraphic operation is meant to return a representative graphic of all the styling applied to a given layer, except if a specific rule name is provided (through the RULE parameter), in which case the graphic shall represent the styling of that specific rule.

This does not make a lot of sense to me, I will go read the specs.

what do you think?

I think that is terrible - I only have 16x16 pixels to give you :frowning:

Jody

On Monday 11 July 2005 21:59, Jody Garnett wrote:

Gabriel Roldán wrote:
>Hi dave,
>
>I guess I don't agree in forcing the legend graphic to be exactly the size
>requested by the WIDTH and HEIGHT parameters.

Eek!

>1- as for the SLD 1.0 spec, page 62, WIDTH and HEIGHT are optional
> parameters, and, more than that, they're _hints_. For that, I understand
> that the width and height the user sent should be treated as its
> "preferred" dimensions, but there is no obligation on fully respecting
> them, if it makes no sense.

My understanding was that they were required?

Jody, my confussion was that I thought david was talking about the
GetLegendGraphic operation itself, not the default legend graphic advertised
on the capabilities.
The last one says the size of the graphic, and as dave noted, it is required
and the logic tells that the image you get when issuing that request is of
the stated dimensions.
By the other side, WIDTH and HEIGHT parameters of GetLegendGraphic are
optional, and are just _hints_, meaning that the actual size could be
different from the passed through parameters.

>2- I think client applications should be prepared to gracefully treat a
> legend graphic larger than the size requested, like, for exaple, putting
> it on a (html) table cell that expands as required bu lays out correctly
> on the legend widget.

If I make a request for a certainty size, I expect that size.

the reason for width and height to be hints is that you could get a lot of
rules for a given layer at a given scale. What the spec requires, is that the
returned graphic were representative enough of the styling used on the layer,
and puting 10 different symbols on a 16x16 graphic looks less representative
than putting a stack of 10 symbols, each one of 16x16 pixels.

>3- Generally, the width and height requested is thought for the size of a
>single symbol

And that is what I am asking for a single symbol.

you're asking for a single symbol if you're issuing a GetLegendGraphic
operation for each RULE of your layer. to do that, you have to figure out
what rules apply to your current map scale and make a request for each one.
The other (more widely used) approach is to send just one request for the
whole layer, and let the server build a "representative" graphic of all the
rules that apply.

cheers,

Gabriel

>further, the GetLegendGraphic operation is meant to return a
> representative graphic of all the styling applied to a given layer,
> except if a specific rule name is provided (through the RULE parameter),
> in which case the graphic shall represent the styling of that specific
> rule.

This does not make a lot of sense to me, I will go read the specs.

>what do you think?

I think that is terrible - I only have 16x16 pixels to give you :frowning:

Jody

-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar
happening July 14 at 8am PDT/11am EDT. We invite you to explore the latest
in dual core and dual graphics technology at this free one hour event
hosted by HP, AMD, and NVIDIA. To register visit
http://www.hp.com/go/dualwebinar
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

--
Gabriel Roldán <groldan@anonymised.com>
Axios Engineering <http://www.axios.es>
CR/Basurtu-Kastrexana 70, Mod. 14
48002 - Bilbao, Spain
te. (+34) 94 441 63 84
fax (+34) 94 441 64 90

Gabriel Roldán wrote:

Jody, my confussion was that I thought david was talking about the GetLegendGraphic operation itself, not the default legend graphic advertised on the capabilities.

Okay.

And that is what I am asking for a single symbol.
   

you're asking for a single symbol if you're issuing a GetLegendGraphic operation for each RULE of your layer.

I don't think you can do that? The symbol represents the entire layer. Remember that the SLD (and thus the rules) are a black box known only to geoserver at this time.

The other (more widely used) approach is to send just one request for the whole layer, and let the server build a "representative" graphic of all the rules that apply.

We are going around in circles on this one Gabriel, lets get out the specs as that is what they are for. I just tried looking through 1.3.0 (but it was not very helpful).

It sounds to me like we both have different applications in mind, an each idea makes perfect sense on its own. I am sure we are both right, the question is what the spec says.

Jody

On Monday 11 July 2005 22:44, Jody Garnett wrote:

Gabriel Roldán wrote:
>Jody, my confussion was that I thought david was talking about the
>GetLegendGraphic operation itself, not the default legend graphic
> advertised on the capabilities.

Okay.

>>And that is what I am asking for a single symbol.
>
>you're asking for a single symbol if you're issuing a GetLegendGraphic
>operation for each RULE of your layer.

I don't think you can do that? The symbol represents the entire layer.
Remember that the SLD (and thus the rules) are a black box known only to
geoserver at this time.

>The other (more widely used) approach is to send just one request for the
>whole layer, and let the server build a "representative" graphic of all
> the rules that apply.

We are going around in circles on this one Gabriel, lets get out the
specs as that is what they are for. I just tried looking through 1.3.0
(but it was not very helpful).

I don't think we're going around in circles. You can do a GetLegendGraphics
request for a single rule.
The spec says (SLD 1.0, page 62),

"RULE. Optional. Rule of style to produce legend graphic for, if applicable.
In the case that a style has multiple rules but no specific rule is selected,
then the map server is obligated to produce a graphic that is representative
of all of the rules of the style."

Also I don't have any specific application in mind, Jody. I was all about
discussing adherence to the spec from my side.

Gabriel

It sounds to me like we both have different applications in mind, an
each idea makes perfect sense on its own. I am sure we are both right,
the question is what the spec says.

Jody

--
Gabriel Roldán <groldan@anonymised.com>
Axios Engineering <http://www.axios.es>
CR/Basurtu-Kastrexana 70, Mod. 14
48002 - Bilbao, Spain
te. (+34) 94 441 63 84
fax (+34) 94 441 64 90

I don't think you can do that? The symbol represents the entire layer.
Remember that the SLD (and thus the rules) are a black box known only to
geoserver at this time.

ah, I think "at this time" you mean when getting the legend graphic url stated
in the capabilities? that's right. It is clear at this time the returned
image MUST be of the size stated on the capabilities. That was a geosever
error.
By the other hand, you do can issue rule specific requests, as the spec says,
and geoserver supports it.
It could make more sense to a high tech client like udig, and could be pretty
difficult for a html based one. So you have the flexibility to treat them as
a black box (an get what the server wants to return in order to provide a
"representative" graphic of all the rules that apply), or take the control
and get a graphic for each rule.

cheers,

Gabriel.

Hi Gabriel:

We are going around in circles on this one Gabriel, lets get out the
specs as that is what they are for. I just tried looking through 1.3.0
(but it was not very helpful).
   

I don't think we're going around in circles. You can do a GetLegendGraphics request for a single rule.

You are correct - it was me going around in circles.
Problem is I want a graphic for my layer - and the spec clearly says that this is a legend graphic (not a layer graphic).
Thanks for find the spec, I was looking in the WMS specs.

The spec says (SLD 1.0, page 62),

"RULE. Optional. Rule of style to produce legend graphic for, if applicable. In the case that a style has multiple rules but no specific rule is selected, then the map server is obligated to produce a graphic that is representative of all of the rules of the style."

Also I don't have any specific application in mind, Jody. I was all about discussing adherence to the spec from my side.

I think the best compromise I can do is request the size I want (16x16) and figure out a way to smoothly handle a different size. I am going to try and take just the first 16x16 (in case the answer was 16x32 or something).

Cheers,
Jody