locationtech / locationtech/spatial4j

Double resolution trimmed in GeoJSONWriter

Open
#140 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
961
Forks
172
PR merge metrics
No merged PRs in 30d

Description

I'm wondering if there is a reason for setting the lat/lon resolution in GeoJSONWriter to 6 decimal places?

I came across the following SW, NE bounding box from a geocoder
(53.3747317, -2.2614302
53.3747324, -2.2608337)

The GeoJSONWriter (using JtsSpatialContext.GEO) returned the following:

{
  "type": "Polygon",
  "coordinates": [
    [
      [
        -2.26143,
        53.374732
      ],
      [
        -2.26143,
        53.374732
      ],
      [
        -2.260834,
        53.374732
      ],
      [
        -2.260834,
        53.374732
      ],
      [
        -2.26143,
        53.374732
      ]
    ]
  ]
}

The first and second point are identical, which threw an exception when I tried to index it within Elasticsearch.

Is there an alternative way to convert the Shape to GeoJSON so it does not trim the values?

In the meantime, I am using BigDecimal.valueOf(doubleValue).toPlainString(). Is that something that can / should be changed in Spatial4j?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at GeoJSONWriter and trace how coordinate resolution is selected for JtsSpatialContext.GEO. Reproduce the reported bounding box output, then verify that the resulting GeoJSON preserves sufficient coordinate precision and does not create duplicate points that Elasticsearch rejects.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.