Skip to content

feat: configurable GeoJSON coordinate precision (default 6) - #386

Merged
dkastl merged 2 commits into
nextfrom
feat/geojson-precision
Jun 14, 2026
Merged

feat: configurable GeoJSON coordinate precision (default 6)#386
dkastl merged 2 commits into
nextfrom
feat/geojson-precision

Conversation

@dkastl

@dkastl dkastl commented Jun 14, 2026

Copy link
Copy Markdown
Member

Closes #7.

Problem

GeoJSON output carried full floating-point precision (15-17 digits), e.g. 135.27597373034055. For EPSG:4326 that is far beyond any real-world accuracy (6 places ≈ 0.11 m, 7 ≈ 1 cm) and it bloats the payload, which is noticeable for large polygons. RGeo's GeoJSON encoder offers no precision option and upstream declines to add one (the original concern in #7), so the plugin now rounds coordinates itself.

Change

  • Setting: new geojson_precision (default 6, clamped to 0..15) read via RedmineGtt.geojson_precision. Storage keeps full precision; only output is rounded, so nothing is lost.
  • PostGIS path: ST_AsGeoJson(geom, <precision>) (the maxdecimaldigits argument). The precision is a clamped Integer, so the interpolation is injection-safe.
  • RGeo path (Conversions::GeomToJson): rounds the numbers under each coordinates key after encoding, leaving properties untouched. This covers the map's issues-index GeoJSON, .geojson downloads, and single-feature output.
  • Settings UI: a number field on the General tab, with en/ja/de strings.
  • geodata_for_print (single-feature print, EPSG:3857 meters) is intentionally left as-is; it is a different unit and not the payload concern.

Verification

  • Live in a Redmine 6.1 dev instance with a high-precision point: both the RGeo path (.geojson, .json) and the PostGIS path (index db_geojson) output [139.691701, 35.68953, 0.0] at the default; setting precision to 2 yields [139.69, 35.69] on both. Settings field renders and round-trips.
  • Ruby tests pass (unit issue/project/user + API integration + gtt_map + filter API: 30 runs, 305 assertions, 0 failures).

Test note

assert_equal_coordinates previously compared at 5 decimals. Now that output is rounded to 6, comparing below the output precision double-rounds boundary values (e.g. 135.2528349round(6) 135.252835round(5) 135.25284, whereas a direct round(5) is 135.25283). The helper now compares at the output precision, and the "small geom changes" assertions use that rounding comparator instead of exact float equality.

Closes #7.

GeoJSON output carried full floating-point precision (15-17 digits), which
bloats payloads for large geometries and conveys no real accuracy. RGeo's
encoder offers no rounding option and upstream declines to add one, so the
plugin now rounds coordinates itself.

- New plugin setting geojson_precision (default 6, clamped 0..15). In
  EPSG:4326 degrees, 6 places is ~0.11 m and 7 is ~1 cm, so 6 is a safe
  default; storage keeps full precision, only output is rounded.
- PostGIS path: ST_AsGeoJson(geom, precision) (maxdecimaldigits).
- RGeo path: Conversions::GeomToJson rounds the numbers under each
  'coordinates' key after encoding, leaving 'properties' untouched.
- Settings UI field (general tab) + en/ja/de strings.

Tests: assert_equal_coordinates now compares at the output precision (6)
rather than 5; comparing below the output precision double-rounds boundary
values. The 'small geom changes' assertions use that rounding comparator.

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.

Pull request overview

Adds a configurable precision setting to round GeoJSON coordinates on output (default 6 decimals) to reduce payload size while preserving stored full-precision geometry, covering both the PostGIS (ST_AsGeoJson) and RGeo encoding paths.

Changes:

  • Introduces RedmineGtt.geojson_precision with default/range clamping and a new plugin setting geojson_precision.
  • Applies precision in the PostGIS select (ST_AsGeoJson(..., precision)) and rounds coordinates post-encode for the RGeo path.
  • Updates settings UI and i18n strings; adjusts coordinate comparison helper/tests for the new output rounding behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/redmine_gtt.rb Adds default/range constants and RedmineGtt.geojson_precision setting reader with clamping.
lib/redmine_gtt/patches/geojson_attribute.rb Uses ST_AsGeoJson(..., precision) for DB-side GeoJSON generation.
lib/redmine_gtt/conversions.rb Rounds numeric values under coordinates after RGeo GeoJSON encoding.
init.rb Registers new plugin default setting geojson_precision: 6.
app/views/settings/gtt/_general.html.erb Adds settings UI number field for GeoJSON precision (0–15).
config/locales/en.yml Adds label/help text for the new setting (English).
config/locales/ja.yml Adds label/help text for the new setting (Japanese).
config/locales/de.yml Adds label/help text for the new setting (German).
test/test_helper.rb Updates coordinate comparison helper to compare at output precision.
test/unit/issue_test.rb Switches geom-change assertions to use the rounding-aware coordinate comparator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_helper.rb Outdated
assert_equal_coordinates used DEFAULT_GEOJSON_PRECISION; use
RedmineGtt.geojson_precision so the comparison follows the live setting and
stays correct if a test changes it.
@dkastl
dkastl merged commit e9d689c into next Jun 14, 2026
17 of 18 checks passed
@dkastl
dkastl deleted the feat/geojson-precision branch June 14, 2026 13:49
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