Valid GeoJSON object for choroplethmapbox Trace

Unfortunately PlotlyJS.jl doesn’t check whether a key/attribute is needed for a trace type. That’s why it worked with df, too.

You can read a geojson file as a json file, and modify some values or add new (key, values)

using JSON, HTTP
url  = "https://raw.githubusercontent.com/ginseng666/GeoJSON-TopoJSON-Austria/master/2017/simplified-99.9/laender_999_geo.json"
result = HTTP.request("GET", url)
jsondata = JSON.parse(String(result.body))

Let us inspect jsondata["features"][1]["properties"]

print(jsondata["features"][1]["properties"])

Add a new property:

for (k, feat) in enumerate(jsondata["features"])
    feat["properties"]["id"]=k
end  

save the modified geojson to a local json file:

stringdata = JSON.json(jsondata)
open("newjson.json", "w") do f
        write(f, stringdata)
end

Read the new geojson file:

newjdata= JSON.parsefile("newjson.json")

Inspect that the new property is present:

for feat in newjdata["features"]
    print(feat["properties"], "\n")
end 

now in the definition of the choroplethmapbox, set geojson=newjdata, instead of geojson=url.

1 Like