Skip to content

perf(engine): walk Project Crs fields directly for crs-wkt (#2909) - #3058

Merged
Mavrick-F merged 2 commits into
opengeos:mainfrom
ninhhaidang:fix/2909-crs-wkt-walk
Nov 28, 2026
Merged

Mavrick-F merged 2 commits into
opengeos:mainfrom
ninhhaidang:fix/2909-crs-wkt-walk

Conversation

@ninhhaidang

@ninhhaidang ninhhaidang commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add Crs::needs_wkt(self) in crates/data/src/raster/crs.rs to check whether a Crs::Custom definition requires crs-wkt without serializing, and update saves_wkt's doc comment to reflect its role as a test serialization oracle.
  • Add exhaustively destructured needs_wkt(&self) methods on Dataset (crates/data/src/lib.rs), SourceLayer (crates/map/src/source.rs), Layer, and Map (crates/map/src/lib.rs), preserving the !windowed rule for Dataset::held_in.
  • Replace saves_wkt(&Payload(self)) (and saves_wkt(map) / saves_wkt(layer) in map_file_bytes / layer_file_bytes) in crates/engine/src/project_capabilities.rs with direct O(layers + tables + workspaces + offline_areas) exhaustive field walks (project_needs_wkt, Map::needs_wkt, Layer::needs_wkt, SourceLayer::needs_wkt, Dataset::needs_wkt).
  • Memory & serialization impact: eliminates the redundant full-project serialization to std::io::sink(), holding zero extra copies of layer or raster data during Project::serialize, project.save, project.saveAs, project.package, autosave recovery, offline.package, and peer_text.

Surfaces reached

  • Desktop, browser, CLI, Python, mobile (ui-touch), Assistant/MCP, plugins: all use rustgis-engine's Project::required_capabilities, map_file_bytes, and layer_file_bytes through Project / map / layer serialization. No UI/ribbon/shortcut surface is added or changed.

Testing

  • cargo test -p rustgis-data --lib raster::crs::tests::crs_needs_wkt_matches_saves_wkt — passed (1 passed, 0 failed)
  • cargo test -p rustgis-engine --lib project::capabilities::tests — passed (41 passed, 0 failed, including crs_wkt_direct_walk_matches_saves_wkt_across_all_fields)
  • cargo clippy -p rustgis-data -p rustgis-map -p rustgis-engine --all-targets -- -D warnings — passed
  • cargo xtask test-hygiene, cargo xtask layers, cargo xtask rows — passed
  • RUSTFLAGS='-D warnings' cargo check --locked --target wasm32-unknown-unknown -p rustgis-web — passed
  • cargo fmt --check — passed

UI evidence

No visible UI change.

Related issue

Fixes #2909

Summary by CodeRabbit

  • Bug Fixes
    • Project and map exports now more reliably preserve coordinate reference information for custom and selected WKT-based coordinate systems.
    • CRS checks cover project settings, workspaces, datasets, maps, and map layers, helping maintain consistent spatial placement in saved files.
    • Dataset CRS information is also checked when data is not windowed, reducing the risk of losing placement details during export.
    • Coordinate reference information is included based on whether the selected CRS requires WKT serialization.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 01:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds direct checks for whether CRS data requires WKT. Project, map, and layer capability checks use these methods instead of serializing payloads to determine whether to include crs-wkt. Tests compare the checks and generated headers with saves_wkt.

Changes: CRS WKT Capability Detection

Layer / File(s) Summary
CRS WKT requirement
crates/data/src/raster/crs.rs
Adds Crs::needs_wkt and tests it against saves_wkt for standard, EPSG, invalid custom, PROJ-defined, and WKT-/ESRI-backed CRS values.
Dataset, source, map, and layer checks
crates/data/src/lib.rs, crates/map/src/source.rs, crates/map/src/lib.rs
Adds needs_wkt checks for datasets, source layers, layers, and maps. Dataset checks include held_in only when the dataset is not windowed.
Project and file capability checks
crates/engine/src/project_capabilities.rs
Adds a direct project CRS check and uses map and layer checks when writing capability headers. Tests cover project, GP environment, workspace, table, map, offline-area, and shapefile CRS fields, including the windowed dataset case.

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

Change: Refactor · Severity of issue fixed: Medium

Possibly related issues

  • opengeos/RustGIS#1853: Defines crs-wkt as the capability for custom systems whose placement is described only by WKT.
  • opengeos/RustGIS#2922: References the double-serialization issue addressed by this change.

Suggested reviewers: pick2510

Merge Risk: Minimal · up to 3d599

This change replaces repeated full-project serialization with a direct check of whether a custom CRS needs crs-wkt. The reported tests show it matches the old behavior. No behavior change or merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the conventional commit form and names the main change: the engine now walks Project CRS fields directly to decide crs-wkt, instead of serializing the project to a sink. It also names t…
Linked Issues check Passed Issue #2909 asks for two coding changes: (1) replace the saves_wkt(&Payload(self)) pass in Project::required_capabilities() with a direct walk over Crs fields that calls crs.needs_wkt(); (2) add a uni…
Out of Scope Changes check Passed The added changes apply the same direct crs-wkt check to the save paths the issue names. Project::required_capabilities uses project_needs_wkt. map_file_bytes and layer_file_bytes use Map::needs_wkt a…
Description check Passed The description covers the Summary, Testing, and Related issue sections. It lists the new methods, the replaced serialization checks, and the test commands with results. It also links the issue (Fixes…
Full details: Title check

Explanation

The title uses the conventional commit form and names the main change: the engine now walks Project CRS fields directly to decide crs-wkt, instead of serializing the project to a sink. It also names the affected area (engine) and the issue number. The title is specific and matches the changeset summary and objectives.

Full details: Linked Issues check

Explanation

Issue #2909 asks for two coding changes: (1) replace the saves_wkt(&Payload(self)) pass in Project::required_capabilities() with a direct walk over Crs fields that calls crs.needs_wkt(); (2) add a unit test showing the direct walk agrees with saves_wkt across the CRS-bearing fields of a populated project. At head, crates/engine/src/project_capabilities.rs ends required_capabilities with if project_needs_wkt(self) { required.push("crs-wkt") } and no longer serializes to std::io::sink() for this check. crates/data/src/raster/crs.rs keeps saves_wkt only as a test oracle beside Crs::needs_wkt. The change summary adds Crs::needs_wkt (crates/data/src/raster/crs.rs), Dataset::needs_wkt (crates/data/src/lib.rs), Layer/Map::needs_wkt (crates/map/src/lib.rs) and SourceLayer::needs_wkt (crates/map/src/source.rs). The PR reports crs_needs_wkt_matches_saves_wkt (1 passed) and crs_wkt_direct_walk_matches_saves_wkt_across_all_fields (within 41 passed). The walk covers project CRS, workspaces, tables, maps, and offline-area data, which extends the issue's layers/tables/layouts list. The project_needs_wkt body and the test bodies were not readable at head because of truncation, so this verdict rests on the readable call site, the change summary, and the reported test results.

Full details: Out of Scope Changes check

Explanation

The added changes apply the same direct crs-wkt check to the save paths the issue names. Project::required_capabilities uses project_needs_wkt. map_file_bytes and layer_file_bytes use Map::needs_wkt and Layer::needs_wkt in place of saves_wkt on their payloads. Dataset::needs_wkt keeps the !ds.windowed rule for Dataset::held_in. Every change is a needs_wkt predicate, a call-site swap, or a test. No UI, command, or feature change appears in the reviewed evidence, and the PR reports no visible UI change. Some hunks were not readable, so this check rests on the change summary and the readable head code.

Full details: Description check

Explanation

The description covers the Summary, Testing, and Related issue sections. It lists the new methods, the replaced serialization checks, and the test commands with results. It also links the issue (Fixes #2909). The UI evidence section is present and states that there is no visible UI change, which matches the template's allowance. The description is detailed and specific. Minor gaps: the 'Surfaces reached' and 'Memory & serialization impact' bullets add context beyond the template but do not conflict with it.

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 checks each CRS in sight,
To see if WKT must take flight.
Projects, maps, and layers agree,
No sink-bound second pass to see.
Tests compare each flag with care,
Then hop along without a stare.

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: 8d3130fe-93cb-4697-9fa5-6efb7845072e
Commits

Reviewing files that changed from the base of the PR and between e0e4d1b and 3d599fe.

Files selected for processing: 3

  • crates/data/src/raster/crs.rs
  • crates/engine/src/project_capabilities.rs
  • crates/map/src/lib.rs

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: 2 files, +179/−9 lines. The PR replaces the saves_wkt(&Payload(self)) full-project serialization with direct field walks (project_needs_wkt, map_needs_wkt, layer_needs_wkt, dataset_needs_wkt) and adds Crs::needs_wkt. I could not run the tests or clippy here (no shell), so everything below comes from reading the code.

Bugs

  • None found. I checked every serialized path that can carry a Crs against the walk: coordinate_system, gp_env.projected, workspaces[].crs, tables[].dataset, maps[].layers[].dataset (crs, and held_in unless windowed), layers[].source.shapefile_crs, and offline_areas[].data. Dataset::shown_in is #[serde(skip)]. Synced, RasterLayer (its crs is a String), Map, AreaConflict and Projector hold no serialized Crs. The windowed rule matches Dataset::serialize. Confidence: high (about 85%).

Security

  • None found.

Performance

  • None. The walk is O(layers + tables + workspaces + offline areas) and no longer serializes the project. The old path only ran at all when the custom table had a WKT-needing system, so the gain is smaller than the description suggests, but it is not a regression.

Quality

  • project_capabilities.rs:1043, posted inline (Category: quality). project_needs_wkt is a hand-kept list of Crs-bearing fields. A Crs in a field added later would now be silently missed, where the old full serialization caught it. The test only covers fields it lists. Suggested fix: destructure Project exhaustively, as the tests near project.rs:2892 do, so a new field becomes a compile error. Same for the three helpers below it. This is a latent risk, not a current miss. Confidence: medium-high.
  • Nits, not posted inline: in the new test, let mut cases and cases.drain(..) could be a plain for (name, apply) in cases. The test also repeats the Payload helper from project_capabilities.rs; a shared helper would avoid the copy.

AGENTS.md

  • None found. The PR changes no saved structure, so cargo xtask schema and fixtures don't apply. It adds no commands, limits, or new background work. Its crs.rs test is in the crate's test module, and the test-hygiene patterns (no identical assert_eq! sides, no timer waits) look satisfied.

Prior reviews: none on this PR, so I left no earlier concerns alone.

Change size

Compared: the whole PR against main (merge base b985666 to PR head 98a3f11).

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 354.3 KB
Size after 363.1 KB
Total size change +8.8 KB
Path Before After Change
crates/engine/src/project_capabilities.rs 174.4 KB 181.7 KB +7.3 KB
crates/data/src/raster/crs.rs 179.9 KB 181.3 KB +1.5 KB

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

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

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security problems, or AGENTS.md violations. The review is static only: I had no shell, so I did not compile or run the tests the PR lists.

Bugs: None found.

  • I checked the new walk against the serializer for each field it ignores with _. Map.graticule_crs is a String. Projector.crs is not serialized. Layer.projected_crs is #[serde(skip)]. RasterLayer.crs is a String. Layout, Map.basemap, Map.tiles, Map.groups, Map.bookmarks and the Project collections (jobs, models, shared, data_stores, notebooks) hold no serialized Crs. Confidence: high.
  • Dataset::needs_wkt matches Dataset::serialize, which writes crs when set and held_in only when !windowed and not LonLat. Confidence: high.
  • Crs::needs_wkt matches From<Crs> for SavedCrs, which is the only place WKT_SAVED is set. Confidence: high.
  • The change also removes a recursion. The old required_capabilities → saves_wkt(Payload) → Project::serialize → required_capabilities cycle would overflow the stack whenever a WKT-needing system was registered. The walk has no such cycle. Confidence: high.
  • Every production caller of saves_wkt is replaced (map_file_bytes, layer_file_bytes, required_capabilities). The remaining callers are tests.
  • Prior thread: the earlier concern that the walk could silently miss a new Crs field is resolved. The author switched to exhaustive destructuring at e0e4d1b, which I confirmed. I did not re-raise it.

Security: None found. There is no new input parsing and no unwrap, expect, or panic in non-test code.

Performance: Low, confidence medium.

  • The old saves_wkt returned early when no registered system needed WKT. The new walk always runs. It is O(fields) with no allocation for non-custom systems, and it runs once per save, so the cost is small. I did not post this inline.

Quality: Nits, grouped here rather than posted inline.

  • The PR description names helpers dataset_needs_wkt, layer_needs_wkt and map_needs_wkt. The code uses methods Dataset::needs_wkt, Layer::needs_wkt, Map::needs_wkt and SourceLayer::needs_wkt, with project_needs_wkt as a free function. Please update the description.
  • After this change saves_wkt is only a test oracle, but its doc comment still describes production use. Consider moving it under #[cfg(test)] or updating the doc.
  • The test helper payload_saves_wkt duplicates the Payload wrapper pattern. It is harmless.

AGENTS.md: No violations found. I checked these rules:

  • Never crash: no new unwrap, expect or panic.
  • Schema: the saved content is unchanged, so schema/project.schema.json needs no update.
  • Layering and wasm: no new dependencies, and no desktop-only code added.
  • Size for real data: the change traverses fields and does not store or copy layer data, so no memory multiple is required.
  • Reach every surface: the PR body states this.

Prior concerns: 1 thread already on this PR was left alone, because it is resolved and the author's reply addresses it.

Twins checked: The diff touches no read route, overlay tool, layer.add*/project.open* command, or wasm32 branch. I checked both map and layer file writers, and the saves_wkt callers.

Change size

Compared with the base branch: the whole PR against main (merge base b985666 to PR head e0e4d1b).

Measure Value
Files changed 5 (added 0, modified 5, removed 0, renamed 0)
Size before 840.5 KB
Size after 855.3 KB
Total size change +14.8 KB
File Before After Change
crates/engine/src/project_capabilities.rs 174.4 KB 182.4 KB +8.0 KB
crates/map/src/lib.rs 256.2 KB 259.1 KB +3.0 KB
crates/map/src/source.rs 131.4 KB 133.0 KB +1.7 KB
crates/data/src/raster/crs.rs 179.9 KB 181.3 KB +1.5 KB
crates/data/src/lib.rs 98.7 KB 99.3 KB +0.7 KB

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
@ninhhaidang
ninhhaidang force-pushed the fix/2909-crs-wkt-walk branch from e0e4d1b to 3d599fe Compare November 27, 2026 14:36
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Overall the change is sound. The hand-written walk matches the serialization for every Crs-bearing field I traced, and all three writers (project, map, layer) now go through the new helpers. I found no bugs, security issues, or performance regressions. One quality point is posted inline.

Bugs

  • None found. I checked the walk against the serialized fields: coordinate_system, gp_env.projected, workspaces[].crs, tables[].dataset (including TableFile), maps[].layers[].dataset, source.shapefile_crs, offline_areas[].data, and the !windowed rule for held_in. Skipped fields (projected_crs, lonlat, unplaced, shown_in, SourceLayer.projection) hold no serialized Crs. ProjectedCells is Copy, so projected.is_some_and(...) compiles. Confidence: high.

Security

  • None.

Performance

  • None. The change removes a full project serialization to io::sink(). Crs::needs_wkt short-circuits on non-custom systems, so it takes no lock for them. Confidence: high.

Quality

  • Inline comment posted on crates/engine/src/project_capabilities.rs:1044. This follows up the resolved thread on the same walk. The author's reply says a new Crs field is a compile error, but that holds only for fields destructured directly. Containers such as layouts, presentations, models, Layer.raster, and SourceLayer.gdal/postgis are matched with _, so a Crs added inside their types would be missed silently. None holds a Crs today. Confidence: medium. Category: quality.
  • Nit: the test name crs_wkt_direct_walk_matches_saves_wkt_across_all_fields overclaims. The fixture populates only maps, tables, workspaces, offline areas, and the project CRS.
  • Nit: crs_needs_wkt_matches_saves_wkt in crs.rs and the project-level test overlap on the same Crs cases.

AGENTS.md

  • No rule is broken. The PR body states that it adds no copy of layer data, which fits the "Size for real data" rule. cargo xtask rows and the test suite are reported as passing in the PR body, not reproduced here.

Prior reviews

  • 1 earlier thread (the exhaustive-walk concern) is resolved. I left it alone except for the nested-container gap above, which the author's reply does not address.

Change size

Compared with the base branch (merge base 67800ac to PR head 3d599fe), whole PR.

Measure Value
Files changed 5 (0 added, 5 modified, 0 removed, 0 renamed)
Size before 846.3 KB
Size after 861.2 KB
Total size change +14.9 KB
Path Before After Change
crates/engine/src/project_capabilities.rs 175.4 KB 183.4 KB +8.0 KB
crates/map/src/lib.rs 261.0 KB 264.0 KB +3.0 KB
crates/map/src/source.rs 131.4 KB 133.0 KB +1.7 KB
crates/data/src/raster/crs.rs 179.9 KB 181.4 KB +1.5 KB
crates/data/src/lib.rs 98.7 KB 99.3 KB +0.7 KB

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 27, 2026
Merged via the queue into opengeos:main with commit 04ef9e0 Nov 28, 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.

Project::serialize double-serializes the full project to io::sink() for crs-wkt detection

3 participants