Skip to content

feat(data): override dBASE encoding on import - #3655

Open
Mavrick-F wants to merge 1 commit into
opengeos:mainfrom
Mavrick-F:t3/add-data-encoding
Open

Mavrick-F wants to merge 1 commit into
opengeos:mainfrom
Mavrick-F:t3/add-data-encoding

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Shapefiles and dBASE tables without encoding metadata fall back to UTF-8. For a CP932 file, this can replace Japanese text with U+FFFD. Pass a code page name or number to layer.addData, layer.addDataBytes or layer.addDownload to decode the text without writing a sidecar. RustGIS applies the override before the .cpg and language driver and still reports malformed bytes. Projects retain the choice, including when a linked Shapefile is reopened.

  • Desktop Add Data exposes a dBASE encoding field in the Shapefile link/copy dialog. Browser uploads can set it with layer.addDataBytes, and hosts can set it in layer.addDownload when completing a download. The phone uses the shared command handlers.
  • The CLI, Python add_data, Assistant and MCP use the shared command parameters. Plugins that can call these commands use the same parameters and existing command permissions.
  • The desktop ribbon opens the same Add Data dialog. Command search and configured shortcuts use the registered commands. The import uses the existing undo and removal paths. A reopened project retains the decoder for linked sources and the decoded rows for copies.

Testing

  • Reproduced the UTF-8 replacement on a CP932 file with no .cpg and a zero language driver. Confirmed that a build without the new capability refuses the project fixture.
  • Regenerated the command snapshot and project schema with cargo xtask commands and cargo xtask schema.
  • Passed the engine regression for code-page selection, malformed text, byte and download imports, and project reopen.
  • Passed the project fixture, loss-guide parity, and saved command capability tests. Passed the full Linux fork gate, including the WebAssembly build and Chrome smoke test. Fork CI

UI evidence

Add Data dialog before the change

Add Data dialog with the dBASE encoding field

Related issue

Maintainer-approved additive change.

Summary by CodeRabbit

  • New Features

    • Add an optional encoding override when importing Shapefiles and dBASE tables, including from ZIP files, downloads, and byte uploads. The override takes precedence over file metadata and is saved with the project.
    • Desktop Shapefile import now offers an encoding field.
    • Imports without an override continue to use file metadata and existing fallback behavior.
  • Bug Fixes

    • Improved notices for encoding-related text changes and unsupported overrides.
    • Projects with encoding overrides are identified as requiring support for that setting.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds optional dBASE encoding overrides for Shapefile and dBASE imports. The override passes through import routes and readers, is retained in dataset and project state, and is used during Shapefile publishing. The changes also update encoding notices, documentation, and tests.

Changes: dBASE Encoding Overrides

Layer / File(s) Summary
Encoding-aware DBF readers
crates/data/src/dbf.rs, crates/data/src/io.rs, crates/data/src/lib.rs, crates/data/src/source/shp.rs, crates/data/tests/integration/shapefile_encoding.rs
DBF, Shapefile, and ZIP readers accept optional encoding overrides. The readers validate supplied labels and record supplied encodings on datasets.
Import routes and encoding input
apps/rustgis-python/python/rustgis/__init__.py, crates/engine/src/cmd/*, crates/engine/src/tests.rs, crates/engine/command-surface.txt, crates/ui-egui/src/layerchooser.rs
The Python API, Add Data commands, byte and download routes, and desktop chooser pass encoding overrides to readers. Read-ahead keys include the encoding. Tests cover these routes and ignored options.
Retained encoding and project compatibility
crates/map/src/source.rs, crates/engine/src/project.rs, crates/engine/src/project_capabilities.rs, crates/engine/src/peer.rs, crates/engine/src/cmd/repair.rs, crates/map/src/*, crates/plugins/src/tools.rs, schema/*, docs/maintaining.md
Source layers and project tables retain encoding overrides. Capability detection identifies projects and saved content that require dBASE encoding support. Source identity and stale-state checks include the setting.
Publishing, notices, and documentation
crates/data/src/publish.rs, crates/data/src/loss.rs, crates/data/src/source/mod.rs, docs/user-guide/*
Shapefile publishing uses the dataset encoding for style selection and validation reads. Encoding notices and documentation describe overrides and encoding precedence.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client as Add Data UI or Python API
  participant Command as layer.addData command
  participant Reader as Encoding-aware reader
  participant Dataset as Dataset
  Client->>Command: path and encoding override
  Command->>Reader: read data with encoding override
  Reader->>Dataset: decoded data and supplied encoding
Loading

Possibly related issues

  • opengeos/RustGIS issue 1853 concerns saved project capabilities. This change adds the dbf-encoding capability to projects and schemas.
  • opengeos/RustGIS issue 1405 concerns older releases refusing unsupported document content. This change marks projects that require dBASE encoding support.

Possibly related PRs

  • opengeos/RustGIS#713: Defines the metadata-based encoding selection order that this change extends with an explicit override.
  • opengeos/RustGIS#3252: Adds notices for missing usable encoding metadata in the same Shapefile and DBF import paths.

Suggested reviewers: giswqs, choupeanut, elpidioassinaturas

Merge Risk: Minimal · up to cdebb

The dBASE encoding override reaches the import routes and is retained in projects, with capability gating for older readers. Review found no concrete defect that should block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(data): override dBASE encoding on import" matches the main change in the changeset. The summaries show a new optional encoding override for layer.addData, layer.addDataBytes, and layer…
Description check Passed The description follows the template's sections: Summary, Testing, UI evidence, and Related issue. The Summary explains what changes and why, covering the CP932 UTF-8 replacement problem, the new over…
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 "feat(data): override dBASE encoding on import" matches the main change in the changeset. The summaries show a new optional encoding override for layer.addData, layer.addDataBytes, and layer.addDownload, applied to Shapefile and dBASE text imports, and persisted in projects via a new dbf-encoding capability. The title is concise, specific, and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the template's sections: Summary, Testing, UI evidence, and Related issue. The Summary explains what changes and why, covering the CP932 UTF-8 replacement problem, the new override, and project persistence. Testing lists commands run and tests passed. UI evidence includes before and after screenshots for the dialog change. The Related issue section gives 'Maintainer-approved additive change' rather than an issue reference, as the template asks for 'Closes #123' or 'Part of #456'. This is a minor gap and does not outweigh the otherwise complete description.

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 code-page key,
The DBF reads clearly as can be.
From ZIP to map, the labels stay,
Saved projects keep the choice in play.
The bunny hops, then files away.

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: 51ff08e0-fae7-4acc-a7c2-a62d12825ea7
Commits

Reviewing files that changed from the base of the PR and between 17a145b and cdebb5c.

Files selected for processing: 30

  • apps/rustgis-python/python/rustgis/__init__.py
  • crates/data/src/dbf.rs
  • crates/data/src/io.rs
  • crates/data/src/lib.rs
  • crates/data/src/loss.rs
  • crates/data/src/publish.rs
  • crates/data/src/source/mod.rs
  • crates/data/src/source/shp.rs
  • crates/data/tests/integration/shapefile_encoding.rs
  • crates/engine/command-surface.txt
  • crates/engine/src/cmd/layer.rs
  • crates/engine/src/cmd/plugins.rs
  • crates/engine/src/cmd/raster.rs
  • crates/engine/src/cmd/repair.rs
  • crates/engine/src/peer.rs
  • crates/engine/src/project.rs
  • crates/engine/src/project_capabilities.rs
  • crates/engine/src/tests.rs
  • crates/map/src/lib.rs
  • crates/map/src/look.rs
  • crates/map/src/source.rs
  • crates/plugins/src/tools.rs
  • crates/ui-egui/src/layerchooser.rs
  • docs/maintaining.md
  • docs/user-guide/data-formats.md
  • docs/user-guide/data.md
  • docs/user-guide/loss-codes.md
  • docs/user-guide/shapefile-encoding.md
  • schema/fixtures/dbf_encoding.rgis
  • schema/project.schema.json

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

Comment on lines +5751 to +5753
let r =
super::raster::add_named_bytes_read(s, p, name, bytes, b(p, "zoom"), super::raster::ByteRead { asked, ..Default::default() })
.map_err(named)?;

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.

layer.addUrl downloads a Shapefile, zip or .dbf address and hands the bytes to add_named_bytes_read with ByteRead { asked, .. }, so an encoding on that command is never read. layer.addUrl's spec does not declare encoding either, and unknown keys are ignored (layer.rs:5777). An encoding given for a URL is therefore dropped with no notice, and the text decodes with the .cpg or UTF-8 default. That is the silent wrong-text case this PR is meant to fix, and the URL route is a twin of layer.addDownload, which does pass it through.

Suggested fix: forward the encoding here, declare "encoding"? in the layer.addUrl params (then run cargo xtask commands), and add a regression test with a CP932 .dbf fetched by URL that checks the decoded text and the notice.

Suggested change
let r =
super::raster::add_named_bytes_read(s, p, name, bytes, b(p, "zoom"), super::raster::ByteRead { asked, ..Default::default() })
.map_err(named)?;
let r = super::raster::add_named_bytes_read(
s,
p,
name,
bytes,
b(p, "zoom"),
super::raster::ByteRead { asked, encoding: dbf_encoding(p).as_deref(), ..Default::default() },
)
.map_err(named)?;

Category: bug

requires
}

fn command_uses_dbf_encoding(id: &str, params: &Value) -> bool {

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.

command_uses_dbf_encoding sets the dbf-encoding requirement for any encoding on these three commands, including sources that ignore it (GeoJSON, GeoPackage, Parquet, a PNG). A saved script or macro with such a parameter then makes the project refused by older RustGIS even though nothing about it depends on the new reader. Only .shp, .dbf and .zip paths use the option (takes_dbf_encoding in layer.rs already defines that set), so the check could test the path too, or the requirement could follow Dataset::dbf_encoding alone, which the layer and table checks already cover.

Category: quality

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Code review

Reviewed the whole diff (30 files) against pr-context/AGENTS.md. No earlier review threads exist on this PR, so none were left alone. I could not build or run the tests (no shell), so these findings come from reading the diff and the surrounding source. I did not check that the test helpers the new engine test calls exist.

Bugs

  • layer.addUrl silently drops encoding for Shapefile, zip and .dbf URLs (crates/engine/src/cmd/layer.rs:5751). The URL route calls add_named_bytes_read with no encoding, its spec does not declare encoding, and unknown keys are ignored. The user gets the wrong decode with no notice, which breaks the "Never silent" rule. The URL route is a twin of layer.addDownload, which does pass the encoding. Confidence: high (about 85%). Inline comment posted with a fix.

Security

  • None found. The label is trimmed, length-capped and matched against a fixed list in DbfEncoding::parse, and it never reaches a path, a command or a shell.

Performance

  • None found. The no-CRS Shapefile route now goes through read_shapefile_with, but is_syncable already sent .shp to read_synced, so no extra sync-base copy is added. Confidence: high.

Quality

  • command_uses_dbf_encoding (crates/engine/src/project_capabilities.rs:2273) requires the dbf-encoding capability for any encoding, including on sources that ignore it. That makes older readers refuse such projects for no reason. Inline comment posted. Confidence: medium-high.
  • read_path_with_encoding drops the override in its zip/KML arm, which calls read_bytes without an encoding. Add Data does not reach it today, because zips go through read_layers_file, so this is latent. Confidence: medium.
  • dbf_encoding() turns true, [] or {} into Some(""), so a .shp fails with "unsupported dBASE encoding" and does not say the value had the wrong type. Rejecting non-string, non-number values where they are parsed would be clearer. Confidence: medium.
  • Scope note, not a defect: the desktop field appears only for .shp (layerchooser.rs). .dbf and zipped Shapefile imports have no field, which matches the PR body's "Shapefile link/copy dialog". Confidence: high.

AGENTS.md

  • The layer.addUrl gap above is also a "Never silent" and "Reach every surface" break. It is recorded under Bugs, not repeated here.

Twins checked

  • Read routes: layer.addData (loose .shp/.dbf, streamed, zip, GeoJSON), layer.addDataBytes, layer.addDownload, layer.addUrl (finding above), layer.addDataText (text cannot be dBASE, so none needed). GDAL and DuckDB do not read .shp, and the "ignored" notice covers them.
  • Project paths: Table, Layer and SourceLayer keep the encoding through save, reopen, repair, reload, publish and peer, and the capability checks cover both datasets and sources.
  • The wasm branches: the no-CRS desktop route stays behind cfg(not(wasm32)), and read_shapefile_with stays gated.

Change size

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

Measure Value
Files changed 30 (1 added, 29 modified, 0 removed, 0 renamed)
Size before 7.1 MB (7,460,013 B)
Size after 7.1 MB (7,475,866 B)
Total size change +15.5 KB
Path Before After Change
crates/engine/src/tests.rs 3.9 MB 3.9 MB +4.8 KB
crates/data/src/io.rs 625.5 KB 627.7 KB +2.2 KB
crates/engine/src/cmd/layer.rs 497.0 KB 499.0 KB +2.0 KB
crates/engine/src/project_capabilities.rs 325.0 KB 326.0 KB +1.0 KB
crates/ui-egui/src/layerchooser.rs 39.0 KB 39.7 KB +0.8 KB
docs/user-guide/data.md 163.8 KB 164.4 KB +0.6 KB
crates/map/src/source.rs 141.7 KB 142.3 KB +0.6 KB
crates/engine/src/cmd/raster.rs 104.2 KB 104.7 KB +0.5 KB
crates/data/tests/integration/shapefile_encoding.rs 46.3 KB 45.8 KB -0.5 KB
schema/fixtures/dbf_encoding.rgis 0 B 409 B +409 B
crates/data/src/source/shp.rs 53.5 KB 53.9 KB +0.4 KB
crates/data/src/lib.rs 104.9 KB 105.2 KB +0.4 KB
apps/rustgis-python/python/rustgis/init.py 41.8 KB 42.2 KB +0.4 KB
docs/user-guide/data-formats.md 128.6 KB 128.9 KB +0.4 KB
crates/data/src/publish.rs 101.0 KB 101.3 KB +0.3 KB
crates/data/src/dbf.rs 46.3 KB 46.6 KB +0.3 KB
crates/engine/src/project.rs 158.5 KB 158.8 KB +0.3 KB
docs/maintaining.md 40.2 KB 40.4 KB +0.2 KB
schema/project.schema.json 39.9 KB 40.1 KB +0.2 KB
crates/map/src/look.rs 24.4 KB 24.5 KB +118 B

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3655/
Web app https://preview.rustgis.app/pr-3655/app/
Commit cdebb5c

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

This branch has not been deployed

No deployments
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