Python中GeoJson和bokeh-1的使用讲解

yipeiwu_com5年前Python基础

GeoJson 文档

{
 "type": "FeatureCollection",
 "features": [
  {
   "geometry": {
    "type": "Polygon",
    "coordinates": [
     [
      [
       3,
       1
      ],
      [
       3,
       2
      ],
      [
       4,
       2
      ],
      [
       4,
       1
      ],
      [
       3,
       1
      ]
     ]
    ]
   },
   "type": "Feature",
   "properties": {
    "perimeter": 0,
    "vista": "mim",
    "provincia": "右侧正方形",
    "objectid": 24,
    "prov": 0,
    "bounds": [
     0,
     0
    ],
    "provif3_": 27.0,
    "ogc_fid": 26,
    "provif3_id": 26.0
   }
  },
  {
   "geometry": {
    "type": "Polygon",
    "coordinates": [
     [
      [
       1,
       1
      ],
      [
       1,
       2
      ],
      [
       2,
       2
      ],
      [
       2,
       1
      ],
      [
       1,
       1
      ]
     ]
    ]
   },
   "type": "Feature",
   "properties": {
    "perimeter": 0,
    "vista": "mim",
    "provincia": "左侧正方形",
    "objectid": 24,
    "prov": 0,
    "bounds": [
     0,
     0
    ],
    "provif3_": 27.0,
    "ogc_fid": 26,
    "provif3_id": 26.0
   }
  }
 ]
}
from bokeh.io import show, output_notebook, output_file
from bokeh.models import (
  GeoJSONDataSource,
  HoverTool,
  LinearColorMapper
)
from bokeh.plotting import figure
from bokeh.palettes import Viridis6
with open(r'argentina.json', 'r', encoding='utf8') as f:
  geo_source = GeoJSONDataSource(geojson=f.read())
color_mapper = LinearColorMapper(palette=Viridis6)
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
p = figure(title="正方形", tools=TOOLS, x_range=[1, 10], y_range=[1, 10], width=500, height=500)
p.grid.grid_line_color = None
p.patches('xs', 'ys', fill_alpha=0.7, fill_color={'field': 'objectid', 'transform': color_mapper},
     line_color='white', line_width=0.5, source=geo_source)
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [("Provincia:", "@provincia")]
output_file("test.html", title="Testing Polygon in bokeh")
show(p)

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对【听图阁-专注于Python设计】的支持。如果你想了解更多相关内容请查看下面相关链接

相关文章

一篇文章搞定Python操作文件与目录

一篇文章搞定Python操作文件与目录

前言 文件和目录操作是很常见的功能,这里做个简单的总结,包括注意事项和实际的实现代码,基本日常开发都够用了 目录操作 判断目录或是文件是否存在 os.path.exists(p...

hmac模块生成加入了密钥的消息摘要详解

hmac模块生成加入了密钥的消息摘要详解

hmac模块 hmac模块用于生成HMAC码。这个HMAC码可以用于验证消息的完整性,其原理也很简单,就是一种加入了密钥的消息摘要,相比起MAC更加安全。JWT(JSON Web Tok...

python提示No module named images的解决方法

本文讲述了python提示No module named images的解决方法,非常实用!分享给大家供大家参考。具体方法如下: 出现提示:ImportError: No module...

Python 一句话生成字母表的方法

List >>> [chr(i) for i in range(97,123)] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',...

python 读取更新中的log 或其它文本方式

在项目中遇到这个问题,想把本地的log文件通过 Server-Send Event 的形式 发送给前端。 但是如何把那些 新增加log文本 读取出来就成了问题。 想过遍历log文件取得行...