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

make TopoOptions JSON serializable #46

Closed
mattijn opened this issue Aug 16, 2019 · 0 comments · Fixed by #47
Closed

make TopoOptions JSON serializable #46

mattijn opened this issue Aug 16, 2019 · 0 comments · Fixed by #47

Comments

@mattijn
Copy link
Owner

mattijn commented Aug 16, 2019

Currently when doing:

import geojson
import topojson
import altair as alt

feature_1 = geojson.Feature(
    geometry=geojson.Polygon([[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]),
    properties={"name":"abc"}
)
feature_2 = geojson.Feature(
    geometry=geojson.Polygon([[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]]),
    properties={"name":"def"}
)
data = geojson.FeatureCollection([feature_1, feature_2])

tj = topojson.Topology(data, prequantize=False).to_dict()

# inline topojson data object
data_topojson = alt.InlineData(values=tj, format=alt.DataFormat(feature='data',type='topojson')) 

# chart object
alt.Chart(data_topojson).mark_geoshape(
).encode(
    color="properties.name:N"
).properties(
    projection={'type': 'identity', 'reflectY': True}
)

Results in:


TypeError: Object of type 'TopoOptions' is not JSON serializablec:\programdata\miniconda3\lib\json\encoder.py in default(self, o)
    178         """
    179         raise TypeError("Object of type '%s' is not JSON serializable" %
--> 180                         o.__class__.__name__)
    181 
    182     def encode(self, o):

TypeError: Object of type 'TopoOptions' is not JSON serializable

This is because tj['options'] is a class and not a dict.

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 a pull request may close this issue.

1 participant