Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aidanlister opened this issue May 31, 2021 · 0 comments

Comments

@aidanlister
Copy link

aidanlister commented May 31, 2021

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:

geojson_data=json.dumps(self.data, ensure_ascii=False),

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):
    ...
aidanlister added a commit to aidanlister/mapboxgl-jupyter that referenced this issue May 31, 2021
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

No branches or pull requests

1 participant