Skip to content

Commit 4e1c9b6

Browse files
committed
Add RFC-139: Raster labeling (CONNECTIONTYPE RASTERLABEL)
1 parent 168282f commit 4e1c9b6

File tree

3 files changed

+149
-1
lines changed

3 files changed

+149
-1
lines changed

en/development/rfc/index.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,5 @@ the project.
149149
ms-rfc-135
150150
ms-rfc-136
151151
ms-rfc-137
152-
ms-rfc-138
152+
ms-rfc-138
153+
ms-rfc-139

en/development/rfc/ms-rfc-139.txt

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
.. _rfc139:
2+
3+
=========================================================================
4+
MS RFC 139: Raster labeling (CONNECTIONTYPE RASTERLABEL)
5+
=========================================================================
6+
7+
:Date: 2024/08/14
8+
:Author: Even Rouault
9+
:Contact: even.rouault at spatialys.com
10+
:Status: Draft
11+
:Version: MapServer 8.4
12+
13+
1. Overview
14+
-----------
15+
16+
This is a proposal to add the ability to render labels from raster pixel values,
17+
as an alternative or complement to other typical raster rendering (grayscale,
18+
classification, etc.). Typical applications are for temperature, wind, humidity,
19+
slopes, altitude, noise, pollution, etc.
20+
21+
Visual example (rendered with MapServer):
22+
23+
.. image:: ../../images/rasterlabel.png
24+
25+
2. The proposed solution
26+
------------------------
27+
28+
This RFC proposes the addition of a new type of layer in MapServer:
29+
CONNECTIONTYPE RASTERLABEL.
30+
The code is strongly based on the UVRASTER capabilities, but will be kept separate
31+
as some likely potential evolutions of UVRASTER (such as modifying u,v values
32+
during reprojection operations) will make both implementation diverge.
33+
34+
The new type is a hybrid layer, which has a raster data source as input and
35+
vector features as output. Only the point representation of those
36+
vector features will be supported. Values at nodata will be ignored.
37+
38+
Since the data source is a raster, all raster processing options can be
39+
used (e.g. RESAMPLE). A default value of RESAMPLE=AVERAGE will be used, if it
40+
is not explicitly defined.
41+
42+
To render a vector field layer, we need to define a layer in the mapfile
43+
with the following options:
44+
45+
* Set the layer TYPE to POINT.
46+
* Set CONNECTIONTYPE to RASTERLABEL.
47+
* Set the DATA to the raster file.
48+
* If the raster file has more than one bands, add a PROCESSING "BANDS=<num>" option
49+
* Specify a CLASS with a LABEL object to label the points, using the [value]
50+
attribute binding.
51+
52+
Optional "PROCESSING" settings:
53+
54+
* BANDS=<num>: Specify the band to label. Not needed if there is a single band.
55+
* LABEL_SPACING=<num>: The spacing is simply the distance, in pixels, between points
56+
to be displayed in the vector field. Default is 32.
57+
* RESAMPLE=NEAREST/AVERAGE/BILINEAR: Defaults to AVEAGE.
58+
* ALLOW_OVERSAMPLE=YES/NO: Whether it is allowed to oversample the raster at
59+
a resolution higher than its nominal resolution. Default is NO, meaning that
60+
when zooming in beyond the nominal resolution of the raster, at most one
61+
point will be generated for each source pixel. This gives to the user a sense
62+
of the resolution of the data it displays.
63+
64+
The UVRASTER layer has one attribute bindings that can be used in the layer
65+
definition and/or class expressions:
66+
67+
* [value]: the raw raster value
68+
69+
Example of a layer definition:
70+
71+
::
72+
73+
LAYER
74+
NAME "temperature"
75+
TYPE POINT
76+
CONNECTIONTYPE RASTERLABEL
77+
PROJECTION
78+
"init=epsg:4326"
79+
END
80+
DATA data/temperature.tif
81+
# PROCESSING "BANDS=1"
82+
# PROCESSING "LABEL_SPACING=32"
83+
# PROCESSING "RESAMPLE=AVERAGE"
84+
# PROCESSING "ALLOW_OVERSAMPLE=NO"
85+
CLASS
86+
TEXT (tostring([value],"%.1f")+"°")
87+
LABEL
88+
TYPE TRUETYPE
89+
SIZE 7
90+
END # label
91+
END # class
92+
END
93+
94+
95+
3. Implementation Details
96+
-------------------------
97+
98+
Internally, a RASTERLABEL layer will have its own renderer/driver code. It's a
99+
hybrid layer because it reads the raster source as a normal raster
100+
layer does, but all other functions behave like a vector layer. The
101+
layer can be drawn as a normal point layer using whichShape, GetShape
102+
etc.
103+
104+
Basic internal draw process of a RASTERLABEL layer:
105+
106+
1. whichShape() is called: the raster data source is read using the
107+
internal GDAL functions, resample and all other raster options are applied
108+
and the pixels result is stored in the internal layer structure.
109+
110+
2. getShape() is called: loop through the raster pixels and returns a
111+
shapeObj (Point) created with the pixel location.
112+
113+
3. MapServer draws its point feature as any other vector layer.
114+
115+
3.1 Files affected
116+
------------------
117+
118+
The following files will be modified/created by this RFC:
119+
120+
::
121+
122+
mapserver.h/mapfile.c (Connection type RASTERLABEL support in the mapfile)
123+
maprasterlabel.cpp (new file for the RASTERLABEL renderer)
124+
mapuvraster.cpp (renamed from mapuvraster.c, not strictly correlated with this development, but was the opportunity to make an optimization to make getShape() faster when requesting increasing feature index, that is also used by maprasterlabel.cpp)
125+
maplayer.c (new layer type handling, virtual tables init etc.)
126+
maplexer.l (add additional RASTERLABEL keyword)
127+
128+
3.2 MapScript
129+
-------------
130+
131+
No issue for any MapScript bindings. The RASTERLABEL layer is handled/rendered internally as
132+
any other layer..
133+
134+
3.4 Backwards Compatibility Issues
135+
----------------------------------
136+
137+
This change provides a new functionality with no backwards compatibility issues being considered.
138+
139+
4. Candidate implementation
140+
---------------------------
141+
142+
* https://github.com/MapServer/MapServer/pull/7135
143+
144+
5. Voting history
145+
-----------------
146+
147+
TBD

en/images/rasterlabel.png

14.6 KB
Loading

0 commit comments

Comments
 (0)