mapbox / mapbox/mapboxgl-jupyter

viz.create_html() rounds lat/lng to 4 decimal places which drops accuracy to 11m

Open
#185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
681
Forks
137
PR merge metrics
No merged PRs in 30d

Description

This is the difference between this:

Screen Shot 2021-05-31 at 3 37 04 pm

And this:

Screen Shot 2021-05-31 at 3 38 20 pm

This is happening here:
https://github.com/mapbox/mapboxgl-jupyter/blob/9a15a0759db5b0c5dc8d59f4a8e0d77b9c378daf/mapboxgl/viz.py#L281

I'm attempting to solve this by passing in a decimal rather than a float when building my FeatureCollection:
```
features.append(Feature(
geometry=Point((Decimal(m['lng']), Decimal(m['lat']))),
))
```

You can monkey patch this like this:

```
import json
import decimal

class FullJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o)
return super().default(o)

default_props = {'cls': FullJSONEncoder, 'skipkeys': False, 'check_circular': False, 'allow_nan': False, 'indent': False, 'separators': None, 'default': None, 'sort_keys': False, 'ensure_ascii': False}
with patch.object(json.dumps, '__kwdefaults__', default_props):
...
```

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 mapboxgl/viz.py around line 281, where viz.create_html() handles the coordinate data, and reproduce the reported precision loss with the Decimal-based FeatureCollection example. Done means generated HTML preserves the latitude and longitude accuracy instead of rounding them to four decimal places.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.