首页 > 编程语言 > 详细

python生成shp文件

时间:2020-07-16 17:56:56      阅读:187      评论:0      收藏:0      [点我收藏+]

创建点的代码:

# _*_ coding: utf-8 _*_
__author__ = ‘xbr‘
__date__ = ‘2018/11/4 23:17‘
 
from osgeo import ogr
import matplotlib.pyplot as plt
 
from ospybook.vectorplotter import VectorPlotter
 
point = ogr.Geometry(ogr.wkbPoint)  # 构建几何类型:点
point.AddPoint(59.5, 11.5)          # 创建点01
x, y = point.GetX(), point.GetY()   # Python的任性赋值方式
# 调用VectorPlotter类
vp = VectorPlotter(True)
vp.plot(point, ‘bo‘)      # 画出蓝色圆点
point.AddPoint(59.5, 13)  # 在点01基础上添加点02
vp.plot(point, ‘rs‘)      # 画出红色方点
 
plt.show()   # 少了这句话则图像不显示

创建线的代码:

# _*_ coding: utf-8 _*_
__author__ = ‘xbr‘
__date__ = ‘2018/11/4 23:25‘
 
from osgeo import ogr
import matplotlib.pyplot as plt
 
from ospybook.vectorplotter import VectorPlotter
 
line = ogr.Geometry(ogr.wkbLineString)  # 构建几何类型:线
line.AddPoint(54, 37)      # 添加点01
line.AddPoint(62, 35.5)    # 添加点02
line.AddPoint(70.5, 38)    # 添加点03
line.AddPoint(74.5, 41.5)  # 添加点04
# 调用VectorPlotter类
vp = VectorPlotter(True)
vp.plot(line, ‘r-‘)
 
plt.show()   # 少了这句话则图像不显示

创建多边形的代码:

# _*_ coding: utf-8 _*_
__author__ = ‘xbr‘
__date__ = ‘2018/11/4 23:33‘
 
from osgeo import ogr
import matplotlib.pyplot as plt
 
from ospybook.vectorplotter import VectorPlotter
 
ring = ogr.Geometry(ogr.wkbLinearRing)  # 构建几何类型:线
ring.AddPoint(58, 38.5)  # 添加点01
ring.AddPoint(53, 6)     # 添加点02
ring.AddPoint(99.5, 19)  # 添加点03
ring.AddPoint(73, 42)    # 添加点04
yard = ogr.Geometry(ogr.wkbPolygon)  # 构建几何类型:多边形
yard.AddGeometry(ring)
yard.CloseRings()
# 调用VectorPlotter类
vp = VectorPlotter(True)
vp.plot(yard, fill=False, edgecolor=‘blue‘)
ring = yard.GetGeometryRef(0)
for i in range(ring.GetPointCount()):
    ring.SetPoint(i, ring.GetX(i) - 5, ring.GetY(i))
vp.plot(yard, fill=False, ec=‘red‘, linestyle=‘dashed‘)
plt.show()   # 少了这句话则图像不显示

 

python生成shp文件

原文:https://www.cnblogs.com/raorao1994/p/13323435.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!