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

support for multiple gdf and geojson as input #169

Merged
merged 17 commits into from
Aug 26, 2022
Merged

Conversation

mattijn
Copy link
Owner

@mattijn mattijn commented Aug 13, 2022

WIP. This PR aims to support multiple geodataframes as input to store it in a single topojson file.

Eg. combination of global continent-level and country-level data.

@mattijn
Copy link
Owner Author

mattijn commented Aug 13, 2022

BTW. Reading of topojson files that includes multiple objects is already supported:

with open(r'tests/files_topojson/gm.topo.json') as f:
    topo_file = json.load(f)
    
topo_nl = Topology(topo_file, object_name='nl_features')
topo_gm = Topology(topo_file, object_name='gm_features')

topo_nl.to_alt(projection='mercator')

topo_gm.to_alt(projection='mercator')

@mattijn
Copy link
Owner Author

mattijn commented Aug 13, 2022

Goal is to support the following approach:

import geopandas as gpd
from topojson import Topology

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world[['continent', 'geometry', 'pop_est']]
continents = world.dissolve(by='continent', aggfunc='sum')

Topology(
    data=[world, continents], 
    object_name=['world', 'continents']
)

@mattijn
Copy link
Owner Author

mattijn commented Aug 24, 2022

I like this feature. Check the following:

import geopandas as gpd
from topojson import Topology
import altair as alt

africa_countries = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")).query('continent == "Africa"')
africa_continent = africa_countries.dissolve(by='continent', aggfunc='sum').reset_index()

topo = Topology(
    data=[africa_countries, africa_continent], 
    object_name=['countries', 'continent']
)
# disable dataset consolidation
# see https://altair-viz.github.io/user_guide/data_transformers.html#dataset-consolidation
alt.data_transformers.consolidate_datasets = False

# simplify the topology in once for both objects and visualise 
topo.toposimplify(5, inplace=True)
topo.to_alt(object_name='continent') | topo.to_alt(object_name='countries')

image

@mattijn mattijn marked this pull request as ready for review August 24, 2022 22:30
@mattijn mattijn merged commit e375bc9 into master Aug 26, 2022
@mattijn
Copy link
Owner Author

mattijn commented Aug 26, 2022

@mattijn mattijn changed the title support for multiple gdf as input support for multiple gdf and geojson as input Sep 4, 2022
@mattijn
Copy link
Owner Author

mattijn commented Sep 4, 2022

Accidentally commit to master instead from a PR. This commit e32cfc3 provides support for multiple geojson objects as input.
Documented here: https://mattijn.github.io/topojson/example/input-types.html#list-of-geojson-objects

@mattijn mattijn deleted the multiple-gdf-input branch September 20, 2022 07:52
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 this pull request may close these issues.

None yet

1 participant