Python中shapefile转换geojson的示例


Posted in Python onJanuary 03, 2019

shapefile转换geojson

import shapefile
import codecs
from json import dumps
# read the shapefile
def shp2geo(file="line出产.shp"):
  reader = shapefile.Reader(file)
  fields = reader.fields[1:]
  field_names = [field[0] for field in fields]
  buffer = []
  for sr in reader.shapeRecords():
    record = sr.record
    record = [r.decode('gb2312', 'ignore') if isinstance(r, bytes)
         else r for r in record]
    atr = dict(zip(field_names, record))
    geom = sr.shape.__geo_interface__
    buffer.append(dict(type="Feature", geometry=geom, properties=atr))
    # write the GeoJSON file
  geojson = codecs.open(file.split('.')[0] + "-geo.json", "w", encoding="gb2312")
  geojson.write(dumps({"type": "FeatureCollection", "features": buffer}, indent=2) + "\n")
  geojson.close()
if __name__ == '__main__':
  # import os
  # for z,x,c in os.walk('.'):
  #   for zz in c:
  #     if zz.endswith(".shp"):
  #       shp2geo(zz)
  # shp2geo(file='D.shp')
  shp2geo(file='ttttttttttt.shp')

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对三水点靠木的支持。如果你想了解更多相关内容请查看下面相关链接

Python 相关文章推荐
使用70行Python代码实现一个递归下降解析器的教程
Apr 17 Python
修改Python的pyxmpp2中的主循环使其提高性能
Apr 24 Python
在Python中将函数作为另一个函数的参数传入并调用的方法
Jan 22 Python
Python增强赋值和共享引用注意事项小结
May 28 Python
Pandas之ReIndex重新索引的实现
Jun 25 Python
对Django中内置的User模型实例详解
Aug 16 Python
python中用logging实现日志滚动和过期日志删除功能
Aug 20 Python
python爬虫-模拟微博登录功能
Sep 12 Python
关于Pytorch的MNIST数据集的预处理详解
Jan 10 Python
python中return如何写
Jun 18 Python
K近邻法(KNN)相关知识总结以及如何用python实现
Jan 28 Python
python可视化大屏库big_screen示例详解
Nov 23 Python
Python关于excel和shp的使用在matplotlib
Jan 03 #Python
Python使用folium excel绘制point
Jan 03 #Python
Python获取航线信息并且制作成图的讲解
Jan 03 #Python
Python中GeoJson和bokeh-1的使用讲解
Jan 03 #Python
Python图像滤波处理操作示例【基于ImageFilter类】
Jan 03 #Python
python 调用有道api接口的方法
Jan 03 #Python
对python调用RPC接口的实例详解
Jan 03 #Python
You might like
php正则表达式使用的详细介绍
2013/04/27 PHP
ajax+php控制所有后台函数调用
2015/07/15 PHP
Thinkphp无限级分类代码
2015/11/11 PHP
PHPExcel中文帮助手册|PHPExcel使用方法(分享)
2017/06/09 PHP
解决Laravel5.5下的toArray问题
2019/10/15 PHP
ECMAScript 基础知识
2007/06/29 Javascript
window.open关于浏览器拦截问题分析及解决方法
2013/02/05 Javascript
js定时器的使用(实例讲解)
2014/01/06 Javascript
将HTML格式的String转化为HTMLElement的实现方法
2014/08/07 Javascript
jQuery实现选中弹出窗口选择框内容后赋值给文本框的方法
2015/11/23 Javascript
JQuery插件Marquee.js实现无缝滚动效果
2016/04/26 Javascript
JS实现旋转木马式图片轮播效果
2017/01/18 Javascript
原生js实现鼠标跟随效果
2017/02/28 Javascript
angular2 ng build部署后base文件路径问题详细解答
2017/07/15 Javascript
javaScript实现复选框全选反选事件详解
2020/11/20 Javascript
JavaScript如何实现元素全排列实例代码
2019/05/14 Javascript
vue中在vuex的actions中请求数据实例
2019/11/08 Javascript
JS实现多选框的操作
2020/06/24 Javascript
基于vue--key值的特殊用处详解
2020/07/31 Javascript
[10:21]2018DOTA2国际邀请赛寻真——Winstrike
2018/08/11 DOTA
Python中用字符串调用函数或方法示例代码
2017/08/04 Python
Python 多个图同时在不同窗口显示的实现方法
2019/07/07 Python
django数据关系一对多、多对多模型、自关联的建立
2019/07/24 Python
Python创建一个元素都为0的列表实例
2019/11/28 Python
Python3的socket使用方法详解
2020/02/18 Python
python中的对数log函数表示及用法
2020/12/09 Python
CSS3中的注音对齐属性ruby-align用法指南
2016/07/01 HTML / CSS
《三峡》教学反思
2014/03/01 职场文书
研究生毕业自我鉴定范文
2014/03/27 职场文书
个人收入证明范本
2014/09/18 职场文书
房屋转让协议书
2014/10/18 职场文书
初中班主任心得体会
2016/01/07 职场文书
导游词之太原天龙山
2020/01/02 职场文书
Nginx的rewrite模块详解
2021/03/31 Servers
python3.9之你应该知道的新特性详解
2021/04/29 Python
Nginx图片服务器配置之后图片访问404的问题解决
2022/03/21 Servers