Skip to content

feat(crs): write GeoJSON, CSV, KML and GPX in longitude/latitude from the system a layer holds (#2032 C1e part 2) - #2510

Merged
pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:feat/crs-export-2
Nov 20, 2026
Merged

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

Conversation

@pick2510

@pick2510 pick2510 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2032 (C1e, part 2 of 2; part 1 was #2507).

The engine's own writers of longitude/latitude formats convert the layer to longitude/latitude at the writer (Dataset::in_lonlat, Dataset::geometry_to_lonlat) instead of assuming the layer already holds it. Behaviour-neutral: every dataset holds longitude/latitude today (coord_crs() is LonLat), so each conversion is the identity and borrows.

Reached:

  • Convert/export workflow formats (GeoJSON, CSV, KML, GPX, WKT CSV): the writers get the converted copy; the export notes still read the layer, which converts as it needs, so nothing is converted twice.
  • Packaged geoprocessing results (results/*.geojson).
  • OGC API Features collections and the web layer zip, and the web map page (styled_features, which now returns an error naming the feature instead of writing raw coordinates).
  • The plugin features call (with or without crs: the target conversion now starts from longitude/latitude).
  • Python layer_geojson (whole layer, read in place, selection).

Not touched, already converting: clipboard copy (C1c), embeddings (fresh longitude/latitude datasets), analysis tool inputs for GeoLibre and plugin tools (lonlat_inputs in gp.rs). Desktop, browser, phone and the Assistant reach these through the same commands; the CLI and MCP have no separate writer.

Left for C2 (not longitude/latitude formats, but they read raw coordinates as degrees): STL mesh, glTF scene, the mobile package's simplify tolerance.

Size: no extra copy today. Once a layer holds another system, in_lonlat makes one converted copy of the layer (≈1× the layer) for the duration of the write; the plugin and web-map paths convert feature by feature.

Rows: the touched loops now use the Features/RowRef accessors; xtask/row-uses.txt goes 839 → 833.

Tests: no new tests here. The hook that makes coord_crs() return another system is cfg(test) in rustgis-data only; command-path tests on layers held natively come with C2, as promised in #2469/#2466. Local CI: fmt, clippy, workspace tests (only the three known box-only failures: damaged shapefiles, GDAL FileGDB, streamed shapefile framing), schema, notices, wasm, cargo xtask rows.

Summary by CodeRabbit

  • Bug Fixes
    • GeoJSON exports, workflow downloads, and geoprocessing results now use longitude/latitude coordinates.
    • Selected and visible features in shared maps, web layers, and OGC responses are also converted to longitude/latitude.
    • Coordinate conversion failures now report the affected layer and feature where available.

… the system a layer holds (opengeos#2032 C1e part 2)

The engine's direct writers (Convert/export workflow formats, packaged gp results, OGC collection
and web layer zips, the plugin features call, the Python layer_geojson) convert the layer to
longitude/latitude at the writer instead of assuming its coordinates are. Behaviour-neutral:
every dataset holds longitude/latitude today.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Export and feature-response paths now convert dataset or feature geometries to longitude/latitude before serialization or response construction. Conversion errors propagate in these paths, and selected-feature and styled-feature errors identify the layer and feature.

Changes: Coordinate Conversion Paths

Layer / File(s) Summary
Python dataset and selected-feature exports
apps/rustgis-python/src/lib.rs
Streamed and full-layer GeoJSON exports convert datasets to longitude/latitude. Selected-feature exports convert each geometry and report the layer and feature when conversion fails.
Geoprocessing and workflow serialization
crates/engine/src/cmd/items.rs, crates/engine/src/cmd/workflows.rs
Geoprocessing GeoJSON and workflow serializers receive longitude/latitude datasets. Conversion errors propagate before serialization.
Plugin and sharing feature responses
crates/engine/src/cmd/plugins.rs, crates/engine/src/cmd/sharing.rs, xtask/row-uses.txt
Plugin feature rows, styled features, OGC collection items, and web-layer GeoJSON convert to longitude/latitude. The plugin response retains the layer CRS metadata. Web map generation propagates styled-feature errors. The tracked direct-row-use count changes from 839 to 833.

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

Change: Refactor

Possibly related issues

  • opengeos/RustGIS issue 2032: The issue describes export and save conversion from the layer CRS to longitude/latitude. This PR changes several export paths to perform that conversion.
  • opengeos/RustGIS issue 1934: The issue describes the host.features coordinate boundary. This PR converts plugin feature geometries to longitude/latitude, but does not add the requested optional CRS input.

Suggested reviewers: giswqs, mavrick-f

Merge Risk: Minimal · up to 72f71

The change makes export and feature-response writers convert to longitude/latitude before output, and behavior is unchanged while all layers already hold longitude/latitude. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: GeoJSON, CSV, KML and GPX writers now produce longitude/latitude by converting from the layer's coordinate system. This matches the raw summary, which covers workflows, pac…
Description check Passed The description follows the template sections (Summary, Testing, UI evidence, Related issue). Summary and Testing are detailed and explain the behaviour-neutral change, the reached writers, the size i…
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 change: GeoJSON, CSV, KML and GPX writers now produce longitude/latitude by converting from the layer's coordinate system. This matches the raw summary, which covers workflows, packaged results, OGC, web layers, plugin features, and Python layer_geojson. The title is long and includes an issue reference, but it is related to the main change.

Full details: Description check

Explanation

The description follows the template sections (Summary, Testing, UI evidence, Related issue). Summary and Testing are detailed and explain the behaviour-neutral change, the reached writers, the size impact, and the local CI run. The UI evidence section is filled with 'No visible UI change.', which matches the template's instruction for PRs without visible UI change. The Related issue section still contains the template placeholder text and does not name the issue in a Closes or Part of line, although the Summary mentions 'Part of #2032'.

Resolution

Optional: replace the placeholder comment under 'Related issue' with an explicit line such as 'Part of #2032'. The Summary already references it, so this is minor.

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 map coordinate,
And nudges each export toward the sun.
The features hop in longitude,
Then latitude joins the run.
The carrots rest; the outputs gleam,
While errors name the layer and feature.

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: a7abd118-b56d-4214-919b-45e28f817a48
Commits

Reviewing files that changed from the base of the PR and between e6f6e7b and 72f7177.

Files selected for processing: 6

  • apps/rustgis-python/src/lib.rs
  • crates/engine/src/cmd/items.rs
  • crates/engine/src/cmd/plugins.rs
  • crates/engine/src/cmd/sharing.rs
  • crates/engine/src/cmd/workflows.rs
  • xtask/row-uses.txt

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

// Every format here is longitude/latitude.
let target = ps(p, "path").unwrap_or(&ds.name);
let mut notes = rustgis_data::export_notes([(ds, ds.lonlat_extent())], target, rustgis_data::raster::Crs::LonLat);
notes.extend(rustgis_data::io::export_losses_notes(ds, format, name_field, target).map_err(|e| e.to_string())?);

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.

Memory: the CSV branch converts the layer twice once a layer holds another system. lonlat (line 2094) lives until the function returns, and export_losses_notes calls ds.in_lonlat() again for CSV (crates/data/src/io.rs:4324), so the peak is about 2× the layer, not the "≈1×, nothing converted twice" the PR body states. Today this is the identity path, so there is no cost yet.

Passing the already-converted copy here avoids the second copy. The losses notes only read coordinates in longitude/latitude, so the notes do not change. export_notes must keep ds, since it reads ds.crs.

Suggested change
notes.extend(rustgis_data::io::export_losses_notes(ds, format, name_field, target).map_err(|e| e.to_string())?);
notes.extend(rustgis_data::io::export_losses_notes(&lonlat, format, name_field, target).map_err(|e| e.to_string())?);

Confidence: high on the code path, medium on how much this matters before a layer can hold another system.

features.push_row(r.to_feature());
if let Some(g) = r.geometry()
&& let std::borrow::Cow::Owned(g) =
l.dataset.geometry_to_lonlat(g).map_err(|e| format!("{}: feature {}: {e}", l.name, r.id()))?

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.

Performance (latent): Dataset::geometry_to_lonlat calls self.coord_crs().to(LonLat) on every call. For a layer in another system, that builds a Crs::transformer() per feature. ogc_warp::transformer caches the same construction for this reason. The per-feature loops here (also sharing.rs styled_features and the Python layer_geojson selection branch) would pay that cost once per feature.

Behaviour is unchanged today, since coord_crs() is always LonLat and the call returns early. Before a layer can hold another system, build the Reprojection once per layer (Dataset::lonlat_conversion() is already public) and convert each row with it, or add a helper that does so. No change is needed in this PR if the follow-up is tracked for C2.

Confidence: medium. The mechanism is clear from the code. The cost depends on how expensive Crs::transformer is for the systems in use.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Behaviour is unchanged today: every dataset is held in longitude/latitude, so each in_lonlat and geometry_to_lonlat call is the identity. The findings below only matter once a layer can hold another system (C2). I checked the diff against the Dataset, Features and RowRef APIs, all the call sites and return types, and every GeoJSON/CSV/KML/GPX writer in the repo. No prior review threads exist on this PR, so I left none out.

Bugs

  • Python selection drops out-of-range rows silently. apps/rustgis-python/src/lib.rs:205 uses filter_map over selection and skips any index that row() rejects, with no notice. This predates the PR, but the PR rewrote this exact loop. Stale selection indices are unlikely. Confidence: low.

Security

  • None found. The changed code adds no input parsing and no new external surface.

Performance

  • Per-feature transformer rebuild (latent). geometry_to_lonlat rebuilds coord_crs().to(LonLat) on every call. Once a layer holds another system, the per-feature loops in plugins.rs:598, sharing.rs:526 and the Python selection branch will construct a transformer per feature. Confidence: medium. Inline comment posted at plugins.rs:598.
  • CSV conversion holds two full copies (latent). workflows.rs:2104 export_losses_notes runs its own in_lonlat() while the converted copy from line 2094 is still alive, so the peak is about 2× the layer. The PR says "≈1×" and "nothing is converted twice", which is inaccurate for CSV. Confidence: high on the code, medium on impact today. Inline comment with a one-line suggestion posted at workflows.rs:2104.

Quality

  • New refusal and conversion branches are untested. The cfg(test) hook lives only in rustgis-data, so the engine and Python paths can't be exercised. The PR says this and defers it to C2, which is a reasonable scope call. Confidence: medium. Under AGENTS.md this is "test both ways" and is not blocking.
  • Error text varies. in_lonlat says "feature N has a place in X…", geometry_to_lonlat says "a place of this feature in X…", and the callers prefix "layer: feature N:", so the messages read differently. Nit, left for the release quality pass.
  • Copies keep the source crs. in_lonlat clones with crs still set to the source system, so the copy passed to the writers says it holds source coordinates while the geometry is longitude/latitude. None of the five writers read ds.crs today, and the doc comment already notes this for C2. Confidence: low.

AGENTS.md

  • Size claim. The PR body's "≈1×" and "nothing is converted twice" are inaccurate for the CSV path (see above).
  • Reach-every-surface. The PR body names the desktop, Python, plugins, web and OGC surfaces and explains the rest. I checked the rest: geolibre stage and gp.rs lonlat_inputs already convert, plugins.rs:663 is the tail of the same features function, and clipboard.rs, embeddings.rs and ui-egui/embeddingsui.rs already use lonlat data.
  • Unverified. The xtask/row-uses.txt count (839 → 833) and the cargo xtask rows / memory checks need CI. I could not run them.

Change size

Compared with main (merge base e6f6e7b to PR head 72f7177).

Measure Value
Files changed 6 (0 added, 6 modified, 0 removed, 0 renamed)
Size before 378.5 KB (387,578 B)
Size after 380.4 KB (389,552 B)
Total size change +1.9 KB (+1,974 B)
File Before After Change
crates/engine/src/cmd/plugins.rs 69.4 KB 70.1 KB +747 B
apps/rustgis-python/src/lib.rs 13.5 KB 14.0 KB +502 B
crates/engine/src/cmd/sharing.rs 91.3 KB 91.7 KB +414 B
crates/engine/src/cmd/workflows.rs 110.5 KB 110.7 KB +182 B
crates/engine/src/cmd/items.rs 93.3 KB 93.4 KB +129 B
xtask/row-uses.txt 502 B 502 B 0 B

@pick2510
pick2510 enabled auto-merge November 20, 2026 09:42
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2510/
Web app not published: this branch predates preview marking; merge main into it
Commit 72f7177

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).

@pick2510
pick2510 added this pull request to the merge queue Nov 20, 2026
Merged via the queue into opengeos:main with commit 0ea4b14 Nov 20, 2026
29 checks passed
@pick2510
pick2510 deleted the feat/crs-export-2 branch November 20, 2026 10: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