如何让 folium 接受似乎导致此错误的 geoJSON 输入?
尝试制作等值线地图并遇到相同的错误,因此尝试仅使用我通过获取较大 geoJSON 文件的子集创建的 JSON 文件在基本大叶地图上进行 geoJSON 覆盖。在 Juypter Notebook 中工作。JSON 文件似乎具有正确的结构。
msp_map = folium.Map(location=[纬度,经度],zoom_start=10)
folium.GeoJson(msp_zipcode_geo, name='geojson').add_to(msp_map)
msp_map
AttributeError Traceback(最近一次调用)~/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不是 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 返回 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 """渲染元素的 HTML 表示。""" 320 表示名称,孩子在 self ._children.items(): --> 321 child.render(**kwargs) 322 返回 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 如果脚本不是 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返回 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 """这个方法正在被异步实现。""" --> 579 rv = self._func(*arguments) 580 if autoescape: 581 rv = Markup(rv)
在宏中(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 尝试:--> 262 return __obj(*args, **kwargs) 263 除了 StopIteration: 264 return __self.environment.undefined('值未定义,因为'
~/conda/lib/python3.6/site-packages/folium/features.py in style_data(self) 563 564 for 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' 对象没有属性 'setdefault'
期望获得带有 geoJSON 文件中指定的县边界覆盖的地图。
发现数据的 key_on 列中存在数据类型不匹配,其中在 geoJSON 文件中它是字符串类型,而在数据集文件中它是 int64。转换数据集文件更容易,并为 geoJSON 集中的每个多边形生成具有正确颜色范围的等值线。
还发现我作为更大的 geoJSON 文件的子集创建的 geoJSON 文件的不同之处在于,我将一些数据存储为 dict,而它应该是列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句