Skip to content

Add support for custom geojson polygons in choropleth traces #4267

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

Closed
geraldo opened this issue Oct 10, 2019 · 13 comments · Fixed by #4419
Closed

Add support for custom geojson polygons in choropleth traces #4267

geraldo opened this issue Oct 10, 2019 · 13 comments · Fixed by #4419
Assignees
Labels
feature something new
Milestone

Comments

@geraldo
Copy link

geraldo commented Oct 10, 2019

Locationmode right now only accepts these 3 options: "ISO-3" | "USA-states" | "country names"

I want to make choropleth maps for different countries on provinces level, as equivalent to locationmode: "USA-states". Instead of defining a new locationmode for every country, like "BRA-states" or "ESP-states" maybe it would be better to define a new generic one calles "province" and afterwards define the country using locations option.

@etpinard
Copy link
Contributor

etpinard commented Oct 25, 2019

Our current topojson files (built in https://github.com/etpinard/sane-topojson using Natural Earth data) contain:

  • (only) USA states for the 110m resolution
  • USA, Brazil and Australian states + Canadian provinces at 50m

The "full" subunit lists are available here.


In general, we can't use a single locationmode value for all these subunits because they have overlapping values. For example, 'WA' means both Washington state and Western Australia.


I suspect what you're really looking for is either:

  • Add topojson files for the 10m resolution to have subunits from more countries available to choropleth traces. We would consider doing this only for scoped geo maps, as in the 'world' scope rendering would be too slow (in SVG at least)
  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

@nicolaskruchten nicolaskruchten added this to the v1.52.0 milestone Nov 15, 2019
@etpinard
Copy link
Contributor

@nicolaskruchten I suspect you're looking for us to implement

  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

item here?

@nicolaskruchten
Copy link
Contributor

Yup. TopoJSON optional for now but basically the same API as we did for mapbox would be great, plus some automatic bounding box logic

@geraldo
Copy link
Author

geraldo commented Nov 20, 2019

  • To provide your own "subunit" topojson (or geojson) in choropleth traces, similar how choroplethmapbox does it.

Yes, that's what I'm looking for. The first option also would be nice, but actually it's not hard to make (or find) topojson files for different countries.

Thanks for translating my description into a proper feature request.

@etpinard etpinard changed the title [Feature request] make location mode extendible Add support for custom geojson polygons in choropleth traces Nov 20, 2019
@etpinard etpinard added the feature something new label Nov 20, 2019
@etpinard etpinard self-assigned this Nov 22, 2019
@etpinard
Copy link
Contributor

etpinard commented Nov 29, 2019

Here's my WIP branch:

where a new locationmode value is added in choropleth and scattergeo traces called 'geojson-id' and where much of the corresponding choroplethmapbox logic is reused.


Now regarding

plus some automatic bounding box logic

This is essentially the geo subplot version of #3434. To me, it makes more sense to implement this at the subplot level.

I'm thinking of adding a new layout.geo attribute named fitbounds which would be false by default. When turned on, we would compute the bounds of the data in all traces (i.e. lon/lat pts for scattergeo, polygons for choropleth) on the subplot and "fit" them (i.e. compute the corresponding projection.scale and translation) before first render. This would essentially be an "opt-on" version of our autorange routine.

That's probably a couple more days of work; nothing substantial. Does that sound ok?

@etpinard
Copy link
Contributor

etpinard commented Nov 29, 2019

... oops, I forgot to paste the link to the demo:https://codepen.io/etpinard/pen/zYxOoEB

@nicolaskruchten
Copy link
Contributor

That's probably a couple more days of work; nothing substantial. Does that sound ok?

Yes! Can we default it to true for geo subplots that contain only choropleth in geojson mode... somehow?

@nicolaskruchten
Copy link
Contributor

Also: this would be geo-only right? we would add it to mapbox some other day?

@etpinard
Copy link
Contributor

Can we default it to true for geo subplots that contain only choropleth in geojson mode... somehow?

We could, but I'd vote against it for consistency with choroplethmapbox.

@etpinard
Copy link
Contributor

Also: this would be geo-only right? we would add it to mapbox some other day?

Yes, that's the plan for v1.52.0

@nicolaskruchten
Copy link
Contributor

what would fitbounds do when not using geojson and/or in the presence of scope?

@nicolaskruchten
Copy link
Contributor

Having thought about this a bit, I think fitbounds would need to accept two modes, in addition to "off"... One scoped to the entire geojson, and one scoped to locations-only.

@etpinard
Copy link
Contributor

etpinard commented Dec 2, 2019

Having thought about this a bit, I think fitbounds would need to accept two modes, in addition to "off"... One scoped to the entire geojson, and one scoped to locations-only.

Sure, good call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants