[Geoserver-users] How to create weighted heatmap with Geoserver, WMS, and SLD

Hi

I am trying to figure out how to create weighted heat maps by performing a vector to raster transformation on my data via the SLD gs:Heatmap function (http://docs.geoserver.org/stable/en/user/styling/sld-extensions/rendering-transform.html).

So far I have successfully created weighted heat maps using Geoserver, WMS, and SLD, but the generated heat maps are not exactly as I would like them because the data in the underlying transformed raster seems to always get scaled to values between 0 and 1 before the ColorMap is applied.

I very much want to create images that look like a heat map, but I do not always want my data to scale between 0 and 1. For instance, say my weighted attribute has a theoretical maximum of 100, but the attribute values never exceed 50 (for a certain data set). In this hypothetical case, I would want the data to get scaled to between 0 and 0.5 - because I wouldn’t want the colors from the ColorMap that represent a value near 1 to be displayed.

So far, it seems like no matter what I try the data always dynamically gets scaled to be between 0 and 1 - meaning that I always get the colors at the top end of the ColorMap even if this is not what I want. I should note that I have looked at the Barnes Surface transformation, and I am pretty convinced that I cannot achieve the same heat map look and feel using that transformation.

My questions are:

  1. in the SLD is there a way to set a theoretical range of values for the weighted attribute so that the underlying data gets scaled based upon that range?

  2. if there is not a way to scale the data appropriately in the SLD, is there another approach or another transformation I could use that would generate an image that looks like the heat map images?

  3. if I have to code up a solution in Java, what GeoTools classes should I use? Pointing me to some help documentation with examples would be great. I have seen some people suggest using VectorToRasterProcess.java, but I don’t know if that is a good approach.

Thanks in advance,

B

I am using the weightAttr parameter in my SLD, and that seems to work; however, the generated heat maps seem to always scale the underlying weighted data to values between 0 and 1.

I want to generate heat maps using Geoserver, WMS and SLD. I have been able to successfully generate heat maps this way, but the generated heat maps are not quite what I want them to be.

I want my heat maps to be weighted by an attribute

My questions are:

  • is there a way I can get the ColorMap to not
  • if I cannot do what I want using Geoserver, does anyone have a suggestion for what GeoTools methods to use to create heat maps?

Barnes Surface

weightAttr

I never found out how to do exactly what I wanted, but I wanted to share with others what I did.

I opted to create a choropleth map instead of a heat map (http://en.wikipedia.org/wiki/Choropleth_map). Using a choropleth map gave me more control over the color transitions and also more accurately reflected the underlying data. By using this approach, my data did not get automatically scaled to be between 0 and 1.

Below you will see an example URL that uses SLD variable substitution for two variables (attribute, scale). Also, below, you will see my SLD file that conditionally applies choropleth maps based upon attribute names and only applies the choropleth coloring scheme if the attributes are not null (using the isNull function). Ultimately, my approach was to programmatically build up the URL so that I could create many different choropleth images using different attributes and scale factors. You’ll also notice that I found that the resulting images looked the best if I simultaneously applied the choropleth colors to both the fill and stroke parameters. I should note that I used GeoServer 2.3.5. I should also note that although my example does not use negative values, negative values are supported by this methodology.

Example WMS URL:

IPAddress/geoserver/NameOfWorkspace/wms?service=WMS&version=1.1.0&request=GetMap&layers=NameOfLayer&styles=NameOfStyle&env=attribute:NameOfAttribute;scale:2.1&bbox=-101.0,44.0,-100.0,45.0&width=1000&height=750&srs=EPSG:4326&format=application/openlayers

SLD:

<?xml version="1.0" encoding="ISO-8859-1"?>



Example Name for NamedLayer

Example Title ExampleNameForRule1 attribute ExampleAttribute ExampleAttribute false attribute ExampleAttribute false 1000000 attribute ExampleAttribute scale 1

ogc:Literal0</ogc:Literal>
ogc:Literal#59E954</ogc:Literal>

ogc:Literal9.9999</ogc:Literal>
ogc:Literal#054205</ogc:Literal>

ogc:Literal10</ogc:Literal>
ogc:Literal#EFD504</ogc:Literal>

ogc:Literal50</ogc:Literal>
ogc:Literal#EFA300</ogc:Literal>

ogc:Literal100</ogc:Literal>
ogc:Literal#FC5D0B</ogc:Literal>

ogc:Literal500</ogc:Literal>
ogc:Literal#EC0000</ogc:Literal>

ogc:Literal1000</ogc:Literal>
ogc:Literal#B40001</ogc:Literal>

ogc:Literal5000</ogc:Literal>
ogc:Literal#500202</ogc:Literal>

ogc:Literalcolor</ogc:Literal>
</ogc:Function>


<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal0</ogc:Literal>

ogc:Literal0.01</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>




<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal#59E954</ogc:Literal>

ogc:Literal9.9999</ogc:Literal>
ogc:Literal#054205</ogc:Literal>

ogc:Literal10</ogc:Literal>
ogc:Literal#EFD504</ogc:Literal>

ogc:Literal50</ogc:Literal>
ogc:Literal#EFA300</ogc:Literal>

ogc:Literal100</ogc:Literal>
ogc:Literal#FC5D0B</ogc:Literal>

ogc:Literal500</ogc:Literal>
ogc:Literal#EC0000</ogc:Literal>

ogc:Literal1000</ogc:Literal>
ogc:Literal#B40001</ogc:Literal>

ogc:Literal5000</ogc:Literal>
ogc:Literal#500202</ogc:Literal>

ogc:Literalcolor</ogc:Literal>
</ogc:Function>

0
round

<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal0</ogc:Literal>

ogc:Literal0.01</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>



ExampleNameForRule2 attribute ExampleAttribute ExampleAttribute true attribute ExampleAttribute false 1000000 attribute ExampleAttribute scale 1

ogc:Literal0</ogc:Literal>
ogc:Literal#03FFFF</ogc:Literal>

ogc:Literal10</ogc:Literal>
ogc:Literal#029EF0</ogc:Literal>

ogc:Literal100</ogc:Literal>
ogc:Literal#0148DE</ogc:Literal>

ogc:Literal1000</ogc:Literal>
ogc:Literal#0009BF</ogc:Literal>

ogc:Literalcolor</ogc:Literal>
</ogc:Function>


<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal0</ogc:Literal>

ogc:Literal0.01</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>




<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal#03FFFF</ogc:Literal>

ogc:Literal10</ogc:Literal>
ogc:Literal#029EF0</ogc:Literal>

ogc:Literal100</ogc:Literal>
ogc:Literal#0148DE</ogc:Literal>

ogc:Literal1000</ogc:Literal>
ogc:Literal#0009BF</ogc:Literal>

ogc:Literalcolor</ogc:Literal>
</ogc:Function>

0
round

<ogc:Function name=“Interpolate”>

ogc:Mul
<ogc:Function name=“property”>
<ogc:Function name=“env”>
ogc:Literalattribute</ogc:Literal>
ogc:LiteralExampleAttribute</ogc:Literal>
</ogc:Function>
</ogc:Function>
<ogc:Function name=“env”>
ogc:Literalscale</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>
</ogc:Mul>

ogc:Literal0</ogc:Literal>
ogc:Literal0</ogc:Literal>

ogc:Literal0.01</ogc:Literal>
ogc:Literal1</ogc:Literal>
</ogc:Function>







···

On Wed, Mar 12, 2014 at 10:58 AM, B L <lalonde.14@anonymised.com> wrote:

Hi

I am trying to figure out how to create weighted heat maps by performing a vector to raster transformation on my data via the SLD gs:Heatmap function (http://docs.geoserver.org/stable/en/user/styling/sld-extensions/rendering-transform.html).

So far I have successfully created weighted heat maps using Geoserver, WMS, and SLD, but the generated heat maps are not exactly as I would like them because the data in the underlying transformed raster seems to always get scaled to values between 0 and 1 before the ColorMap is applied.

I very much want to create images that look like a heat map, but I do not always want my data to scale between 0 and 1. For instance, say my weighted attribute has a theoretical maximum of 100, but the attribute values never exceed 50 (for a certain data set). In this hypothetical case, I would want the data to get scaled to between 0 and 0.5 - because I wouldn’t want the colors from the ColorMap that represent a value near 1 to be displayed.

So far, it seems like no matter what I try the data always dynamically gets scaled to be between 0 and 1 - meaning that I always get the colors at the top end of the ColorMap even if this is not what I want. I should note that I have looked at the Barnes Surface transformation, and I am pretty convinced that I cannot achieve the same heat map look and feel using that transformation.

My questions are:

  1. in the SLD is there a way to set a theoretical range of values for the weighted attribute so that the underlying data gets scaled based upon that range?

  2. if there is not a way to scale the data appropriately in the SLD, is there another approach or another transformation I could use that would generate an image that looks like the heat map images?

  3. if I have to code up a solution in Java, what GeoTools classes should I use? Pointing me to some help documentation with examples would be great. I have seen some people suggest using VectorToRasterProcess.java, but I don’t know if that is a good approach.

Thanks in advance,

B

I am using the weightAttr parameter in my SLD, and that seems to work; however, the generated heat maps seem to always scale the underlying weighted data to values between 0 and 1.

I want to generate heat maps using Geoserver, WMS and SLD. I have been able to successfully generate heat maps this way, but the generated heat maps are not quite what I want them to be.

I want my heat maps to be weighted by an attribute

My questions are:

  • is there a way I can get the ColorMap to not
  • if I cannot do what I want using Geoserver, does anyone have a suggestion for what GeoTools methods to use to create heat maps?

Barnes Surface

weightAttr