創建點的代碼:
# _*_ 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() # 少了這句話則圖像不顯示