Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windspeed barbs now display text in kts next to the barb #410

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ USER root
LABEL maintainer="[email protected]"

# Version should be same as in Definitions.h
LABEL version="2.28.0"
LABEL version="2.28.1"

# Try to update image packages
RUN apt-get -q -y update \
Expand Down
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
**Version 2.28.1 2024-10-11**
- Windbarbs on modelfields can now display the windspeed in kts as text when rendertextforvectors in RenderSettings is set to true.

**Version 2.28.0 2024-09-11**
- Metadata for layer items like variables, projections, dimensions and styles are now stored in a database table called `layermetadata`. This can be disabled via the `enablemetadatacache` property in [Settings](doc/configuration/Settings.md).



**Version 2.27.0 2024-09-02**
- PostgreSQL query from `getFilesAndIndicesForDimensions` has been rewritten, which fixes https://github.com/KNMI/adaguc-server/issues/341.
- Optimized existing PostgreSQL queries and reduced number of PostgreSQL queries in general. This results in better performance, the benchmark tool runs 9% faster.
Expand Down
4 changes: 3 additions & 1 deletion adagucserverEC/CCairoPlotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,8 @@ void CCairoPlotter::drawBarb(int x, int y, double direction, double strength, CC
CT::string text;
text.print("%d", strengthInKnots);
if (drawText) {
this->drawStrokedText(x - cos(direction + M_PI) * 15 - 5, y + sin(direction + M_PI) * 12 + 5, 0, text.c_str(), 12, 1 * drawOutline, outlineColor, barbColor);
// If speed is really low, draw the text below the circle
double textDirection = strengthInKnotsRoundedToFive <= 2 ? -M_PI / 2.1 : direction;
this->drawStrokedText(x - cos(textDirection + M_PI) * 15 - 5, y + sin(textDirection + M_PI) * 12 + 5, 0, text.c_str(), 12, 1 * drawOutline, outlineColor, barbColor);
}
}
8 changes: 4 additions & 4 deletions adagucserverEC/CImgRenderFieldVectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int applyUVConversion(CImageWarper *warper, CDataSource *sourceImage, bool enabl

xpntNorthSph = sin(vecAngle); // Rotate the point/vector (0,1) around Z-axis with vecAngle
ypntNorthSph = cos(vecAngle);
xpntEastSph = ypntNorthSph; // Rotate the same point/vector around Z-axis with 90 degrees
xpntEastSph = ypntNorthSph; // Rotate the same point/vector around Z-axis with 90 degrees
ypntEastSph = -xpntNorthSph;

// zpntNorthSph = 0; zpntEastSph = 0; // not needed in 2D
Expand Down Expand Up @@ -380,8 +380,8 @@ std::vector<CalculatedWindVector> renderBarbsAndVectors(CImageWarper *warper, CD
if (!(units.equals("kts") || units.equals("knots"))) convertToKnots = true;

// Number of pixels between the vectors:
int vectorDensityPy = 50; // 22;
int vectorDensityPx = 50; // 22;
int vectorDensityPy = 60; // 22;
int vectorDensityPx = 60; // 22;
firstXPos = int(tx) % vectorDensityPy;
firstYPos = int(ty) % vectorDensityPx;
double u, v;
Expand Down Expand Up @@ -417,7 +417,7 @@ std::vector<CalculatedWindVector> renderBarbsAndVectors(CImageWarper *warper, CD
}
if (!drawGridVectors) {
if ((int(x - firstXPos) % vectorDensityPy == 0 && (y - firstYPos) % vectorDensityPx == 0) || (enableContour == false && enableShade == false)) {
strength = (strength)*1.0;
strength = (strength) * 1.0;

// Calculate coordinates from requested coordinate system
double projectedCoordX = ((double(x) / double(dImageWidth)) * (drawImage->Geo->dfBBOX[2] - drawImage->Geo->dfBBOX[0])) + drawImage->Geo->dfBBOX[0];
Expand Down
9 changes: 6 additions & 3 deletions adagucserverEC/CImgWarpBilinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

const char *CImgWarpBilinear::className = "CImgWarpBilinear";
void CImgWarpBilinear::render(CImageWarper *warper, CDataSource *sourceImage, CDrawImage *drawImage) {
CStyleConfiguration *styleConfiguration = sourceImage->getStyle();
#ifdef CImgWarpBilinear_DEBUG
CDBDebug("Render");
#endif
Expand Down Expand Up @@ -409,11 +410,13 @@ void CImgWarpBilinear::render(CImageWarper *warper, CDataSource *sourceImage, CD
}
}
if (enableBarb) {
CalculatedWindVector wv;

bool rendertextforvectors = styleConfiguration != nullptr && styleConfiguration->styleConfig != nullptr && styleConfiguration->styleConfig->RenderSettings.size() > 0 &&
styleConfiguration->styleConfig->RenderSettings[0]->attr.rendertextforvectors.equals("true");
for (size_t sz = 0; sz < windVectors.size(); sz++) {
wv = windVectors[sz];
CalculatedWindVector wv = windVectors[sz];
float outlineWidth = 0;
drawImage->drawBarb(wv.x, wv.y, wv.dir, wv.strength, CColor(0, 0, 255, 255), outlineWidth, wv.convertToKnots, wv.flip, false);
drawImage->drawBarb(wv.x, wv.y, wv.dir, wv.strength, CColor(0, 0, 255, 255), outlineWidth, wv.convertToKnots, wv.flip, rendertextforvectors);
}
}

Expand Down
5 changes: 4 additions & 1 deletion adagucserverEC/CServerConfig_CPPXSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ class CServerConfig : public CXMLSerializerInterface {
public:
class Cattr {
public:
CT::string settings, striding, renderer, scalewidth, scalecontours, renderhint, randomizefeatures, featuresoverlap;
CT::string settings, striding, renderer, scalewidth, scalecontours, renderhint, randomizefeatures, featuresoverlap, rendertextforvectors;
} attr;
void addAttribute(const char *name, const char *value) {
if (equals("settings", name)) {
Expand All @@ -833,6 +833,9 @@ class CServerConfig : public CXMLSerializerInterface {
} else if (equals("featuresoverlap", name)) {
attr.featuresoverlap.copy(value);
return;
} else if (equals("rendertextforvectors", name)) {
attr.rendertextforvectors.copy(value);
return;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef Definitions_H
#define Definitions_H

#define ADAGUCSERVER_VERSION "2.28.0" // Please also update in the Dockerfile to the same version
#define ADAGUCSERVER_VERSION "2.28.1" // Please also update in the Dockerfile to the same version

// CConfigReaderLayerType
#define CConfigReaderLayerTypeUnknown 0
Expand Down
11 changes: 10 additions & 1 deletion data/config/datasets/adaguc.tests.harm_windbarbs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<NameMapping name="thinbarb" title="Wind barbs (thinned)" abstract="Rendered with thinned barbs"/>
</Style>

<Style name="Windbarbwithnumbers">
<Scale>1</Scale>
<Offset>0</Offset>
<RenderMethod>barb</RenderMethod>
<RenderSettings rendertextforvectors="true" />
<NameMapping name="barb" title="Wind barbs with number" abstract="Rendered with barbs and wundspeed number"/>
<NameMapping name="thinbarb" title="Wind barbs with number (thinned)" abstract="Rendered with thinned barbs and windpeed number"/>
</Style>

<Layer type="database">
<Name>wind__at_10m</Name>
<Title>Wind 10m flags</Title>
Expand All @@ -18,7 +27,7 @@
<DataPostProc algorithm="ax+b" a="1" b="0" units="m/s"/>
<Dimension name="time" units="ISO8601" default="min">time</Dimension>
<Dimension name="forecast_reference_time" units="ISO8601">reference_time</Dimension>
<Styles>Windbarbs</Styles>
<Styles>Windbarbs,Windbarbwithnumbers</Styles>
</Layer>

<!-- End of configuration /-->
Expand Down
2 changes: 1 addition & 1 deletion doc/configuration/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Configuration
with custom image
- [Stippling](Stippling.md) (distancex, distancey, discradius)
Configuration of stippling renderer.
- [RenderSettings](RenderSettings.md) (settings, striding, renderer, scalewidth, scalecontours, renderhint) Configuration of
- [RenderSettings](RenderSettings.md) (settings, striding, renderer, scalewidth, scalecontours, renderhint, rendertextforvectors) Configuration of
renderers

<!-- -->
Expand Down
10 changes: 9 additions & 1 deletion doc/configuration/RenderSettings.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RenderSettings (settings, striding, renderer, scalewidth, scalecontours, renderhint)
RenderSettings (settings, striding, renderer, scalewidth, scalecontours, renderhint, rendertextforvectors)
=============================================

Back to [Configuration](./Configuration.md)
Expand All @@ -19,6 +19,14 @@ Controls behaviour of nearestneighbour rendering
<RenderSettings settings="precise"/>
```

# rendertextforvectors

```xml
<RenderSettings rendertextforvectors="true" />
```

When set to true, it will render text with windbarbs.

# striding

Controls how many grid cells are skipped. E.g. if set to 2, every other
Expand Down
31 changes: 31 additions & 0 deletions tests/AdagucTests/TestWMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,37 @@ def test_WMSGetMapWithHarmWindBarbs(self):
0.1,
)
)

def test_WMSGetMapWithHarmWindBarbsWithText(self):
AdagucTestTools().cleanTempDir()
filename = "test_WMSGetMapWithHarmWindBarbs_without_outline_with_text.png"
config = ADAGUC_PATH + "data/config/adaguc.tests.dataset.xml"
# pylint: disable=unused-variable
status, data, headers = AdagucTestTools().runADAGUCServer(
args=[
"--updatedb",
"--config",
config + ",adaguc.tests.harm_windbarbs.xml",
],
env=self.env,
isCGI=False,
)
self.assertEqual(status, 0)

status, data, headers = AdagucTestTools().runADAGUCServer(
"DATASET=adaguc.tests.harm_windbarbs&SERVICE=WMS&SERVICE=WMS&=&=&VERSION=1.3.0&REQUEST=GetMap&LAYERS=wind__at_10m&WIDTH=914&HEIGHT=966&CRS=EPSG:3857&BBOX=10144.960912989336,6256275.017522922,1229386.3384520854,7544882.425294002&STYLES=Windbarbwithnumbers/barb&FORMAT=image/png&TRANSPARENT=FALSE&time=2023-09-30T06:00:00Z&DIM_reference_time=2023-09-28T06:00:00Z&BGCOLOR=0x000000&",
{"ADAGUC_CONFIG": ADAGUC_PATH + "data/config/adaguc.tests.dataset.xml"},
)
AdagucTestTools().writetofile(self.testresultspath + filename, data.getvalue())
self.assertEqual(status, 0)
self.assertTrue(
AdagucTestTools().compareImage(
self.expectedoutputsspath + filename,
self.testresultspath + filename,
3,
0.1,
)
)

def test_WMSGetMap_EPSG3067(self):
AdagucTestTools().cleanTempDir()
Expand Down
Binary file modified tests/expectedoutputs/TestCSV/test_CSV_windbarbs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.