Problem with geojson data

Hi,

First post here, hi everybody. Pretty new to plotly so sorry if my terminology is not in line with community standars.

I’m trying to use choropleth_mapbox from plotly.express to visualize data on postal code areas of Finland. I can’t get it to work with postal codes where the area is not defined in a single polygon, but instead in multiple polygons. This is quite often the case in coastal post codes with inhabited islands.

Example: the geojson data below works if you paste it to geojson.io (http://geojson.io/#map=13/60.1582/24.8666, zoomed to correct location), but won’t show if used with the choropleth_mapbox method. Any idea how I could get it to work?

{
“type”: “FeatureCollection”,
“features”: [{“type”: “Feature”, “geometry”: {“type”: “GeometryCollection”, “geometries”: [{“type”: “Polygon”, “coordinates”: [[[24.871561, 60.16438], [24.872599, 60.164396], [24.87274, 60.1644], [24.873111, 60.164412], [24.873619, 60.164435], [24.874123, 60.16447], [24.87462, 60.164519], [24.87511, 60.164585], [24.875594, 60.164664], [24.876074, 60.164752], [24.876551, 60.164846], [24.877976, 60.165135], [24.878451, 60.165226], [24.878927, 60.16531], [24.879405, 60.165381], [24.879885, 60.165437], [24.880369, 60.16547], [24.880861, 60.165476], [24.881357, 60.165459], [24.881857, 60.165425], [24.882358, 60.16538], [24.882861, 60.165326], [24.883871, 60.165204], [24.885899, 60.164932], [24.887417, 60.16472], [24.888415, 60.164568], [24.888905, 60.164486], [24.889385, 60.164397], [24.889849, 60.164297], [24.890293, 60.164184], [24.890709, 60.164051], [24.891077, 60.1639], [24.891417, 60.16373], [24.891734, 60.163546], [24.892033, 60.163352], [24.892315, 60.163149], [24.892581, 60.162939], [24.892828, 60.162722], [24.893054, 60.1625], [24.893253, 60.162271], [24.893423, 60.162031], [24.893565, 60.161785], [24.893687, 60.161535], [24.89379, 60.161283], [24.893879, 60.16103], [24.893952, 60.160777], [24.894009, 60.160525], [24.894043, 60.160276], [24.894051, 60.16003], [24.894021, 60.159791], [24.89394, 60.15956], [24.893818, 60.159365], [24.893651, 60.159182], [24.893442, 60.15901], [24.893194, 60.158853], [24.892904, 60.158715], [24.892537, 60.158586], [24.892131, 60.158477], [24.891696, 60.158382], [24.889853, 60.158041], [24.889368, 60.157937], [24.8889, 60.157823], [24.888456, 60.157699], [24.888043, 60.157565], [24.887674, 60.157419], [24.887412, 60.157284], [24.886782, 60.157671], [24.886485, 60.157698], [24.88432, 60.157417], [24.883528, 60.156871], [24.881928, 60.156555], [24.881781, 60.156476], [24.881717, 60.156175], [24.881235, 60.155795], [24.880589, 60.155549], [24.879981, 60.155532], [24.879802, 60.155497], [24.879628, 60.155486], [24.879429, 60.155519], [24.87929, 60.155525], [24.878029, 60.155198], [24.877567, 60.155175], [24.876454, 60.155417], [24.873827, 60.15495], [24.873039, 60.154076], [24.873015, 60.154066], [24.872894, 60.154159], [24.872636, 60.154304], [24.872338, 60.154406], [24.871985, 60.154456], [24.87159, 60.154463], [24.871404, 60.154451], [24.871165, 60.154437], [24.870717, 60.154387], [24.870254, 60.154322], [24.869779, 60.154244], [24.869298, 60.154158], [24.868321, 60.153973], [24.866351, 60.15358], [24.866086, 60.153526], [24.864877, 60.153276], [24.863903, 60.153065], [24.862942, 60.152842], [24.862475, 60.152725], [24.861097, 60.152367], [24.860643, 60.152255], [24.860191, 60.152151], [24.859743, 60.152062], [24.8593, 60.151992], [24.858863, 60.151949], [24.858434, 60.151945], [24.858031, 60.151985], [24.857639, 60.152061], [24.857259, 60.152165], [24.85689, 60.15229], [24.856538, 60.15243], [24.856207, 60.152584], [24.855903, 60.152748], [24.855637, 60.152922], [24.855421, 60.153106], [24.855272, 60.153301], [24.855203, 60.153517], [24.855205, 60.153743], [24.85526, 60.153977], [24.855353, 60.154217], [24.855474, 60.154459], [24.855613, 60.154704], [24.855767, 60.154951], [24.856097, 60.155446], [24.856952, 60.156687], [24.857269, 60.157182], [24.857411, 60.157429], [24.857536, 60.157676], [24.85758, 60.157781], [24.857638, 60.157922], [24.857708, 60.158167], [24.857733, 60.158411], [24.857709, 60.158616], [24.857705, 60.158649], [24.857629, 60.158885], [24.85751, 60.159116], [24.857351, 60.15934], [24.857152, 60.159556], [24.856908, 60.159759], [24.856602, 60.159956], [24.856257, 60.16014], [24.855888, 60.160315], [24.854752, 60.160818], [24.854406, 60.160987], [24.854099, 60.16116], [24.85385, 60.16134], [24.853684, 60.161532], [24.853619, 60.16174], [24.853639, 60.161959], [24.85372, 60.162187], [24.853845, 60.162422], [24.854001, 60.162661], [24.854176, 60.162903], [24.854745, 60.163646], [24.854928, 60.163897], [24.855099, 60.164152], [24.855243, 60.16439], [24.855373, 60.164631], [24.855492, 60.164873], [24.855594, 60.165111], [24.855701, 60.165361], [24.855793, 60.165606], [24.855849, 60.165777], [24.855874, 60.165851], [24.855943, 60.166098], [24.855998, 60.166344], [24.856035, 60.166591], [24.856048, 60.166839], [24.856035, 60.167087], [24.856002, 60.167335], [24.855907, 60.167849], [24.855864, 60.16808], [24.855831, 60.168328], [24.855818, 60.168573], [24.855824, 60.168816], [24.85585, 60.169054], [24.8559, 60.169286], [24.855939, 60.169396], [24.855978, 60.169508], [24.856091, 60.169717], [24.856247, 60.169907], [24.856461, 60.17007], [24.85676, 60.170209], [24.857118, 60.170315], [24.857513, 60.170391], [24.857927, 60.170439], [24.858344, 60.170458], [24.858748, 60.170441], [24.859121, 60.17038], [24.859428, 60.170279], [24.859699, 60.170142], [24.859936, 60.169977], [24.860141, 60.169792], [24.860312, 60.169592], [24.860446, 60.169381], [24.860536, 60.16916], [24.860577, 60.168953], [24.860588, 60.168741], [24.86058, 60.168309], [24.860586, 60.168078], [24.860606, 60.167846], [24.860642, 60.167615], [24.860699, 60.167385], [24.86078, 60.167159], [24.860892, 60.166938], [24.86106, 60.1667], [24.861269, 60.16647], [24.861511, 60.166248], [24.861784, 60.166035], [24.862092, 60.16583], [24.862493, 60.165621], [24.862982, 60.165416], [24.863531, 60.165218], [24.864108, 60.165032], [24.864681, 60.164861], [24.865218, 60.164712], [24.866303, 60.164429], [24.866381, 60.164406], [24.868171, 60.164393], [24.869622, 60.164382], [24.871561, 60.16438]]]}, {“type”: “Polygon”, “coordinates”: [[[24.846138, 60.165783], [24.846639, 60.165784], [24.847183, 60.165793], [24.848249, 60.165825], [24.84877, 60.165827], [24.849358, 60.165795], [24.84987, 60.165722], [24.850267, 60.165619], [24.850638, 60.165493], [24.850994, 60.16535], [24.851333, 60.165197], [24.851655, 60.165039], [24.851833, 60.164945], [24.851956, 60.16488], [24.852233, 60.164718], [24.852459, 60.164552], [24.852607, 60.164376], [24.852656, 60.164196], [24.852627, 60.164007], [24.852538, 60.163811], [24.852397, 60.163614], [24.852213, 60.163417], [24.852, 60.163234], [24.851527, 60.162869], [24.850983, 60.162433], [24.85071, 60.162223], [24.850427, 60.162028], [24.850125, 60.161858], [24.849794, 60.161724], [24.849445, 60.161641], [24.84908, 60.1616], [24.848718, 60.161597], [24.848382, 60.161634], [24.848093, 60.161715], [24.847902, 60.16182], [24.847761, 60.161953], [24.847667, 60.162107], [24.847621, 60.162275], [24.847625, 60.162456], [24.84767, 60.162642], [24.847746, 60.162829], [24.847844, 60.163015], [24.848087, 60.163387], [24.848194, 60.16357], [24.848244, 60.163749], [24.848229, 60.163837], [24.84822, 60.163895], [24.848136, 60.164037], [24.847994, 60.164169], [24.84774, 60.16432], [24.847419, 60.164455], [24.847049, 60.164579], [24.846643, 60.164694], [24.846212, 60.164802], [24.845764, 60.164904], [24.845306, 60.165], [24.844842, 60.16509], [24.844377, 60.165174], [24.843941, 60.165243], [24.84351, 60.165302], [24.843089, 60.165346], [24.843047, 60.165349], [24.842603, 60.166555], [24.843155, 60.166407], [24.843699, 60.166251], [24.844187, 60.166103], [24.845031, 60.165838], [24.845073, 60.165829], [24.845145, 60.165813], [24.845365, 60.1658], [24.845704, 60.165789], [24.846138, 60.165783]]]}, {“type”: “Polygon”, “coordinates”: [[[24.84313, 60.148672], [24.842433, 60.1484], [24.841763, 60.148436], [24.841177, 60.148641], [24.840398, 60.148889], [24.83995, 60.149191], [24.839452, 60.149515], [24.839481, 60.149801], [24.839703, 60.150042], [24.840161, 60.150335], [24.840626, 60.150509], [24.841229, 60.150757], [24.841948, 60.150697], [24.842484, 60.150516], [24.842838, 60.150212], [24.843199, 60.14979], [24.843518, 60.149297], [24.843498, 60.148868], [24.84313, 60.148672]]]}, {“type”: “Polygon”, “coordinates”: [[[24.844547, 60.155421], [24.84374, 60.15536], [24.842874, 60.155489], [24.842426, 60.155767], [24.842025, 60.156069], [24.841622, 60.156395], [24.841023, 60.156813], [24.841047, 60.15717], [24.841511, 60.157368], [24.841979, 60.157494], [24.842597, 60.157528], [24.8429, 60.157272], [24.843203, 60.157015], [24.843702, 60.156667], [24.844042, 60.156577], [24.844913, 60.156378], [24.845275, 60.155956], [24.845107, 60.155597], [24.844547, 60.155421]]]}]}, “properties”: {“name”: “Lauttasaari”, “description”: “<div class=“googft-info-window”>\nid: 00200
\nnimi: Lauttasaari
\nnamn: Drums\u00f6
\nkunta: 091
\nkuntanro: 91
\nvuosi: 2016
\npinta_ala: 2619434.18\n”, “id”: “00200”, “namn”: “Drums\u00f6”, “kunta”: “091”, “kuntanro”: “91”, “vuosi”: “2016”, “pinta_ala”: “2619434.18”}, “id”: “00200”}]
}

Hi @mfahler,

It’s not the Multipolygon that makes your choropleth not showing up.
Please read here https:plot.ly/~empet/15238 what is usually missing in your data and why the choropleth is not displayed.

Thanks!

So it seems like I have to convert the geometry type used from GeometryCollection to Multipolygon and make the accompanying changes to the geojson structure? Let’s see how it goes.

@mfahler
No, just check if the id is defined and where in the geojson nested dicts. It is explained before the first scattermapbox definition.

I’m only having trouble with the areas with a GeometryCollection geometry type. Other areas show up fine in the choropleth.

I’m pretty sure this is the problem: https://plot.ly/python/reference/#choroplethmapbox-geojson
“Note that we only accept GeoJSON of type “FeatureCollection” and “Feature” with geometries of type “Polygon” and “MultiPolygon”.”

@mfahler

You are right. I didn’t notice GeometryCollection in the file definition. Maybe if you should try somehow to transform your geojson file such that to get one readable by Scattermapbox. Eventually to add different ids to each geometry in a GeometryCollection, but the same z value.

Restructured the JSON and got it to work. Thanks!

1 Like