Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request. [Bug]: Unique Values on a numeric field sorts its classes and legend as text (10153 before 1741) #1340 / fix(style): Unique Values on numbers in numeric order, and say what is past the first 64 (#1340) #1373 added the notice for features past the first 64 values. fix(ui): the Symbology pane lists up to 200 Unique Values classes, and says how many it leaves out #1543 lets the Symbology pane list up to 200 classes. [Feature]: Unique Values classes keep the order they are listed in, by choice (High, Medium, Low) #3319 is about class order. None of them lets a field get more than 64 classes.
What problem does this solve?
Soil, geology, land-use and zoning maps often have far more than 64 mapping units. A soil survey of the state of Ceará (Brazil), for example, has 713 distinct values in its unit field (UnidMapFin: PVAe1 … PVAe38, RLe1 … RLe165, …).
layer.symbology {"type": "unique", "field": "UnidMapFin"} keeps the first 64 values in text order and draws the rest as <all other values>:
FUNCEME_SolosCE: 3942 features whose value is past the first 64 values of UnidMapFin (in text order) are drawn as <all other values>
So 3,942 of 5,203 polygons (76 %) are drawn in the same grey. The layout legend then lists Agua … LAd39 and <all other values>, which is alphabetical order, not importance. The map can't be made this way, and no setting changes the 64.
The limit applies only when classes are made automatically from a field. Elsewhere RustGIS already handles more:
| Path | Limit | Where |
|---|---|---|
Unique Values from a field (layer.symbology, the Symbology pane's Classify, subtypes) |
64 | MAX_UNIQUE, crates/map/src/symbology.rs:1075, used by Renderer::unique_counted (:1239-1241) and layer.rs:8365/:8397, design.rs:2379 |
| Unique Values from an expression, applied again | up to 200 | MAX_EXPRESSION_CLASSES, symbology.rs:1078, unique_by_up_to (:1286-1294), layer.rs:8366-8370 |
| QGIS / ArcGIS style import | 4096 | qgis/renderer.rs:17, arcgis_style.rs:16 |
| Symbology pane list | 200 | panes.rs:5641-5653 |
| Layout legend | no class limit; up to 6 columns, adjustSize down to 4 pt |
render/src/layout/legend.rs, map/src/layout/legend.rs:382 |
The 64 is a safe default, but it shouldn't be a hard limit when a style import can bring 4,096 classes and the legend can draw them.
A second, smaller problem shows up at once: the default qualitative ramp (Harbour) has 10 colours, and Ramp::pick cycles them (k % len, crates/map/src/color.rs:616-635). Class 0 and class 10 get the same colour, and so do classes 1 and 11, and so on. With 64 classes each colour is used six or seven times, so two neighbouring units can have the same colour. With more classes this gets worse.
Proposed solution
-
maxClassesinlayer.symbology(Unique Values only; refused for the other types):layer.symbology {"layer": "Solos", "type": "unique", "field": "UnidMapFin", "maxClasses": 1000}- It ranges from 1 to
MAX_UNIQUE_CLASSES, a new constant of 1000, the same asMAX_LEGEND_LABELS(map/src/layout/legend.rs:9). The default stays 64, so existing projects and scripts behave as before. - The field path calls a new
Renderer::unique_up_to(ds, rows, field, ramp, base, max), which mirrorsunique_by_up_to.unique_countedstays asunique_up_to(…, MAX_UNIQUE). - The same key goes to the expression path in place of the fixed
keep.MAX_EXPRESSION_CLASSESstays as the most a re-applied rule style keeps. - The notice gives the number actually used: "… past the first {max} values …". When features are past it, the notice adds "
maxClassesup to 1000 keeps more". - The Symbology pane gets a Classes: [64 ▾] field next to Classify for Unique Values (64, 128, 256, 512, 1000). It lists them all, so the pane limit of 200 (
panes.rs:5641-5653) goes up toMAX_UNIQUE_CLASSES.
- It ranges from 1 to
-
Distinct colours past the ramp's length: a qualitative ramp with s stops gives class k the stop
k % s, shifted in lightness by its roundr = k / s. The shift goes −12 %, +12 %, −24 %, +24 % … in OKLab L, clamped to 15–92 %. That way class k and class k + s are never the same colour. Rounds past four start again at four times the stop count, with a hue turn of 360° / (2s). A custom ramp with exactly n stops keeps its colours as they are (current behaviour). -
Docs: in
user-guide/cartography.md(Unique Values), mentionmaxClassesand say that a field with hundreds of units reads better when classes are grouped by an expression, such as the code without its trailing numbers (replace(…'0','')…), with each class labelled throughlayer.classStyle {"label"}. That works today, and it is how the Ceará map was made: 52 classes in 13 layers, one per soil order, each name used as a legend heading.
In parts (each under 400 lines; only the last says "Closes"):
maxClassesfor fields and expressions inlayer.symbology,Renderer::unique_up_to, the notice, and engine and map tests. Tests: 100 values withmaxClasses: 100keep 100 classes and no notice; the default still keeps 64 and gives the notice;maxClasses: 0and1001are refused;maxClasseswith"type": "graduated"is refused.- Distinct colours past the ramp's length in
Ramp::pick, with tests: for Harbour, classes 0 and 10 differ, and the first 10 classes keep today's colours. - The Symbology pane's Classes field, raising the pane's list to
MAX_UNIQUE_CLASSES, and the docs.
Alternatives considered
- Only raise
MAX_UNIQUEto 1000. Simpler, but a field with thousands of distinct values, such as a name or id field, would then make 1,000 classes by accident on a plain Classify. Keeping 64 as the default and making the higher number a choice avoids that. - Group automatically, by prefix or by the most frequent values. Useful, but how to group is a decision about the data (soil order, suborder, unit). Expressions already do it. A "top N by count, rest as Other" order could be a follow-up option (
"order": "count"). - A legend table element listing unit codes and descriptions. That belongs to layout tables ([Feature]: Layout bar charts: group and aggregate, order, bar limit, and look #2487 family), not to symbology.
Additional context
- Reproduction:
→ the notice above; the layout legend shows 64 classes plus
layer.addData {"path": "<abs path>/FUNCEME_SolosCE.shp"} layer.symbology {"layer": "FUNCEME_SolosCE", "type": "unique", "field": "UnidMapFin"}<all other values>. Any field with more than 64 distinct values reproduces it, for example a points layer with anamefield. - Workaround used today:
"expression": "replace(replace(… UnidMapFin,'0','') …,'9','')"gives 52 classes, which fits in 64, with one layer per soil order (each a definition query) so that the legend shows the order names as headings. The A2 landscapepanellayout keeps the 52 rows at about 6.5 pt. In A3 the legend'sadjustSizebrings them down to about 4.7 pt.
Activity