Skip to content

Commit

Permalink
Shadeinterval with fixed value now also works with point data
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenplieger committed Jul 10, 2023
1 parent d3d69ec commit f0f3e83
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
25 changes: 20 additions & 5 deletions adagucserverEC/CImgRenderers/CImgRenderPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void CImgRenderPoints::renderSinglePoints(CImageWarper *, CDataSource *dataSourc
if (!useDrawPointTextColor) {
if (dataObjectIndex == 0) { // Only calculate color for 1st dataObject, rest gets defaultColor
if ((dataSource->getStyle() != NULL) && (dataSource->getStyle()->shadeIntervals != NULL) && (dataSource->getStyle()->shadeIntervals->size() > 0)) {
drawPointTextColor = getPixelColorForValue(dataSource, v);
drawPointTextColor = getPixelColorForValue(dataSource, drawImage, v);
} else {
int pointColorIndex = getPixelIndexForValue(dataSource, v); // Use value of dataObject[0] for colour
drawPointTextColor = drawImage->getColorForIndex(pointColorIndex);
Expand All @@ -340,7 +340,7 @@ void CImgRenderPoints::renderSinglePoints(CImageWarper *, CDataSource *dataSourc
} else { // Text and disc
if (!useDrawPointFillColor) { //(dataSource->getNumDataObjects()==1) {
if ((dataSource->getStyle() != NULL) && (dataSource->getStyle()->shadeIntervals != NULL) && (dataSource->getStyle()->shadeIntervals->size() > 0)) {
drawPointFillColor = getPixelColorForValue(dataSource, v);
drawPointFillColor = getPixelColorForValue(dataSource, drawImage, v);
} else {
int pointColorIndex = getPixelIndexForValue(dataSource, v); // Use value of dataObject[0] for colour
drawPointFillColor = drawImage->getColorForIndex(pointColorIndex);
Expand Down Expand Up @@ -414,7 +414,7 @@ void CImgRenderPoints::renderSinglePoints(CImageWarper *, CDataSource *dataSourc

if (!useDrawPointTextColor) {
if ((dataSource->getStyle() != NULL) && (dataSource->getStyle()->shadeIntervals != NULL)) {
drawPointTextColor = getPixelColorForValue(dataSource, v);
drawPointTextColor = getPixelColorForValue(dataSource, drawImage, v);
} else {
int pointColorIndex = getPixelIndexForValue(dataSource, v); // Use value of dataObject[0] for colour
drawPointTextColor = drawImage->getColorForIndex(pointColorIndex);
Expand All @@ -430,7 +430,7 @@ void CImgRenderPoints::renderSinglePoints(CImageWarper *, CDataSource *dataSourc
}
if (!useDrawPointFillColor) { //(dataSource->getNumDataObjects()==1) {
if ((dataSource->getStyle() != NULL) && (dataSource->getStyle()->shadeIntervals != NULL)) {
CColor col = getPixelColorForValue(dataSource, v);
CColor col = getPixelColorForValue(dataSource, drawImage, v);
drawImage->setTextDisc(x, y, drawPointDiscRadius, t.c_str(), drawPointFontFile, drawPointFontSize, drawPointTextColor, col, drawPointLineColor);
} else {
int pointColorIndex = getPixelIndexForValue(dataSource, v); // Use value of dataObject[0] for colour
Expand Down Expand Up @@ -860,7 +860,7 @@ int CImgRenderPoints::getPixelIndexForValue(CDataSource *dataSource, float val)
return 0;
}

CColor CImgRenderPoints::getPixelColorForValue(CDataSource *dataSource, float val) {
CColor CImgRenderPoints::getPixelColorForValue(CDataSource *dataSource, CDrawImage *drawImage, float val) {
bool isNodata = false;

CColor color;
Expand All @@ -870,6 +870,21 @@ CColor CImgRenderPoints::getPixelColorForValue(CDataSource *dataSource, float va
}
if (!isNodata) {
CStyleConfiguration *styleConfiguration = dataSource->getStyle();
// Based on ShadeInterval configuration with value setting:
// Find the colour matching the given legend, rounded down to the shadeinterval value.
if (styleConfiguration->shadeIntervals->size() == 1) {
CServerConfig::XMLE_ShadeInterval *shadeInterval = ((*styleConfiguration->shadeIntervals)[0]);
if (!shadeInterval->value.empty()) {
double interval = shadeInterval->value.toDouble();
double discreteValue = floor(val / interval) * interval;
int pointColorIndex = getPixelIndexForValue(dataSource, discreteValue);
CColor drawPointFillColor = drawImage->getColorForIndex(pointColorIndex);
return drawPointFillColor;
}
}

// Based on ShadeInterval configuration with min and max attributes:
// determine between which min and max the value falls, and return the color.
for (size_t j = 0; j < styleConfiguration->shadeIntervals->size(); j++) {
CServerConfig::XMLE_ShadeInterval *shadeInterval = ((*styleConfiguration->shadeIntervals)[j]);
if (shadeInterval->attr.min.empty() == false && shadeInterval->attr.max.empty() == false) {
Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/CImgRenderers/CImgRenderPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ class CImgRenderPoints : public CImageWarperRenderInterface {
void render(CImageWarper *, CDataSource *, CDrawImage *);
int set(const char *);
int getPixelIndexForValue(CDataSource *dataSource, float val);
CColor getPixelColorForValue(CDataSource *dataSource, float val);
CColor getPixelColorForValue(CDataSource *dataSource, CDrawImage *drawImage, float val);
};
#endif
43 changes: 43 additions & 0 deletions doc/configuration/ShadeInterval.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,46 @@ Back to [Configuration](./Configuration.md)
<ShadeInterval min="0.50" max="0.75" label="0.50-0.75" fillcolor="\#8080FF"/>
<ShadeInterval min="0.75" max="1.00" label="0.75-1.00" fillcolor="\#4C4CFF"/>
```

## Pick colors from legend by using equal intervals


The following configuration can be used to make a shadeinterval between the specified min and max using the stepsize specified in `<ShadeInterval>`.

In the example below that means (1500-500) / 50 = 20 classes. The colours will be taken from the legend.


```xml
<Legend name="Pr_wn" type="colorRange">
<palette index="0" color="#932226"/>
<palette index="15" color="#944C26"/>
<palette index="30" color="#C39301"/>
<palette index="45" color="#ECDA1E"/>
<palette index="60" color="#89B03B"/>
<palette index="75" color="#279942"/>
<palette index="90" color="#016F52"/>
<palette index="105" color="#009E9D"/>
<palette index="120" color="#00A5DB"/>
<palette index="135" color="#00549D"/>
<palette index="150" color="#122371"/>
<palette index="165" color="#324776"/>
<palette index="180" color="#765081"/>
<palette index="195" color="#B24E8A"/>
<palette index="210" color="#CB83A8"/>
<palette index="225" color="#EEB8C5"/>
<palette index="240" color="#EEB8C5"/>
</Legend>
<Style name="KNMI23_PRSUM_YEAR">
<Legend fixedclasses="true">Pr_wn</Legend>
<ShadeInterval>50</ShadeInterval>
<RenderMethod>shaded,point</RenderMethod>
<Min>500</Min>
<Max>1500</Max>
</Style>

```
See example with a point and a grid dataset:

![](ShadeInterval_with_intervalvalue.png)


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0f3e83

Please sign in to comment.