(本文所述软件还在发展之中,欢迎加入开源项目,提供建议、测试和开发。)html
在Jupyter中进行数据分析时,每每须要将数据叠加到地图上。简单的地图需求能够利用matplotlib/echarts/bokeh的地图显示功能,更为复杂的可使用SuperMap/Leaflet/GMaps提供的地图插件,实现交互的地图操做,能够显示和操做大比例尺的专业级地图,甚至调用专业GIS服务进行空间分析,固然这操做起来也会更复杂一些。node
iClientPy是由超图软件公司(http://www.supermap.com)开发的一个开源项目,能够将SuperMap iServer和Online服务经过python API访问,并支持Jupyter的编程和集成化分析。目前该项目还在开发之中,还没有造成发布版本(预计2018年末发布)。项目地址以下:python
因为conda安装国内访问较慢,能够加入镜像站,配置第三方库的依赖源。这里使用清华大学的源(也但是国内其余镜像源):webpack
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ conda config --set show_channel_urls yes
执行下面命令:git
conda install -y -c http://iclientpy.supermap.io/conda/channel iclientpy
目前安装后地图显示不出来,还须要改进。github
ipyleaflet是基于leaflet的地图显示模块,提供了jupyterlab支持。web
安装到jupyterlab,执行:npm
conda install -c conda-forge nodejs=8.10.0 conda install -c conda-forge ipyleaflet jupyter labextension install jupyter-leaflet
一些用户发现须要 jupyterlab-manager,才能显示地图。
查看 issue 173 和 issue 168 了解更多细节。编程
使用命令 jupyter labextension list 查看 jupyter-widgets 是否安装。若是没有,安装方法以下:json
jupyter labextension install @jupyter-widgets/jupyterlab-manager
目前我在Kubernetes里安装jupyterlab,使用的all-in-one-spark的jupyter镜像,可是安装后地图显示不出来,还须要改进。
倒腾了一番后,运行nodejs降级到10如下,运行 jupyter lab build,而后就能够显示了。不过发现,Ubuntu上的 FireFox仍是显示不出来,经过MacOS上的FireFox倒是能够的。
是基于Google Maps的地图显示插件,须要google maps API的访问token。
为了在JupyterLab中使用jupyter-gmaps须要安装 jupyter widgets 扩展。
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager
而后经过pip安装jupyter-gmaps:
$ pip install gmaps
下次启动 JupyterLab时,会提示须要 “rebuild JupyterLab: this is necessary to include the jupyter-gmaps frontend code into your JupyterLab installation”。
在命令行运行:
$ jupyter lab build
由于国内访问网络缘由和须要token,暂时尚未测试过。
jupyter-renderer是jupyter官方的一个渲染架构,用于绘制更多类型的cell输出。
目前GeoJSON已经能够支持用于绘图了,主要是基于leaflet的。
jupyter labextension install @jupyterlab/geojson-extension
jupyter labextension install jupyterlab_velocity
一样的问题,在JupyterLab里图显示不出来。
将MapBox嵌入到Notebook中进行地图显示。参见:
启用nbextension扩展:
!jupyter nbextension enable --py widgetsnbextension --sys-prefix !jupyter nbextension enable --py --sys-prefix ipyleaflet
查看nbextension扩展列表:
!jupyter nbextension list
查看labextension扩展列表:
!jupyter labextension list
最后须要运行 jupyter lab build,才能真正启用扩展。
不过,我在这一步运行时,一直处于运行状态,而后显示地图时也显示不出来,好像提示webpack的“_.extend is not a function”,后面再慢慢研究。
尝试修复bug:
npm i -y leaflet@~1.0.3 npm i -y jupyter-leaflet
将“parallel: true,”改成“parallel: false,”,以下:
ovyan@jupyter-supermap:/opt/conda/share/jupyter/lab/staging$ cat webpack.prod.config.js var UglifyJSPlugin = require('uglifyjs-webpack-plugin'); var merge = require('webpack-merge'); var webpack = require('webpack'); var common = require('./webpack.config'); module.exports = merge(common, { devtool: 'source-map', plugins: [ new UglifyJSPlugin({ sourceMap: true, parallel: true, uglifyOptions: { beautify: false, ecma: 6, mangle: true, compress: false, comments: false, } }), new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }) ] }); jovyan@jupyter-supermap:/opt/conda/share/jupyter/lab/staging$ nano webpack.prod.config.js
对于上面的问题,在互联网上搜索一番无果,而后到 https://github.com/jupyter-widgets/ipyleaflet 上提了个issue,晚上获得了 jasongrout 的回答,说 “Use node version < 10. JupyterLab does not work with node 10 currently.”,而后执行 conda install nodejs=8.10.0 从 10.4.0 降级下来,再安装就ok了。真是“踏遍世界无觅处,得来也需费功夫”,难者不会、会者不难啊!