feat: configurable GeoJSON coordinate precision (default 6) - #386
Merged
Conversation
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.
There was a problem hiding this comment.
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_precisionwith default/range clamping and a new plugin settinggeojson_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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
geojson_precision(default6, clamped to0..15) read viaRedmineGtt.geojson_precision. Storage keeps full precision; only output is rounded, so nothing is lost.ST_AsGeoJson(geom, <precision>)(themaxdecimaldigitsargument). The precision is a clamped Integer, so the interpolation is injection-safe.Conversions::GeomToJson): rounds the numbers under eachcoordinateskey after encoding, leavingpropertiesuntouched. This covers the map's issues-index GeoJSON,.geojsondownloads, and single-feature output.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
.geojson,.json) and the PostGIS path (indexdb_geojson) output[139.691701, 35.68953, 0.0]at the default; setting precision to2yields[139.69, 35.69]on both. Settings field renders and round-trips.Test note
assert_equal_coordinatespreviously compared at 5 decimals. Now that output is rounded to 6, comparing below the output precision double-rounds boundary values (e.g.135.2528349→round(6)135.252835→round(5)135.25284, whereas a directround(5)is135.25283). The helper now compares at the output precision, and the "small geom changes" assertions use that rounding comparator instead of exact float equality.