How to patch a pandas serie of geoshape ?

I have a pandas dataframe with a column of geoshapes That I would like to display on a map.
Here is the panda series :

``

df.geo_shape[1]
‘{“type”: “Polygon”, “coordinates”: [[[6.728855014402648, 48.1826428129768], [6.727148434879513, 48.18556129472969], [6.710527883652117, 48.18980540566836], [6.712004081624399, 48.198532676335226], [6.742612281822289, 48.20036752133914], [6.746955379591678, 48.190564047365754], [6.742731763437623, 48.18495991879576], [6.728855014402648, 48.1826428129768]]]}’


``

as the geo shape come as a string I eval it and give it to a geoJSONDataSource :

geodata = GeoJSONDataSource(ast.literal_eval(df.geo_shape[0]))

dict((geodata.to_json(True)))
{u’callback’: None,

 u'column_names': [u'type', u'coordinates'],
u'data': {u'coordinates': [[[5.595422739518895, 46.574661252730515],
[5.5868864112024, 46.578124834208275],
[5.566460487135743, 46.579404434922125],
[5.558571581276076, 46.580572027975954],
[5.561819437593718, 46.587949918898076],
[5.575191603674612, 46.59190224479517],
[5.580673541265257, 46.59754467932337],
[5.582347290927083, 46.60141691853218],
[5.587289521318402, 46.59292683804338],
[5.604997996100999, 46.58938109997026],
[5.611508140899815, 46.5826199806949],
[5.603671590915408, 46.57586134356789],
[5.595422739518895, 46.574661252730515]]],
u'type': u'Polygon'},
u'geojson': None,
u'id': u'5a68c30f-9c17-49aa-a0c1-9fc51914d9d0',
u'name': None,
u'selected': {u'0d': {u'glyph': None, u'indices': []},
u'1d': {u'indices': []},
u'2d': {u'indices': []}},
u'tags': []}

``

then I patch it into a figure :

p = figure()

p.patches(source=geodata)

output_file(“geojson.html”)

show§

But I got a Javascript error :

``

The part of the JS where it fails is here :
.prototype.geojson_to_column_data = function() {

var t, e, r, n, o, i, s, a, l, u, c, h, p, _, d, f;

if (n = JSON.parse(this.get(“geojson”)),

“GeometryCollection” !== (d = n.type) && “FeatureCollection” !== d)

throw new Error(“Bokeh only supports type GeometryCollection and FeatureCollection at top level”);

if (“GeometryCollection” === n.type) {

if (null == n.geometries)

throw new Error(“No geometries found in GeometryCollection”);

if (0 === n.geometries.length)

throw new Error(“geojson.geometries must have one or more items”);

l = n.geometries

}

``

How can I patch a pandas serie of geoshape ?

I have the same issue, were you able to figure this out ?

···

On Thursday, July 7, 2016 at 6:13:03 PM UTC-4, Romain Jouin wrote:

I have a pandas dataframe with a column of geoshapes That I would like to display on a map.
Here is the panda series :

``

df.geo_shape[1]
‘{“type”: “Polygon”, “coordinates”: [[[6.728855014402648, 48.1826428129768], [6.727148434879513, 48.18556129472969], [6.710527883652117, 48.18980540566836], [6.712004081624399, 48.198532676335226], [6.742612281822289, 48.20036752133914], [6.746955379591678, 48.190564047365754], [6.742731763437623, 48.18495991879576], [6.728855014402648, 48.1826428129768]]]}’



``

as the geo shape come as a string I eval it and give it to a geoJSONDataSource :

geodata = GeoJSONDataSource(ast.literal_eval(df.geo_shape[0]))

dict((geodata.to_json(True)))
{u’callback’: None,

 u'column_names': [u'type', u'coordinates'],
u'data': {u'coordinates': [[[5.595422739518895, 46.574661252730515],
[5.5868864112024, 46.578124834208275],
[5.566460487135743, 46.579404434922125],
[5.558571581276076, 46.580572027975954],
[5.561819437593718, 46.587949918898076],
[5.575191603674612, 46.59190224479517],
[5.580673541265257, 46.59754467932337],
[5.582347290927083, 46.60141691853218],
[5.587289521318402, 46.59292683804338],
[5.604997996100999, 46.58938109997026],
[5.611508140899815, 46.5826199806949],
[5.603671590915408, 46.57586134356789],
[5.595422739518895, 46.574661252730515]]],
u'type': u'Polygon'},
u'geojson': None,
u'id': u'5a68c30f-9c17-49aa-a0c1- 9fc51914d9d0',
u'name': None,
u'selected': {u'0d': {u'glyph': None, u'indices': []},
u'1d': {u'indices': []},
u'2d': {u'indices': []}},
u'tags': []}

``

then I patch it into a figure :

p = figure()

p.patches(source=geodata)

output_file(“geojson.html”)

show§

But I got a Javascript error :

``

The part of the JS where it fails is here :
.prototype.geojson_to_column_data = function() {

var t, e, r, n, o, i, s, a, l, u, c, h, p, _, d, f;

if (n = JSON.parse(this.get(“geojson”)),

“GeometryCollection” !== (d = n.type) && “FeatureCollection” !== d)

throw new Error(“Bokeh only supports type GeometryCollection and FeatureCollection at top level”);

if (“GeometryCollection” === n.type) {

if (null == n.geometries)

throw new Error(“No geometries found in GeometryCollection”);

if (0 === n.geometries.length)

throw new Error(“geojson.geometries must have one or more items”);

l = n.geometries

}

``

How can I patch a pandas serie of geoshape ?