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

Exclude some GeoAgents attributes from visualization #32

Closed
giacrava opened this issue Jul 2, 2021 · 2 comments · Fixed by #40
Closed

Exclude some GeoAgents attributes from visualization #32

giacrava opened this issue Jul 2, 2021 · 2 comments · Fixed by #40

Comments

@giacrava
Copy link

giacrava commented Jul 2, 2021

I already encountered two situations where some GeoAgents' attributes are causing the impossibility of visualizing the model interactively. 1) When they cause the agent to not be JSON serializable (for instance causing reciprocal references of agents or being pandas data structures), which causes an error 2) When they store lots of data, which makes the initialization of the visualization too long.

Is there a way to exclude some attributes of the GeoAgents from the interactive visualization? Thanks!

@stefaneidelloth
Copy link

I also got an error message that an additional agent property was not serializable.
A possible workaround might be to implement a custom geo_interface method:

    def __geo_interface__(self):
        """
        Override the default __geo_interface__ method of GeoAgent to resolve some serialization issues.

        Return a GeoJSON Feature.

        Removes shape from attributes.
        """
        properties = dict(vars(self))
        properties["model"] = str(self.model)
        shape = properties.pop("shape")

        properties.pop("site")  # <= removes site because it is not serializable 

        shape = transform(self.model.grid.Transformer.transform, shape)

        return {"type": "Feature", "geometry": mapping(shape), "properties": properties}

@wang-boyu
Copy link
Member

In your custom __geo_interface__ method, what if properties is changed into an empty dictionary? That is, to get rid of all attributes:

return {"type": "Feature", "geometry": mapping(shape), "properties": properties}

into

return {"type": "Feature", "geometry": mapping(shape), "properties": {}}

Subsequently the useful properties will be set in the render() function of MapModule. In this way hopefully only the necessary fields are sent to frontend for visualization.

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.

3 participants