Skip to content

refactor(map): selection and view-distance boxes converted from the dataset's own coordinates - #2462

Merged
pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:feat/crs-hits
Nov 19, 2026
Merged

pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:feat/crs-hits

Conversation

@pick2510

@pick2510 pick2510 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2032 (C1b): selection and view-distance checks convert between a layer's own coordinates and longitude/latitude, not read its geometry as longitude/latitude. Storage stays longitude/latitude (Dataset::coord_crs() returns it for every dataset), so nothing a user sees changes; this follows C1a (#2454) as groundwork for layers that keep their own coordinates (C2).

What it changes

  • Dataset::extent_from_lonlat(&Extent) (new): a longitude/latitude box in the dataset's own coordinates, through Crs::to. It is the reverse of extent_to_lonlat (refactor(map): layer extents converted from the dataset's own coordinates #2454). A query box is converted once per layer, not once per feature. Between longitude/latitude it is the box itself. A box partly outside what the layer's system holds gives the part that converts. A streamed source's extent_from_lonlat refuses such a box instead; which suits layers that keep their own coordinates is for C2.
  • Boxes asked of a layer, converted to its own coordinates before comparing with its features' boxes:
    • rectangle selection's check in curved projections (select.byRect);
    • the workspace's summary of the features in view and its snapshot of the features in an extent;
    • the geoprocessing environment's extent filter on a tool's input.
  • The place of a text graphic the map view hit-tests and drags (text_shown), converted from the layer's own coordinates.
  • Distances measured in longitude/latitude, from geometry converted there first:
    • the view clipping distance: render's within_view_distance, upright markers, and the hit-test of graphics text in the map view. Each converts with one conversion per layer.
    • radius selection's measuring (network::within_report, and within and within_counted with it). It uses the geometry as it is while the conversion is the identity, so no copy is made today.

Already in map units, unchanged

Map::hit, hits_at and hits_in (identify, select at a point, by rectangle), selection by polygon and snapping test the projected geometry. Since #2448 that geometry is drawn from the layer's own system.

Left for later

  • Snapping while moving a vertex (snap_vertex::consider) projects the source geometry with the map's projection, as longitude/latitude: C1c, with editing.
  • Editing: the selected-vertex overlay, vertexedit.rs, design.rs and sketch.rs read vertices as longitude/latitude, as does the phone app's editing (ui-touch edit.rs). Moving a text graphic writes longitude/latitude: C1c.
  • Analysis: select by location, IDW label points, the geometry calculator: C1d.
  • A STAC search by the selection (stac_area.rs) sends the selected geometries as a longitude/latitude area, and the globe draws stored geometry as longitude/latitude: both still to convert (C1e and drawing).
  • Radius selection's notice says "missing or infinite coordinates". Once a place that doesn't convert counts there, it needs other words: C2.
  • A conversion that fails gives an empty box, or reaches no feature, with no notice. This can't happen while every dataset is in longitude/latitude; it needs a notice before C2, as coord_crs says.

Surfaces

No user-visible change on any surface (desktop, web, phone, CLI, Python, Assistant/MCP, ribbon, undo): no command, parameter, setting or saved field is added, and every dataset is in longitude/latitude, whose conversions give the same boxes and places.

Tests

  • every_dataset_is_held_in_lonlat (data) also checks that a longitude/latitude box asked of a dataset is the same box, and an empty one stays empty.
  • a_box_partly_outside_its_target_keeps_the_part_that_converts (data): what extent_from_lonlat will do for a layer in its own system. A box with a corner UTM 32N can't bring back gives the box of the rest; a box wholly outside gives an empty one. The other non-identity branches (within_report's conversion, the view-distance and text-graphic conversions) can't run while every dataset is in longitude/latitude; C2 brings their tests.
  • Existing selection (rectangle, polygon, radius, polar radius), identify, workspace, geoprocessing environment and view-distance tests pass unchanged.

cargo xtask ci-equivalent run: fmt, clippy, tests, layers, schema, notices and the wasm build pass; the only test failures are three that fail on this machine on main too (damaged_shapefiles_are_errors_or_skips_not_panics, reads_what_gdal_writes_when_gdal_is_installed, a_streamed_shapefile_is_framed_by_its_records).

Summary by CodeRabbit

  • Bug Fixes
    • Improved map-based feature selection and filtering across datasets that use different coordinate systems.
    • Corrected visibility, distance clipping, and label hit detection so map extents and feature positions are compared consistently.
    • Extent conversions now preserve the portion that can be represented in the target coordinate system; extents that cannot be converted remain empty.

…ataset's own coordinates

Part of opengeos#2032 (C1b). Dataset::extent_from_lonlat converts a query box to a dataset's own coordinates; rectangle selection, workspace summaries and snapshots, the geoprocessing extent filter, the view clipping distance and radius selection convert explicitly instead of reading geometry as longitude/latitude. Every dataset is still in longitude/latitude, so nothing changes.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Spatial checks now convert extents and points between dataset coordinates and longitude/latitude. The changes cover network reports, layer filtering, distance clipping, and map text hit-testing. Dataset also adds a method to convert longitude/latitude extents into dataset coordinates.

Changes: Spatial coordinate conversion

Layer / File(s) Summary
Dataset extent conversion and tests
crates/data/src/lib.rs, crates/data/src/raster/reproject.rs
Dataset adds extent_from_lonlat. Tests cover identity conversion, empty extents, and extents with convertible or non-convertible portions.
Coordinate-aware network reports
crates/analysis/src/network.rs
within_report returns an empty report if longitude/latitude conversion fails. Otherwise, it measures geometries directly for identity conversion or converts them before measuring.
Layer extent filtering
crates/engine/src/cmd/gp.rs, crates/engine/src/cmd/select.rs, crates/engine/src/cmd/workspace.rs
Environment queries, rectangle selection, infographic filtering, and snapshots convert the requested extent into each layer’s coordinates before checking intersections.
Rendering and map text checks
crates/render/src/lib.rs, crates/ui-egui/src/mapview.rs
Distance clipping converts feature bounds to longitude/latitude. Map text clipping and hit-testing convert geometry extents or label points before applying spatial checks.

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

Change: Refactor

Possibly related issues

  • opengeos/RustGIS issue 2008: The issue concerns empty-geometry handling in text_graphic_at; this PR also changes that hit-testing path, but the summaries do not establish that it resolves the empty-geometry case.
  • opengeos/RustGIS issue 2032: The issue tracks explicit coordinate conversion at longitude/latitude boundaries. This PR adds that conversion to several query, filtering, rendering, and hit-testing paths.

Possibly related PRs

  • opengeos/RustGIS#2454: Adds conversion of dataset extents to longitude/latitude, which complements this PR’s conversion of longitude/latitude extents into dataset coordinates.

Suggested reviewers: giswqs, flight1973

Merge Risk: Minimal · up to ae7dc

This change prepares spatial selection and distance checks for datasets with their own coordinate systems. Every dataset is currently held in longitude/latitude, so users should see no change in behavior. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: selection and view-distance checks now convert boxes and geometry from the dataset's own coordinates rather than treating them as longitude/latitude. The title follows…
Description check Passed The description follows the template. It has a Summary-equivalent section that explains the change, the reason for it, and the scope (C1b, groundwork for C2). It describes testing, including new and u…
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.
Full details: Title check

Explanation

The title names the main change: selection and view-distance checks now convert boxes and geometry from the dataset's own coordinates rather than treating them as longitude/latitude. The title follows the conventional type(scope) form and matches the changeset, which adds Dataset::extent_from_lonlat and applies it across select, workspace, geoprocessing, render, and map view paths.

Full details: Description check

Explanation

The description follows the template. It has a Summary-equivalent section that explains the change, the reason for it, and the scope (C1b, groundwork for C2). It describes testing, including new and updated tests and a cargo xtask ci-equivalent run with three pre-existing failures noted. The UI evidence section states 'No visible UI change.', which the template allows when there is no visible change. The Related issue section references Part of #2032 and follows the template's 'Part of' form. The description is thorough and covers the required information.

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 maps the bounds with care
From native grids to lon-lat air
The features meet in matching space
And labels find their screen-place
The rabbit hops through fields anew

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: 1a7b89aa-7390-4181-b4c0-e2e92aa34e2c
Commits

Reviewing files that changed from the base of the PR and between ba1b89e and ae7dce2.

Files selected for processing: 8

  • crates/analysis/src/network.rs
  • crates/data/src/lib.rs
  • crates/data/src/raster/reproject.rs
  • crates/engine/src/cmd/gp.rs
  • crates/engine/src/cmd/select.rs
  • crates/engine/src/cmd/workspace.rs
  • crates/render/src/lib.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; 5 remain after this review.

Comment thread crates/data/src/lib.rs
pub fn extent_from_lonlat(&self, e: &Extent) -> Extent {
match raster::Crs::LonLat.to(self.coord_crs()) {
Ok(to) => to.extent(e),
Err(_) => Extent::EMPTY,

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.

AGENTS.md (Never silent), confidence medium. This Err arm returns an empty box with no notice, and the same silent empty result shows up in within_report (network.rs, returns WithinReport::default()), in text_graphic_at/text_shown (mapview.rs, ? skips the layer), and in the view-distance and upright-marker paths (render). A failed conversion of a query box therefore selects fewer features (or none) without a notice. This can't be reached while coord_crs is always longitude/latitude, and the PR body already defers it, but the rule says existing silent losses are bugs and new paths shouldn't add one. Suggest either a Session::notify-style count for the case, or a test or doc that pins it as unreachable until C2.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Verdict: The change is sound today. Every dataset is held in longitude/latitude, so each new conversion is the identity and no existing behaviour changes. The findings below concern the non-identity branches that C2 will be the first to run.

Bugs

  • None found. I checked the identity short-circuits, the Reprojection::extent sampling, the upright_markers_with and within_view_distance empty-box handling, the snapshot and infographic_of loop structure, and the Dataset::extent_from_lonlat direction (LonLat → own system). All are correct.

Security

  • None found.

Performance

  • Latent, confidence low-medium. within_view_distance and upright_markers_with call Reprojection::extent per feature. For a non-identity layer that is 17×17 = 289 transforms per feature, every frame, once C2 lands. The identity case returns at once, so there is no cost today.

Quality

  • Silent empty results, confidence medium. New paths return empty or skip without a notice when a conversion fails: Dataset::extent_from_lonlat (posted inline at crates/data/src/lib.rs:812), within_report, text_graphic_at/text_shown, and the render view-distance paths. A failed query-box conversion would select fewer features silently. This is unreachable today, and the PR body defers it, so it is flagged rather than blocking.
  • Test coverage, confidence low. None of the non-identity branches (within_report's conversion, the view-distance conversions, text_shown's point conversion, the box conversion at each call site) is exercised. The PR states this, and it is acceptable for now.

AGENTS.md

  • Never silent: see the Quality finding above; it is the only rule touched.
  • The other rules hold: no unwrap/expect, no lines over 140 columns, the reproject tests are in place, and the PR states which surfaces are unaffected.

Prior reviews

  • No prior threads exist, so nothing was left alone.

Change size

Compared: the whole PR against main (merge base 82526c3 to PR head ae7dce2).

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 1.49 MB
Size after 1.49 MB
Total size change +4.7 KB
Path Before After Change
crates/data/src/raster/reproject.rs 10.9 KB 12.4 KB +1.5 KB
crates/data/src/lib.rs 45.3 KB 46.1 KB +868 B
crates/render/src/lib.rs 688.6 KB 689.3 KB +736 B
crates/analysis/src/network.rs 82.1 KB 82.8 KB +626 B
crates/ui-egui/src/mapview.rs 321.8 KB 322.3 KB +509 B
crates/engine/src/cmd/workspace.rs 47.2 KB 47.5 KB +302 B
crates/engine/src/cmd/select.rs 39.6 KB 39.7 KB +155 B
crates/engine/src/cmd/gp.rs 285.0 KB 285.1 KB +137 B

@pick2510
pick2510 enabled auto-merge November 19, 2026 14:40
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2462/
Web app https://preview.rustgis.app/pr-2462/app/
Commit ae7dce2

GitHub Pages takes a minute or two to publish a new commit.

@pick2510
pick2510 added this pull request to the merge queue Nov 19, 2026
Merged via the queue into opengeos:main with commit cce0bc2 Nov 19, 2026
24 checks passed
@pick2510
pick2510 deleted the feat/crs-hits branch November 19, 2026 15:21
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.

1 participant