python生成shp文件


創建點的代碼:

# _*_ 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.511.5)          # 創建點01
x, y = point.GetX(), point.GetY()   # Python的任性賦值方式
# 調用VectorPlotter類
vp = VectorPlotter(True)
vp.plot(point, 'bo')      # 畫出藍色圓點
point.AddPoint(59.513)  # 在點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(5437)      # 添加點01
line.AddPoint(6235.5)    # 添加點02
line.AddPoint(70.538)    # 添加點03
line.AddPoint(74.541.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(5838.5)  # 添加點01
ring.AddPoint(536)     # 添加點02
ring.AddPoint(99.519)  # 添加點03
ring.AddPoint(7342)    # 添加點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()   # 少了這句話則圖像不顯示

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM