Skip to content

feat(layout): raster profiles beside a map frame (#2863 part 2) - #3256

Closed
elpidioassinaturas wants to merge 1 commit into
opengeos:mainfrom
elpidioassinaturas:feat/2863-margin-profiles
Closed

elpidioassinaturas wants to merge 1 commit into
opengeos:mainfrom
elpidioassinaturas:feat/2863-margin-profiles

Conversation

@elpidioassinaturas

Copy link
Copy Markdown
Contributor

Part of #2863 (part 2 of 5: profiles along a side, layout-profile). Part 1, the section lines, is in main (#2872, #3140).

What it does

A new layout element, Profile (Publish › Map Surrounds, and layout.addElement with "kind": "profile"), draws the profile of a raster along one of its frame's section lines, beside the frame:

  • Lined up with the map. Each sample is read at its point of the section line on the page, taken back through the frame's projection to the ground, so each point of the curve is straight under (or beside) the place it comes from, whatever the projection or the frame's bearing. That line is neither a parallel nor the straight line between its ends' longitudes and latitudes that profile.create follows.
  • Follows the frame. Its box is the frame's side along its length (Profile::rect): under or over the frame for a horizontal section line, right or left of it for a vertical one, with a gap and a thickness of its own. Moving or resizing the frame takes the profile with it (Layout::fit_profiles, run by layout.update, layout.duplicateElement and when a layout is read). Dragging the profile changes its gap, resizing it its thickness; along the frame it keeps the frame's.
  • Any raster, any band. layer and band (1-based); not always band 1 called elevation. It has a title (default: the layer's name), a unit after the value axis' numbers, and the value axis from the samples out to round numbers, or min and max given, so two profiles can share a scale. The distance axis counts along the ground (WGS 84) from the line's A end, in the units a scale bar takes. Guide lines, the section's names at the ends (in its colour), an ink (color), a background, the layout's decimal comma.
  • Drawn as a line (lineColor, lineWidth), filled under it in one colour (fill, null for none). No data breaks the curve.
  • Sampled at the raster's cell size, counted along the line in its own grid, up to 10,000 samples (the profile.* commands' limit), bilinear, nothing smoothed. The bilinear read moves to rustgis-data (Raster::bilinear), which rustgis-render can reach; rustgis_analysis::rasterops::elevation_at now calls it, so profile.* keep their results.
  • It follows its section line and its layer when they are renamed, and goes with its frame.
layout.addElement={"kind":"section","frame":1,"name":"A","direction":"horizontal","at":[-44.66,-22.38]}
layout.addElement={"kind":"profile","frame":1,"section":"A","layer":"DEM","side":"bottom","unit":"m","min":400,"max":2900}
layout.update={"element":5,"thickness":36,"fill":null,"lineColor":"#1F5C84"}

Never silent

A profile that can't be drawn draws its placeholder, and says why, once, with the profile named: when it is added or changed, in the layout view, and in PNG, PDF and SVG exports and reports (for a map series' PDF, on how many pages):

  • a tilted frame or one on the globe (a line straight on the page there isn't a section of the ground);
  • a section line running the other way from its side, or one the frame doesn't have or doesn't draw;
  • a layer that isn't a raster of the frame's map, a band it hasn't, no pixels read, or no data along the whole line;
  • a raster read in place (a web address's cloud-optimised GeoTIFF, a tiled GeoTIFF too large to hold): the view reads an overview of it that changes with the scale, so the profile would change with it. The commands refuse such a layer with the reason.

A profile read at 10,000 samples along a line crossing more cells says so, with the cells.

Checks against profile.create (the issue's Mantiqueira)

On the Copernicus DEM GLO-30 of the issue (UTM 23S, 1:200,000, frame 186 × 112 mm), with this branch:

Section Samples Elevations Length profile.create between the ends, as many samples
B, vertical, through the Pedra da Mina 748 (one a cell) 610 to 2,791 m 22,411 m apart by 0.12 m at most, 0.02 m on average
A, horizontal, through the Agulhas Negras 1,242 614 to 2,764 m 37,218 m apart by 14.67 m at most, 2.14 m on average

The vertical line of a UTM frame strays little from the straight line of longitude and latitude between its ends, so the two agree within 0.12 m, as the issue found (0.11 m over 1,600 samples). The horizontal one strays: profile.create reads up to 14.7 m off the page's line there, which is what the profile is for. The tests repeat both on a synthetic relief of the same frame (the DEM isn't committed): the_mantiqueira_profile_agrees_with_profile_create (within 0.5 m), and a_profile_is_read_along_the_line_on_the_page / the_page_line_is_not_a_straight_line_of_longitude_and_latitude, on grids whose value is their own northing or easting, where a page line reads one value end to end and the chord between its ends doesn't. a_profiles_peak_is_drawn_straight_across_from_its_place renders the page and finds a peak's top within 3 pixels of where the frame shows it, on all four sides, with the frame turned. Lengths are on the ellipsoid; profile.create measures on the sphere, 0.4 % longer here.

Screenshot

The Mantiqueira page drawn by this branch (Copernicus DEM GLO-30, © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018, provided under COPERNICUS by the European Union and ESA): two dashed section lines, profile A under the frame and B at its right, sharing a scale from 400 to 2,900 m.

A layout page: a shaded relief of the Mantiqueira with two dashed section lines, A across and B down, the profile of A under the frame and the profile of B at its right, each lined up with its line

Saved files

A layout with a profile requires layout-profile (projects, layout files, saved commands: layout.addElement of a profile, layout.update with a key only a profile reads, layout.import and report.existingTemplate of a layout file with one). A layout without one keeps its bytes. Schema regenerated; new fixture schema/fixtures/layout_profile.rgis, read back byte for byte by the layout-file test. A hand-edited file is brought into range (gap, thickness, line width, band, one-line title and unit), and a profile saved away from its frame's side is put back beside it, counted as adjusted.

Reach

  • Desktop: Publish › Map Surrounds › Profile; the layout view draws it, drags and resizes it (gap and thickness), and says what it doesn't draw. No Format pane rows yet: as part 1b did for section lines, they can follow in their own pull request; until then layout.update sets everything.
  • Browser: nothing desktop-only (no file access of its own; rendering is the page's).
  • Command line, Python, plugins, Assistant and MCP: layout.addElement / layout.update, whose help lists the new keys; command surface updated.
  • Phone: the touch interface has no layout editing; a layout opened there draws it.
  • The way back: undo, layout.removeElement, removing the frame, saved and reopened.

Memory and threads

No copy of the raster: a profile holds at most 10,000 samples (three numbers each, 240 KB), worked out when its page is drawn. Sampling runs on the thread that draws the page, as the rest of the page; its work is bounded by the 10,000 samples, so it adds no background command.

Tests

cargo test -j 4 for rustgis-data, rustgis-analysis, rustgis-map, rustgis-render, rustgis-engine and rustgis-ui-egui; cargo fmt, cargo clippy -D warnings on those crates (all targets), cargo xtask schema --check, and the command-surface snapshot. Locally (Windows): map 515, render 919, analysis all, data 1,914 + 70, ui-egui all (1,683 + the rest), engine lib 2,749 and integration 244 pass; two engine tests fail here as they do on main on this machine (layout_report_text::a_report_measures_each_layout_page_with_its_own_page_number, which measures text with this machine's fonts, and portable_projects::reload::wrong_geometry…, which matches an English OS error).

New tests: a_profile_keeps_to_its_frames_side (map); a_profile_is_read_along_the_line_on_the_page, the_page_line_is_not_a_straight_line_of_longitude_and_latitude, a_profiles_peak_is_drawn_straight_across_from_its_place, a_profile_not_drawn_says_why, a_profiles_value_axis_is_round_or_given (render); a_profile_is_added_follows_its_frame_and_is_undone, a_profile_not_drawn_is_said, the_mantiqueira_profile_agrees_with_profile_create (engine); the layout-profile sample in the capability tests and the fixture in the layout-file test.

No i18n catalogs touched; the icon is drawn in code.

🤖 Generated with Claude Code

A Profile element draws, beside a map frame, a raster's profile along one
of the frame's section lines: under or over it for a horizontal line,
right or left of it for a vertical one. Each sample is read at its point
of the line on the page, taken back through the frame's projection, so
the curve is straight across from the place it comes from. Its box is
the frame's side, which it follows when the frame is moved or resized;
dragged or resized, it changes its gap and thickness.

It reads any band of a raster held whole, bilinearly, a sample a cell up
to 10,000 (Raster::bilinear, moved into rustgis-data from analysis'
elevation_at, which now calls it), and draws a line filled under it or
not, a value axis (round or given min and max), a distance axis along
the ground, guides, a unit, a title and the section's names. One that
can't be drawn (a tilted or globe frame, a raster read in place, a band
it lacks, no data) draws its placeholder and says why, in its commands,
the layout view, exports and reports.

A layout with one requires layout-profile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

self.line_width = finite_or(self.line_width, PROFILE_LINE_WIDTH).clamp(PROFILE_LINE_WIDTHS.0, PROFILE_LINE_WIDTHS.1);
self.band = self.band.clamp(1, MAX_PROFILE_BAND);
self.min = self.min.filter(|v| v.is_finite());
self.max = self.max.filter(|v| v.is_finite());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hand-edited file with min at or above max loads unchanged, and given_range then drops both ends at draw time. The value axis silently reverts to the samples' own range, and clamp counts no repair. The command path refuses such a pair on entry (profile_params), so only a hand-edited file reaches this. AGENTS.md's "Never silent" rule asks that a reader which drops or changes a value says so. Repairing the pair on load fixes it, and because Layout::clamp compares the element's kind, the repair counts as an adjusted element with no further change:

Suggested change
self.max = self.max.filter(|v| v.is_finite());
self.max = self.max.filter(|v| v.is_finite());
if matches!((self.min, self.max), (Some(lo), Some(hi)) if lo >= hi) {
(self.min, self.max) = (None, None);
}

Confidence: high that the value is ignored without a notice. Medium on the fix: the doc says "read only when below the other end", so the maintainers may prefer a notice over a repair.

Category: bug

out.metres.push(metres);
out.values.push(at.and_then(|c| r.bilinear(band, c)));
}
if out.values.iter().all(Option::is_none) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails only when no sample has a value. A line that leaves the raster partway (the raster covers part of the frame's section, or it has a no-data stretch along it) draws a broken curve with no notice. profiles_not_drawn reports only the whole-line failure and the cell count, so the missing part is dropped silently. AGENTS.md's "Never silent" rule asks that a reader or tool that drops data says what, how much and where. A fix would count the samples without a value in ProfileSamples and carry that count in ProfileNote next to cells, then say it in profiles_notice.

Confidence: about 50%. The PR body says "No data breaks the curve", so the gap may be a deliberate choice that still needs a notice.

Category: bug

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base-branch AGENTS.md, and the surrounding code: Layout::clamp, the layout-view redraw, the layer rename and removal paths, and the project read routes. There are no prior review threads on this PR, so no earlier concerns were skipped. I posted two inline comments, both for bugs.

Bugs

  • Silently ignored min/max on load (inline, crates/map/src/layout/profile.rs:209): a hand-edited file with min ≥ max draws with the samples' own axis, and no repair is counted. The inline comment includes a suggestion that clears the pair in clamp, which makes the element count as adjusted. Confidence: high that it is silent; medium on the fix, since the maintainers may prefer a notice.
  • Partial no-data along the section line is silent (inline, crates/render/src/layout/profile.rs:112): only an all-missing line is reported. A line that leaves the raster partway draws a gap with no notice, which the "Never silent" rule covers. Confidence: about 50%, since "No data breaks the curve" in the PR body may be a deliberate choice that still needs a notice.

Security

  • None found. The new parsing takes its values from the command params and from layout files, and it clamps or refuses them. I found no secrets or injection paths.

Performance

  • Each redraw samples every profile twice: once when the page is drawn, and again in the notice pass at crates/ui-egui/src/layoutview.rs:438. Export repeats the notice pass for each page of a series. Sampling is bounded at 10,000 samples per profile, so this costs time rather than hanging. Confidence: low to medium that it matters in practice.

Quality

  • update_profile reports both gap and thickness as held even when only one was clamped (crates/engine/src/cmd/layout/profile.rs, around line 650).
  • Profile::take_rect calls clamp(), which also rewrites the title, unit, and section name as a side effect of a box change.
  • command_uses_profile matches kind case-insensitively, while add_element and element_inputs match "profile" exactly. This over-requires the capability and is harmless.

AGENTS.md

  • No break found. I checked these against the rules:
    • No unwrap, expect, panic, or indexing in non-test code. The ends[0] indexing is on a fixed-size array.
    • The command surface and the capability list are updated.
    • The schema change is complete: project.schema.json lists capabilities, not element kinds, so the two added lines are the whole change.
    • A fixture is added and read back in the layout-file test.
    • The new ribbon label follows the neighbouring buttons.
  • Twin checks:
    • The layer rename and removal paths handle Profile alongside Table, Chart, and Colorbar.
    • render_region, update.rs:779, and inputs.rs:224 deliberately leave profiles out, because they read a raster and not the frame's features.
    • Every layout read route runs Layout::clamp, so profiles are repositioned on load.

Change size

Compared: the whole PR against main (merge base 65e1068 to PR head 9b56f3c).

Measure Value
Files changed 30 (6 added, 24 modified, 0 removed, 0 renamed)
Size before 5.97 MB
Size after 6.06 MB
Total size change +92.2 KB
File Before After Change
crates/render/src/layout/profile.rs 0 B 21.2 KB +21.2 KB
crates/engine/src/cmd/layout/profile.rs 0 B 14.9 KB +14.9 KB
crates/render/src/layout/profile_tests.rs 0 B 13.6 KB +13.6 KB
crates/engine/src/tests/layout_profiles.rs 0 B 11.5 KB +11.5 KB
crates/map/src/layout/profile.rs 0 B 8.9 KB +8.9 KB
crates/map/src/layout/tests.rs 109.1 KB 113.8 KB +4.6 KB
crates/engine/src/cmd/layout.rs 54.7 KB 57.4 KB +2.7 KB
docs/user-guide/layouts.md 85.9 KB 88.2 KB +2.3 KB
crates/map/src/layout.rs 32.5 KB 34.1 KB +1.6 KB
crates/engine/src/project_capabilities.rs 199.8 KB 201.2 KB +1.4 KB
crates/engine/src/cmd/layout/export.rs 26.4 KB 27.5 KB +1.1 KB
crates/data/src/raster/mod.rs 156.8 KB 157.9 KB +1.1 KB
crates/engine/src/cmd/report.rs 77.5 KB 78.6 KB +1.0 KB
schema/fixtures/layout_profile.rgis 0 B 1.0 KB +1.0 KB
crates/engine/src/cmd/layout/inputs.rs 14.6 KB 15.5 KB +1.0 KB
crates/ui-egui/src/layoutview.rs 37.2 KB 38.1 KB +0.9 KB
crates/map/src/layout/elements.rs 47.1 KB 47.9 KB +0.8 KB
crates/ui-egui/src/icons.rs 63.8 KB 64.6 KB +0.8 KB
crates/engine/src/cmd/layout/update.rs 41.8 KB 42.4 KB +0.6 KB
crates/analysis/src/rasterops.rs 192.3 KB 191.8 KB −0.6 KB

The table lists the 20 largest changes from stats.json. The other ten files changed by less.

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3256/
Web app https://preview.rustgis.app/pr-3256/app/
Commit 9b56f3c

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@elpidioassinaturas

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3277: this part is now split into six PRs of about 400 lines each (2a to 2f), opened one at a time, so each gets a full review. The two open review threads here are carried to the part they belong to.

m-hollis-1 pushed a commit to m-hollis-1/rustgis that referenced this pull request Nov 29, 2026
…#2863 part 2c) (opengeos#3310)

* feat(layout): what keeps a profile from being drawn is said (opengeos#2863 part 2c)

A profile that can't be drawn says why, once, with the profile named: a
tilted frame or one on the globe, a section line running the other way
or one its frame lacks or doesn't draw, a layer that isn't a raster of
the frame's map, a band it lacks, a raster read in place (whose overview
changes with the scale), no pixels read, no data along the whole line.
One read at 10,000 samples along a line crossing more cells says so too.
The layout view, PNG, PDF and SVG exports and reports say it, for a map
series' PDF on how many pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(layout): a profile drawn with gaps says how many samples have no value

A line that runs off its raster or over no data draws a broken curve;
the review of opengeos#3256 (thread r4728204609) asked that it be said. A
ProfileNote now carries a drawn profile's samples without a value, and
profiles_notice says those profiles in one notice, with how many of all.
The test was written first and failed.

Part of opengeos#2863

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(layout): a report says a profile it doesn't draw, its layout named

Part of opengeos#2863

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(layout): a thinned or gapped profile says on how many pages

Review round 1 of opengeos#3310. Over several pages, the thinned and gaps
notices dropped the pages a profile is on, which the not-drawn notice
gives; they now keep the count and say "on N of M pages". On one page
they are unchanged. The test was written first and failed. Also the two
wording points on the notice's doc and the layout view's comment.

Part of opengeos#2863

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: elpidioassinaturas <elpidiofilho@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants