Hi guys,
I recently upgraded from 12.3 to 12.4 and noticed a few updates to the GeoJSON functionality, which unfortunately broke my code:
geo_dict = json.loads('filename')
### .... some processing ...
p = Plot()
geo_source = GeoJSONDataSource(geojson=json.dumps(geo_dict))
geo_source.data['name_long'] = [region['properties']['NUTS_ID'] for region in geo_dict['features']]
borders = Patches(xs='xs', ys='ys', line_color='black', line_width=1)
p.add_glyph(geo_source, borders)
hover = HoverTool(tooltips=[
("index", "$index"),
("NUTS ID", "@NUTS_ID")
]
)
p.add_tools(hover, TapTool(), PanTool(), WheelZoomTool(), ResetTool())
output_file("geojson_nuts_EP.html")
show(layout([[p]], sizing_mode='stretch_both'))
Python now complains that GeoJSONDataSource does not know “data” anymore, the following assignment causes the error:
geo_source.data['name_long'] = (whatever)
For some context, this is a map of europe with the so-called NUTS ID (and shapes) assigned to political regions of each country, roughly 20 or more per country. The first few lines of the GeoJSON file are shown below
I understand from the thread (linked below in the “PPS”) that for tooltips, the geojson properties are accessible somehow, as they are part of the dictionary anyway.
So, my questions:
- a solution would be to simply remove the line that causes the error and reference the NUTS_ID field in the tooltips command (how do i locate this field? In the JSON it is root->features->properties->“NUTS_ID”, see snippet below). Is that the right / canonical way to do this?
- if I want to assign additional information to display as a tooltip, that is not present in the GeoJSON, such as additional statistics calculated at runtime or fetched from a DB: How to proceed now that I can not write to “data” directly anymore? I could possibly: 1. read the Geojson into a dict, 2. add the data to the dict, 3. create a GeoJSONDataSource from the dict, 4. reference the newly added attributes. Is this the recommended way to go?
Please keep up the good work, Bokeh is such a wonderful tool.
Thanks, regards,
Georg
PS. GeoJSON snippet:
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "id": 0, "properties": { "NUTS_ID": "AT111", "STAT_LEVL_": 3, "SHAPE_Leng": 1.089017,
"SHAPE_Area": 0.080915 }, "geometry": { "type": "Polygon", "coordinates":
[ [ [ 16.64622, 47.446597 ], [ 16.624257515000011, 47.43690559800001 ], [ 16.611879965000014, 47.431443748000049 ],
PPS. a related thread was here (I decided to open a new one):
https://groups.google.com/a/continuum.io/forum/#!searchin/bokeh/geojson/bokeh/xlosZB6c71U/4AmFvx4FFAAJ