Python 根据数据模板创建shapefile的实现


Posted in Python onNovember 26, 2019

废话不多说,我就直接上代码让大家看看吧!

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : copyShapefile.py
# @Author: huifer
# @Date : 2018-4-28
from os.path import exists

import gdal

from osgeo import ogr
from os import remove

gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES") # 路径中文
gdal.SetConfigOption("SHAPE_ENCODING", "GBK") # 属性中文
in_shapefile = "dataSample/wang_point.shp"# 数据模板
out_shapefile = "shapefileAa.shp" # 输出数据集
in_ds = ogr.Open(in_shapefile) # 读取模板数据
in_lyr = in_ds.GetLayerByIndex(0)
if exists(out_shapefile):
  remove(out_shapefile)
drv = ogr.GetDriverByName("ESRI Shapefile") # 指定数据驱动
out_ds = drv.CreateDataSource(out_shapefile) # 创建数据源
proj = in_lyr.GetSpatialRef() # 获取模板坐标系
out_lyr = out_ds.CreateLayer(out_shapefile.split(".")[0], proj, ogr.wkbPoint)
# copy the schema of the original shapefile to the destination shapefile
lyr_def = in_lyr.GetLayerDefn()
for i in range(lyr_def.GetFieldCount()): # 获取字段长度
  out_lyr.CreateField(lyr_def.GetFieldDefn(i)) # 创建字段
  feature = ogr.Feature(lyr_def)
  wkt = "POINT(88615.730000 75345.486000)"
  point = ogr.CreateGeometryFromWkt(wkt)
  feature.SetGeometry(point)
  # 添加点
  out_lyr.CreateFeature(feature)
  # 关闭 特征
  feature = None
  # 关闭数据
data_source = None

以上这篇Python 根据数据模板创建shapefile的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python字符类型的一些方法小结
May 16 Python
Python内置模块ConfigParser实现配置读写功能的方法
Feb 12 Python
python脚本生成caffe train_list.txt的方法
Apr 27 Python
用Django写天气预报查询网站
Oct 21 Python
Python异步操作MySQL示例【使用aiomysql】
May 16 Python
python把转列表为集合的方法
Jun 28 Python
python 生成器和迭代器的原理解析
Oct 12 Python
Jupyter notebook 启动闪退问题的解决
Apr 13 Python
Python中bisect的用法及示例详解
Jul 20 Python
Python导入父文件夹中模块并读取当前文件夹内的资源
Nov 19 Python
python套接字socket通信
Apr 01 Python
Python图像处理库PIL详细使用说明
Apr 06 Python
Python实现直播推流效果
Nov 26 #Python
Python利用matplotlib绘制约数个数统计图示例
Nov 26 #Python
创建Shapefile文件并写入数据的例子
Nov 26 #Python
python使用opencv在Windows下调用摄像头实现解析
Nov 26 #Python
使用Python实现 学生学籍管理系统
Nov 26 #Python
python redis 批量设置过期key过程解析
Nov 26 #Python
python3 tkinter实现添加图片和文本
Nov 26 #Python
You might like
php cookis创建实现代码
2009/03/16 PHP
让PHP支持断点续传的源码
2010/05/16 PHP
PHP抓取网页、解析HTML常用的方法总结
2015/07/01 PHP
利用PHP获取汉字首字母并且分组排序详解
2017/10/22 PHP
laravel 根据不同组织加载不同视图的实现
2019/10/14 PHP
简述JavaScript对传统文档对象模型的支持
2015/06/16 Javascript
基于jQuery实现的向下滑动二级菜单效果代码
2015/08/31 Javascript
基于AngularJS+HTML+Groovy实现登录功能
2016/02/17 Javascript
JavaScript中循环遍历Array与Map的方法小结
2016/03/12 Javascript
Angular.js与Bootstrap相结合实现手风琴菜单代码
2016/04/13 Javascript
jQuery实现导航回弹效果
2017/02/27 Javascript
Javascript实现基本运算器
2017/07/15 Javascript
Node使用Nodemailer发送邮件的方法实现
2020/02/24 Javascript
vue中全局路由守卫中替代this操作(this.$store/this.$vux)
2020/07/24 Javascript
基于ajax实现上传图片代码示例解析
2020/12/03 Javascript
Python中文竖排显示的方法
2015/07/28 Python
使用python实现接口的方法
2017/07/07 Python
Python 获取当前所在目录的方法详解
2017/08/02 Python
Django时区详解
2019/07/24 Python
Python 变量的创建过程详解
2019/09/02 Python
Pytorch使用MNIST数据集实现基础GAN和DCGAN详解
2020/01/10 Python
python装饰器实现对异常代码出现进行自动监控的实现方法
2020/09/15 Python
Python中对象的比较操作==和is区别详析
2021/02/12 Python
Feelunique澳大利亚:欧洲的化妆品零售电商
2019/12/18 全球购物
计算机软件个人的自荐信范文
2013/12/01 职场文书
战友聚会邀请函
2014/01/18 职场文书
大学理论知识学习自我鉴定
2014/04/28 职场文书
中秋节活动总结
2014/08/29 职场文书
暑期学习心得体会
2014/09/02 职场文书
关于运动会的广播稿
2014/09/22 职场文书
开展党的群众路线教育实践活动工作总结
2014/11/05 职场文书
2015年个人实习工作总结
2014/12/12 职场文书
2015年驾驶员工作总结
2015/04/29 职场文书
2015年体育教师个人工作总结
2015/05/12 职场文书
赞助商致辞
2015/07/30 职场文书
化工厂员工工作总结
2015/10/15 职场文书