Skip to content

Folium can't parse TopoJSON objects with dashes - in name #828

@kevhill

Description

@kevhill

This works just fine in an ipython notebook

m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
    {
      "type":"Topology",
      "transform":{
        "scale": [1,1],
        "translate": [0,0]
      },
      "objects":{ 
        "two_squares":{
          "type": "GeometryCollection",
          "geometries":[
            {"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
            {"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
          ]
        }
      },
      "arcs": [
        [[1,2],[0,-2]],
        [[1,0],[-1,0],[0,2],[1,0]],
        [[1,2],[1,0],[0,-2],[-1,0]]
      ]
    },
    object_path='objects.two_squares'
).add_to(m)
m

but changing the object to include a - renders the map, but not the polygons

m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
    {
      "type":"Topology",
      "transform":{
        "scale": [1,1],
        "translate": [0,0]
      },
      "objects":{ 
        "two-squares":{
          "type": "GeometryCollection",
          "geometries":[
            {"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
            {"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
          ]
        }
      },
      "arcs": [
        [[1,2],[0,-2]],
        [[1,0],[-1,0],[0,2],[1,0]],
        [[1,2],[1,0],[0,-2],[-1,0]]
      ]
    },
    object_path='objects.two-squares'
).add_to(m)
m

Problem description

Literally took me 3 hours to diagnose, as the first topojson file I ever tried to render used -s

Expected Output

Ideal fix would just be to render all objects, as there is no topojson specification that precludes -s. Consolation prize would be a friendly error message when object_path contains a -

Output of folium.__version__

0.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing unexpected or malicious behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions