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 相关文章推荐
TensorFlow实现非线性支持向量机的实现方法
Apr 28 Python
python爬虫之自动登录与验证码识别
Jun 15 Python
Python实现微信小程序支付功能
Jul 25 Python
详解PyTorch手写数字识别(MNIST数据集)
Aug 16 Python
python爬虫添加请求头代码实例
Dec 28 Python
基于Python数据分析之pandas统计分析
Mar 03 Python
python matplotlib实现将图例放在图外
Apr 17 Python
Python 跨.py文件调用自定义函数说明
Jun 01 Python
基于Python爬取京东双十一商品价格曲线
Oct 23 Python
解决python3.x安装numpy成功但import出错的问题
Nov 17 Python
装上这 14 个插件后,PyCharm 真的是无敌的存在
Jan 11 Python
Python中的socket网络模块介绍
Jul 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 全角转半角实现代码
2010/05/16 PHP
新浪SAE云平台下使用codeigniter的数据库配置
2014/06/12 PHP
PHP中使用Imagick实现各种图片效果实例
2015/01/21 PHP
php二维数组合并及去重复的方法
2015/03/04 PHP
phpstorm 正则匹配删除空行、注释行(替换注释行为空行)
2018/01/21 PHP
PHP的RSA加密解密方法以及开发接口使用
2018/02/11 PHP
PHP实现数组向任意位置插入,删除,替换数据操作示例
2019/04/05 PHP
prettify 代码高亮着色器google出品
2010/12/28 Javascript
Javascript递归打印Document层次关系实例分析
2015/05/15 Javascript
基于zepto的移动端轻量级日期插件--date_picker
2016/03/04 Javascript
全面了解addEventListener和on的区别
2016/07/14 Javascript
Bootstrap popover用法详解
2016/12/22 Javascript
js前端日历控件(悬浮、拖拽、自由变形)
2017/03/02 Javascript
详解webpack编译多页面vue项目的配置问题
2017/12/11 Javascript
layer扩展打开/关闭动画的方法
2019/09/23 Javascript
js中关于Blob对象的介绍与使用
2019/11/29 Javascript
JS实现音乐钢琴特效
2020/01/06 Javascript
js实现星星打分效果
2020/07/05 Javascript
实用的 vue tags 创建缓存导航的过程实现
2020/12/03 Vue.js
[00:27]DOTA2荣耀之路2:Patience from zhou!
2018/05/24 DOTA
linux下python抓屏实现方法
2015/05/22 Python
神经网络python源码分享
2017/12/15 Python
python实现监控阿里云账户余额功能
2019/12/16 Python
基于pytorch 预训练的词向量用法详解
2020/01/06 Python
Python selenium 自动化脚本打包成一个exe文件(推荐)
2020/01/14 Python
python中setuptools的作用是什么
2020/06/19 Python
Expected conditions模块使用方法汇总代码解析
2020/08/13 Python
英国排名第一的最新设计师品牌手表独立零售商:TIC Watches
2016/09/24 全球购物
琳达·法罗眼镜英国官网:Linda Farrow英国
2021/01/19 全球购物
J2EE模式面试题
2016/10/11 面试题
项目资料员岗位职责
2013/12/10 职场文书
初中优秀班集体申报材料
2014/05/01 职场文书
小学生教师节广播稿
2015/08/19 职场文书
python神经网络编程之手写数字识别
2021/05/08 Python
解决pytorch 损失函数中输入输出不匹配的问题
2021/06/05 Python
在HTML中引入CSS的几种方式介绍
2021/12/06 HTML / CSS