Skip to content

feat(symbology): size classified points by a field alongside their colours (#1017) - #2130

Merged
Mavrick-F merged 26 commits into
opengeos:mainfrom
Mavrick-F:feat/size-by-field-1017
Nov 17, 2026
Merged

Mavrick-F merged 26 commits into
opengeos:mainfrom
Mavrick-F:feat/size-by-field-1017

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

A Unique Values or Graduated Colors point layer can now also be sized by a number field. Each point keeps its class's colour and takes the size its value gives. GeoLibre projects that colour by one field and size by another now import with both channels.

  • Model: an optional Layer::size_by (field, min, max, min_size, max_size, scaling). Styler applies it after the class symbol and before symbol_by expressions, so a Size expression still wins where it gives a value. Stacked marks scale with it as they do with a size expression. It sits on the layer rather than inside the two renderer variants, so the 45 places that build those renderers stay unchanged. Under Single or Proportional it is kept but unused.
  • Scaling: area grows the marker's area with the value. It reuses the Proportional Symbols formula, now one shared scaled_size, so Proportional Symbols draw as before, except that a range so wide its width overflows (beyond about 1e308) now takes the middle size for every value instead of the smallest, and a NaN value gives the middle size where it gave a NaN size. radius grows the size linearly, as GeoLibre/MapLibre does.
  • Defined edge cases: values past either end take that end's size. A null or non-numeric value keeps its class's size. A range with no width draws every point at the middle size, as Proportional Symbols do; a finite range too wide to subtract takes the same fallback instead of overflowing. layer.sizeBy rejects both. A final size of zero draws no marker, after a Size expression has had its say. Attribute values are only read, never changed.
  • Command: layer.sizeBy {"layer"?, "field": numeric|null, "min"?, "max"?, "minSize"?, "maxSize"?, "scaling"?: "area"|"radius"}. Values not given keep the mapping's, else they default to the field's range, 4–24 pt and area. It refuses non-point layers, other renderers, non-numeric fields, an empty range and sizes outside 0–400 pt, and a refused call adds no undo step. Repair checks the field like the rotation field. On the desktop, finding the field's range runs on the background read queue with progress and Cancel; a result for a layer whose rows or fields changed meanwhile is refused. A streamed layer needs explicit bounds, and a range too wide to scale over is refused. The command is admitted on the scoped MCP route like the other layer styling commands.
  • Editing: below Rotation, the Symbology pane has Size by (field), Values, Sizes and Scaling rows for classified point layers. Choosing a field opens a draft of those rows with Use field range, Apply and Cancel, and nothing changes on the layer until one is clicked. A field with one value throughout, or none yet, can still be set up by typing its Values. An applied mapping edits row by row as before.
  • Legends: the Layers pane and layout legends list the colour classes, then three size rows: the smallest, middle and largest value, labelled with the field. A shown legend's no-data row comes after them. A mapping whose field the layer doesn't have adds no rows. Each row draws the first class's marks, stacked marks included, scaled with the same helper the map uses.
  • Saved files: a project (offline map copies included), a map or layer item, or a map or mobile package that holds a size mapping is saved as format 2 with "requires": ["classified-point-size"], so a RustGIS that can't keep the mapping refuses the file rather than dropping it on the next save. A file without one keeps format 1 and its exact previous form, and removing the last mapping removes the requirement. A malformed size_by is refused, not dropped; a long field name that RustGIS writes reads back. The schema lists the capability and says files are written as format 1 or 2; schema/fixtures/size_by.rgis is the read fixture.
  • GeoLibre import: a categorized or graduated style with proportional size now creates a radius-scaled mapping with no fixed-size note. The class symbols take the minimum radius, so a feature with a missing value draws at the smallest size, as GeoLibre draws it. An absent or non-numeric size field, or an empty size range, keeps the colours and says the size is fixed. A radius or value bound clamped on import is reported, for single and classified styles alike.
  • Surfaces: the desktop and the browser share the Symbology pane's Size by rows (in the browser the range scan runs inline, as the browser has one thread). The command reaches the command line, Python's run, command search, the Assistant and MCP (its parameter help lists every option). The phone interface has no symbology editor, so it reaches the mapping only by drawing it. No ribbon button: the rows sit in the Symbology pane. The way back: each change is undoable, {"field": null} or None removes the mapping, and saved projects reopen with it.

Testing

  • New tests:
    • symbol_by::a_size_mapping_sizes_classed_points_and_keeps_their_colours: radius and area scaling, null, text and out-of-range values, empty range, a zero size drawing nothing, colours and attributes unchanged, legend rows with stacked marks scaled, unused under Single.
    • symbol_by::a_size_mapping_is_saved_only_when_set_and_refused_when_malformed: omitted when absent, round trip, malformed values refused.
    • symbol_by::a_size_range_too_wide_to_divide_uses_the_midpoint: a finite range whose width overflows f64 takes the middle size.
    • geolibre::style_tests::geolibre_colour_classes_keep_their_proportional_size: the earthquakes shape gives a radius mapping with no note; an absent field or empty range gives a note; clamped bounds are reported.
    • tests::a_classified_point_layer_is_sized_by_a_field: command defaults, refusals without an undo step, undo, removal, and the fixture read back.
    • tests::a_size_field_range_is_prepared_off_the_window_thread: the range scan runs on the read queue, and a result for a layer that changed meanwhile is refused.
    • tests::a_streamed_layer_needs_bounds_for_its_size_mapping: a streamed layer's range isn't taken from the view's features; explicit bounds work.
    • tests::size_mappings_require_a_reader_that_keeps_them: format 2 and the requirement only while a mapping exists, in projects, items and packages.
    • panes::tests::size_fields_with_constant_or_missing_values_can_be_configured: a constant or all-null field opens editable bounds and applies.
  • project_save_roundtrip includes layer.sizeBy steps. Locally on this head (after merging main and the autofix commit): the tests above, the render legend tests (16 passed), clippy -D warnings on map, engine, render, assistant and ui-egui, a wasm check, and fmt. Full gate: fork CI (Linux) passed on this head.
  • Manual: imported GeoLibre's hosted demo https://share.geolibre.app/giswqs/earthquakes-last-30-days.geolibre.json (graduated by depth_km, sized by mag 2.5–7.5 → radius 2–18 px). Then I saved it as .rgis, reopened it, and compared screenshots. Depth colours, magnitude sizes, the legend and the editor all survive the reopen. The import's remaining notes are the pop-ups, which are unrelated. With ui_shot, a field that is all null and one that is constant both set up through the draft rows; the saved files are format 2 with the requirement and keep the mapping.

UI evidence

The "before" is main's import result reproduced on this build: the mapping removed and the classes at main's fixed 12 pt, so it also shows the new Size by row set to None. I didn't build a separate main binary.

Before (main's result: depth colours, fixed size):

before

After import (depth colours, magnitude sizes, Size by editor, size rows in the legend):

after import

After save and reopen:

after reopen

A field with no values yet (missing), applied with typed bounds; its points take the smallest size:

missing field

Choosing a field with one value throughout (constant) opens the draft rows with editable bounds, Apply and Cancel:

constant field

Limits: the Layers pane fits its swatches in a small box, so it draws the size rows on one shared scale rather than at their map sizes. The GPU fast path is skipped for a layer with a size mapping, which is then drawn on the CPU as layers with symbol expressions are.

Related issue

Closes #1017

Summary by CodeRabbit

  • New Features
    • Point layers with unique-value or graduated-color styles can size markers by a numeric field while retaining class colors, using area- or radius-based scaling.
    • Set value bounds and marker-size limits in the interface or with layer.sizeBy; bounds can be detected from field values when available. Legends show size variations, and GeoLibre imports support combined color and size styles.
    • Saved projects record when they contain size mappings so compatible applications can preserve them.
  • Bug Fixes
    • Removing a mapped field, or refreshing data where it is no longer numeric, clears its size mapping. Replacing a field preserves numeric compatibility.
    • Notices clarify when aggregation or web output prevents size mappings from appearing.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:windows Run the Windows CI jobs on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support proportional size alongside classified point colours

3 participants