Reputation: 21
How do I get folium to accept geoJSON input which seems to be causing this error?
Trying to do a choropleth map and got the same error so tried to just do a geoJSON overlay on a basic folium map with JSON file I created by taking a subset of a larger geoJSON file. Working in Juypter Notebook. JSON file appears to have correct structure.
msp_map = folium.Map(location=[latitude, longitude], zoom_start=10)
folium.GeoJson( msp_zipcode_geo, name='geojson' ).add_to(msp_map)
msp_map
AttributeError Traceback (most recent call last) ~/conda/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj) 343 method = get_real_method(obj, self.print_method) 344 if method is not None: --> 345 return method() 346 return None 347 else:
~/conda/lib/python3.6/site-packages/folium/map.py in _repr_html_(self, **kwargs) 249 self._parent = None 250 else: --> 251 out = self._parent._repr_html_(**kwargs) 252 return out 253
~/conda/lib/python3.6/site-packages/branca/element.py in _repr_html_(self, **kwargs) 326 327 """ --> 328 html = self.render(**kwargs) 329 html = "data:text/html;charset=utf-8;base64," + base64.b64encode(html.encode('utf8')).decode('utf8') # noqa 330
~/conda/lib/python3.6/site-packages/branca/element.py in render(self, **kwargs) 319 """Renders the HTML representation of the element.""" 320 for name, child in self._children.items(): --> 321 child.render(**kwargs) 322 return self._template.render(this=self, kwargs=kwargs) 323
~/conda/lib/python3.6/site-packages/folium/map.py in render(self, **kwargs) 336 ''), name='map_style') 337 --> 338 super(LegacyMap, self).render(**kwargs) 339 340
~/conda/lib/python3.6/site-packages/branca/element.py in render(self, **kwargs) 631 632 for name, element in self._children.items(): --> 633 element.render(**kwargs)
~/conda/lib/python3.6/site-packages/branca/element.py in render(self, **kwargs) 627 script = self._template.module.dict.get('script', None) 628 if script is not None: --> 629 figure.script.add_child(Element(script(self, kwargs)), 630 name=self.get_name()) 631
~/conda/lib/python3.6/site-packages/jinja2/runtime.py in call(self, *args, **kwargs) 573 (self.name, len(self.arguments))) 574 --> 575 return self._invoke(arguments, autoescape) 576 577 def _invoke(self, arguments, autoescape):
~/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py in _invoke(self, arguments, autoescape) 108 def _invoke(self, arguments, autoescape): 109 if not self._environment.is_async: --> 110 return original_invoke(self, arguments, autoescape) 111 return async_invoke(self, arguments, autoescape) 112 return update_wrapper(_invoke, original_invoke)
~/conda/lib/python3.6/site-packages/jinja2/runtime.py in _invoke(self, arguments, autoescape) 577 def _invoke(self, arguments, autoescape): 578 """This method is being swapped out by the async implementation.""" --> 579 rv = self._func(*arguments) 580 if autoescape: 581 rv = Markup(rv)
in macro(l_1_this, l_1_kwargs)
~/conda/lib/python3.6/site-packages/jinja2/runtime.py in call(_Context__self, _Context__obj, *args, **kwargs) 260 args = (__self.environment,) + args 261 try: --> 262 return __obj(*args, **kwargs) 263 except StopIteration: 264 return __self.environment.undefined('value was undefined because '
~/conda/lib/python3.6/site-packages/folium/features.py in style_data(self) 563 564 for feature in self.data['features']: --> 565 feature.setdefault('properties', {}).setdefault('style', {}).update(self.style_function(feature)) # noqa 566 feature.setdefault('properties', {}).setdefault('highlight', {}).update(self.highlight_function(feature)) # noqa 567 return json.dumps(self.data, sort_keys=True)
AttributeError: 'str' object has no attribute 'setdefault'
Expecting to get map with overlay of county borders as specified in geoJSON file.
Upvotes: 0
Views: 1930
Reputation: 21
Figured out there was a data type mismatch in the key_on column of data where in the geoJSON file it was string type and in the data set file it was int64. Converting data set file was easier and produced choropleth with the right color range for each polygon in the geoJSON set.
Also figured out that geoJSON file I'd created as a subset of larger geoJSON file was different in that I'd stored some data as dict when it should have been list.
Upvotes: 1