Skip to content

feat(annotation): draw and classify points and polygons in Annotate - #3597

Merged
Mavrick-F merged 2 commits into
opengeos:mainfrom
robmarkcole:feat/annotation-points-polygons
Dec 2, 2026
Merged

Mavrick-F merged 2 commits into
opengeos:mainfrom
robmarkcole:feat/annotation-points-polygons

Conversation

@robmarkcole

@robmarkcole robmarkcole commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Analyze → Annotate now offers Point for editable point layers and Polygon, Rotated Box and Circle for editable polygon layers. It reuses the existing Edit gestures. Click to place a point, or click polygon vertices and double-click to finish.

A point takes the active class on click. A polygon takes it at the first vertex, so changing the default mid-sketch affects the next feature. Creating the feature and assigning its class is one Undo step. Escape cancels a sketch, and switching target layers discards unfinished geometry. Right-clicking a point in Select / Edit lets you change its class while keeping the drawing default.

Desktop and browser users reach the shared pane through Analyze → Annotate, View → Windows or Command Search. The existing Edit tools and shortcuts still work independently. The phone interface has no dedicated Annotate control. CLI, Python, Assistant/MCP and plugin callers can already create points and polygons with ordinary feature attributes through the existing editing commands. This pane change adds no command, parameter or tool description on those surfaces. Export uses ordinary GeoJSON geometries and class properties. Circles and rotated boxes reopen as polygons. The user guide covers the new tools and explains which shapes use the construction grid.

Testing

Review follow-up at 341763e2. All 42 focused annotation tests and the strict WebAssembly build passed. The full local cargo xtask ci passed on macOS with bundled fonts for the 27 render extent tests, system fonts for the other renderer tests, and the UI smoke tests run serially. All 1,999 UI unit tests passed. The notes below describe the initial commit.

  • All 41 focused annotation tests passed on macOS. The new regressions cover point creation and right-click reassignment, Undo/Redo, GeoJSON round-tripping, polygon class capture, target switching and removal of the class field during a sketch. All 1,998 UI unit tests passed.
  • Workspace Clippy, formatting, test hygiene, dependency layering, attribution, row-access and schema checks passed. The warnings-as-errors WebAssembly build passed using LLVM Clang for Zstandard. The packaged web app passed the offline Chrome smoke test.
  • The default macOS cargo xtask ci run stopped on five layout extent assertions with system fonts. All 27 extent tests passed with RUSTGIS_BUILTIN_FONTS=1. Applying that setting to the entire renderer caused six other failures. Running the extent tests with bundled fonts and the remaining renderer tests with system fonts gave 1,288 passes and one ignored test.
  • In the remaining workspace tests, a catalog row-drag smoke test failed once in parallel. It passed in isolation and all 167 UI smoke tests passed together when run serially.

UI evidence

RustGIS rendered these screenshots on upstream b942defc and feature commit a86048e0.

Target Before After
Point layer Point layer before the change Classified observation points
Polygon layer Polygon layer before the change Completed polygon with its Wetland class

Related issue

Part of #1717. Follows #2664.

AI assistance. OpenAI Codex implemented the changes, wrote the regression tests, ran the checks, captured the screenshots, and drafted and submitted this PR at the contributor’s request.

Summary by CodeRabbit

  • New Features
    • Annotation editing now supports eligible point and polygon layers, with drawing tools available when editing is enabled and the layer is visible at the current scale.
    • Point and polygon sketches retain their selected class and attributes during creation; editing stops if the target or editing state changes.
    • Point features can be selected for annotation-class actions, and navigation clicks work across additional annotation tools.
  • Bug Fixes
    • Incompatible creation tools switch to Select when the annotation target changes.
  • Documentation
    • Updated the editing guide with drawing details and when annotation classes are applied.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The annotation pane now supports point and polygon targets and drawing tools. Point and polygon creation capture class context and apply validated attributes. Target eligibility, export checks, shape-conversion menus, and the editing guide also reflect the expanded behavior.

Changes: Annotation tools and sketch creation

Layer / File(s) Summary
Target eligibility and drawing tools
crates/ui-egui/src/annotation.rs, crates/ui-egui/src/annotation_classes.rs, crates/ui-egui/src/shapeconvert.rs, docs/user-guide/editing.md
Annotation target selection, class operations, and export checks now accept eligible point and polygon layers. The pane adds matching Point and Polygon tools, and point features open the annotation-class menu. The guide describes the tools and class-capture timing.
Class capture and feature creation
crates/ui-egui/src/annotation_classes.rs, crates/ui-egui/src/mapview.rs
MapView captures the target and class context for point creation and polygon sketches. It validates the context and captured fields before inserting features, and cancels stale sketches. Tests cover class assignment, geometry, undo/redo, export, and cancellation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant AnnotationPane
  participant MapView
  participant SketchClass
  participant TargetLayer
  AnnotationPane->>MapView: Point click or first polygon vertex
  MapView->>SketchClass: Capture target and class context
  SketchClass-->>MapView: Captured context
  MapView->>SketchClass: Validate context and obtain attributes
  SketchClass-->>MapView: Attributes or validation error
  MapView->>TargetLayer: Insert geometry with attributes
Loading

Possibly related issues

  • opengeos/RustGIS#1717: The issue proposes an annotation workflow with point, polygon, circle, and rotated-box tools and class support. This PR adds point and polygon drawing and class handling to that workflow.

Possibly related PRs

  • opengeos/RustGIS#2664: Adds class selection and assignment for circles and rotated boxes. This PR extends class capture and assignment to points and polygons.
  • opengeos/RustGIS#2290: Introduces the annotation pane and shape-conversion workflow that this PR extends.

Suggested reviewers: pick2510, giswqs

Merge Risk: Minimal · up to 34176

Annotate now draws and classifies points and polygons. The class is captured at the right moment and checked again before the feature is inserted. No concrete merge-blocking problem was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(annotation): draw and classify points and polygons in Annotate" names the main change. The changeset adds Point, Polygon, Rotated Box and Circle drawing to the Annotate pane, and captu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template well. It has a Summary that explains the feature, a Testing section with detailed commands and results, and a UI evidence section with before and after screenshots…
Full details: Title check

Explanation

The title "feat(annotation): draw and classify points and polygons in Annotate" names the main change. The changeset adds Point, Polygon, Rotated Box and Circle drawing to the Annotate pane, and captures annotation classes for points and polygons. The title is specific and matches the summary and objectives. The title uses a conventional commit prefix, which is acceptable.

Full details: Description check

Explanation

The description follows the template well. It has a Summary that explains the feature, a Testing section with detailed commands and results, and a UI evidence section with before and after screenshots in a table. The Related issue section says the PR is part of #1717 and follows #2664. Testing covers the review follow-up and the initial commit, so the record is detailed, though some of it is dense. Every required section is filled in with specific, relevant content.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

A rabbit taps a point in place,
Then draws a polygon with care.
A class is caught at sketch’s start,
Its fields travel with the art.
The rabbit hops; the shapes remain,
With undo close at paw again.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: de144ec7-102d-40ab-a836-6205cdef267d
Commits

Reviewing files that changed from the base of the PR and between a86048e and 341763e.

Files selected for processing: 3

  • crates/ui-egui/src/annotation.rs
  • crates/ui-egui/src/annotation_classes.rs
  • crates/ui-egui/src/mapview.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread crates/ui-egui/src/mapview.rs Resolved
Comment thread crates/ui-egui/src/annotation.rs Resolved
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I found no crash, data-loss or wrong-output bugs in the changed code. Two quality comments are inline. The rest are grouped below. I read the diff, the surrounding annotation, annotation_classes, mapview, shapeconvert and engine edit/project code. I could not build or run the tests here, so the test results are unverified.

Bugs

  • Low confidence (~30%): if the Annotate pane is opened while a polygon sketch is already in progress, add_vertex never captures a class, so the polygon is created without the class default and no notice is given. Reproducing it needs an ordinary polygon sketch started before the pane opens. Consider capturing the class at finish, or noticing the omission.

Security

  • None found.

Performance

  • None found. The class capture runs once per sketch or point click, and the per-frame cancel_stale_annotation is O(1).

Quality

  • Inline: the stale-sketch notice reads "target changed" when Enable editing is switched off mid-sketch (mapview.rs:3807). Confidence high.
  • Inline: loop binding enabled shadows the Enable editing flag in annotation.rs panel (annotation.rs:486). Confidence high.
  • Nit: insert_annotation assigns params["attributes"] by index (mapview.rs:3830). It is safe because params is always an object here, but as_object_mut() would match the crate's no-indexing style.
  • Nit: SketchClass::attributes re-validates every key on finish. Validating only the class field would be enough, but this is harmless.

AGENTS.md

  • Medium confidence: the PR description names desktop and browser, plus Undo and Escape. It does not say which other surfaces the change reaches (CLI, Python, phone via ui-touch, ribbon and shortcuts, Assistant/MCP tool descriptions, plugins), or why the rest don't apply. The rule asks for that statement in the pull request.
  • Checked and fine: no new commands or parameters, so the command snapshot is unchanged. No unwrap, expect or unsafe in non-test code. New strings use tl!. The cfg(test) import of GeometryType is correct. Layering is unchanged.

Twins checked

  • Overlay tools in analysis/tools.rs: not touched.
  • layer.add*, project.open*, project.import*: not touched. The engine's fits check refuses a point into a polygon layer and the reverse, so the annotation path can't write mismatched geometry silently.
  • tool.set validation (engine/src/cmd/project.rs:1151) already refuses Create Point and Create Polygon for the wrong layer kind.
  • shapeconvert::menu and annotation_classes::menu: point and polygon right-click menus both route correctly.
  • Wasm branches: annotation_classes::creating has its cfg pair, unchanged. The new code uses no std::time or platform APIs.

Prior reviews: none on this PR, so no concerns were skipped.

Change size

Compared: the whole PR against main (merge base b942def to PR head a86048e).

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 596.5 KB
Size after 607.0 KB
Total size change +10.9 KB
Path Before After Change
crates/ui-egui/src/mapview.rs 396.6 KB 404.1 KB +7.1 KB
crates/ui-egui/src/annotation.rs 73.7 KB 75.3 KB +1.6 KB
crates/ui-egui/src/annotation_classes.rs 30.1 KB 31.5 KB +1.4 KB
crates/ui-egui/src/shapeconvert.rs 38.5 KB 39.0 KB +0.5 KB
docs/user-guide/editing.md 57.2 KB 57.5 KB +0.3 KB

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 341763e from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

@robmarkcole

Copy link
Copy Markdown
Contributor Author

Addressed the review in 341763e. A polygon started in Edit keeps its normal template behavior if Annotate opens mid-sketch. Finishing it now explains how to apply the active class to the selected polygon. The new test exercises that handoff and disabling editing mid-sketch. Feature creation now constructs the command parameters directly. The final field check covers only the captured class field, or zero fields when no class was active.

The PR description now covers the desktop, browser, phone and command interfaces and records the local test settings. All 42 focused annotation tests, the full local quality gate and the strict WebAssembly build passed.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

Reviewed the whole diff (5 files), the two prior threads, and the code it calls into: edit.addFeature and fits in the engine, RustGisApp::run and command_failed, sync_after_session_change, and the sketch and stale-target paths in mapview.rs. I could not build or run the tests in this environment, so the findings below come from reading the code.

Bugs

  • None confirmed. I checked:
    • Stale class after a target switch, an editing toggle, or a project replacement. sync_after_session_change runs after every command, and SketchClass::attributes re-checks the target before writing.
    • A polygon sent to a point layer, or a point to a polygon layer, via the Edit ribbon. fits in cmd/edit.rs refuses it and command_failed notifies, so nothing is written silently.
    • Undo: creation with its class is one edit.addFeature step, and right-click reassignment is one edit.setValue step.
    • Confidence: medium-high.

Security

  • None. The diff adds no parsing, I/O, network use or secrets.

Performance

  • None. The per-frame cancel_stale_annotation check is a constant-time comparison.

Quality

  • mapview.rs:3748 (inline posted): a capture failure in add_vertex notifies on every click. create_point does the same. The sketch already has a once-per-sketch flag (sketch_full_said) for its own notice. Confidence: medium.
  • mapview.rs:3744: sketch_class is not reset when a new polygon sketch starts outside the Annotate pane. I found no path that leaves it stale, because cancel_sketch clears it and finish_sketch takes it. Resetting it at the start would keep that true locally. Confidence: low.
  • Test gaps: no test covers the refusal when a polygon tool is set on a point target, or Space-click with the create tools not adding a vertex. Confidence: medium.
  • insert_annotation: the "started in Edit" notice tells the user to assign a class even when the pane has no class field. Confidence: low-medium.

AGENTS.md

  • No violation found. Interface strings use tl!. The added non-test code has no unwrap, expect or indexing. No command was added or renamed, so the command snapshot is unaffected. Layering holds, since only ui-egui items change. The user guide is updated.
  • Prior threads: two earlier concerns were already raised (the editing-off notice wording, and shadowing of the enabled name). Both are answered and fixed in 341763e, so I did not raise them again. I left 2 earlier concerns alone.

Change size

Compared: the whole PR against main (merge base b942def to PR head 341763e).

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 596.1 KB
Size after 609.0 KB
Total size change +12.8 KB
Path Before After Change
crates/ui-egui/src/mapview.rs 396.6 KB 405.5 KB +8.9 KB
crates/ui-egui/src/annotation_classes.rs 30.1 KB 31.7 KB +1.6 KB
crates/ui-egui/src/annotation.rs 73.7 KB 75.3 KB +1.6 KB
crates/ui-egui/src/shapeconvert.rs 38.5 KB 39.0 KB +508 B
docs/user-guide/editing.md 57.2 KB 57.5 KB +286 B

@robmarkcole

Copy link
Copy Markdown
Contributor Author

Each rejected click is a separate drawing attempt. Capture returns before the first vertex is added, so a failed capture has no active sketch whose notice flag could be reused. The next click can succeed after the target or class is corrected. On a successful sketch, finish takes the captured class and cancel clears it.

For the release quality pass, I’m leaving the suggestion to group repeated notices, the defensive reset, and the two additional tests for incompatible geometry and Space-click. The Edit handoff wording also belongs in that pass: when no class field is configured, the polygon is still created correctly, but the hint should only mention class assignment when that action is available.

@Mavrick-F
Mavrick-F added this pull request to the merge queue Dec 2, 2026
Merged via the queue into opengeos:main with commit 85b150c Dec 2, 2026
30 checks passed
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