JupyterLab安装地图插件

JupyterLab安装地图插件

(本文所述软件还在发展之中,欢迎加入开源项目,提供建议、测试和开发。)

Jupyter中进行数据分析时,往往需要将数据叠加到地图上。简单的地图需求可以利用matplotlib/echarts/bokeh的地图显示功能,更为复杂的可以使用SuperMap/Leaflet/GMaps提供的地图插件,实现交互的地图操作,可以显示和操作大比例尺的专业级地图,甚至调用专业GIS服务进行空间分析,当然这操作起来也会更复杂一些。

1、iClientPy

iClientPy是由超图软件公司(http://www.supermap.com)开发的一个开源项目,可以将SuperMap iServer和Online服务通过python API访问,并支持Jupyter的编程和集成化分析。目前该项目还在开发之中,尚未形成发布版本(预计2018年底发布)。项目地址如下:

 

  • fef5c7fc8432d48c46adc54486918a94d69.jpg

由于conda安装国内访问较慢,可以加入镜像站,配置第三方库的依赖源。这里使用清华大学的源(也可是国内其他镜像源):

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

执行下面命令:

conda install -y -c http://iclientpy.supermap.io/conda/channel iclientpy

目前安装后地图显示不出来,还需要改进。

2、ipyleaflet

ipyleaflet是基于leaflet的地图显示模块,提供了jupyterlab支持。

安装到jupyterlab,执行:

conda install -c conda-forge nodejs=8.10.0

conda install -c conda-forge ipyleaflet
jupyter labextension install jupyter-leaflet

一些用户发现需要 jupyterlab-manager,才能显示地图。 查看 issue 173issue 168 了解更多细节。

使用命令 jupyter labextension list 查看 jupyter-widgets 是否安装。如果没有,安装方法如下:

jupyter labextension install @jupyter-widgets/jupyterlab-manager

目前我在Kubernetes里安装jupyterlab,使用的all-in-one-spark的jupyter镜像,但是安装后地图显示不出来,还需要改进。

倒腾了一番后,运行nodejs降级到10以下,运行 jupyter lab build,然后就可以显示了。不过发现,Ubuntu上的 FireFox还是显示不出来,通过MacOS上的FireFox却是可以的。

3、gmaps

是基于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,暂时还没有测试过。

4、jupyter-renderer

jupyter-renderer是jupyter官方的一个渲染架构,用于绘制更多类型的cell输出。

目前GeoJSON已经可以支持用于绘图了,主要是基于leaflet的。

jupyter labextension install @jupyterlab/geojson-extension
jupyter labextension install jupyterlab_velocity

同样的问题,在JupyterLab里图显示不出来。

5、MapBox

将MapBox嵌入到Notebook中进行地图显示。参见:

6、查看安装信息

启用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了。真是“踏遍世界无觅处,得来也需费功夫”,难者不会、会者不难啊!

转载于:https://my.oschina.net/u/2306127/blog/1859080

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值