Skip to content

Add support for custom geojson polygons in choropleth traces #4267

Description

@geraldo

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.

Activity

  1. etpinard commented on Oct 25, 2019

    @etpinard
    Contributor

    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.
  2. added this to the v1.52.0 milestone on Nov 15, 2019
  3. etpinard commented on Nov 19, 2019

    @etpinard
    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?

  4. nicolaskruchten commented on Nov 19, 2019

    @nicolaskruchten
    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

  5. geraldo commented on Nov 20, 2019

    @geraldo
    Author
    • 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.

  6. changed the title [-][Feature request] make location mode extendible[/-] [+]Add support for custom geojson polygons in choropleth traces[/+] on Nov 20, 2019
  7. self-assigned this
    on Nov 22, 2019
  8. etpinard commented on Nov 29, 2019

    @etpinard
    Contributor

    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?

  9. etpinard commented on Nov 29, 2019

    @etpinard
    Contributor

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

  10. nicolaskruchten commented on Nov 29, 2019

    @nicolaskruchten
    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?

  11. nicolaskruchten commented on Nov 29, 2019

    @nicolaskruchten
    Contributor

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

  12. etpinard commented on Nov 29, 2019

    @etpinard
    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.

  13. etpinard commented on Nov 29, 2019

    @etpinard
    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

  14. nicolaskruchten commented on Nov 30, 2019

    @nicolaskruchten
    Contributor

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

  15. nicolaskruchten commented on Dec 2, 2019

    @nicolaskruchten
    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.

  16. etpinard commented on Dec 2, 2019

    @etpinard
    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.

    Sure, good call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions