python生成shp檔案

2022-03-22 01:03:15 字數 2455 閱讀 1271

建立點的**:

# _*_ coding: utf-8 _*_

__author__ = '

xbr'

__date__ = '

2018/11/4 23:17

'from

osgeo import ogr

import matplotlib.pyplot 

asplt

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 

asplt

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 

asplt

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()   # 少了這句話則影象不顯示

shp檔案及附屬

主檔案 shp 用於儲存要素幾何的主檔案,之前分享過該檔案的結構詳解 必需檔案。shx 用於儲存要素幾何索引的索引檔案 必需檔案。dbf 用於儲存要素屬性資訊的 dbase 表,主要記錄的是屬性資訊,可採用excel等開啟,相當於屬性表 必需檔案。幾何與屬性是一對一關係,這種關係基於記錄編號。dba...

ArcEngine複製shp檔案

在網上找的一些 都沒有實現自己想要的功能,整了兩天,今天把這個功能實現了,用gp工具實現。region 複製shp檔案 copyshp 複製shp檔案 要拷貝檔案的路徑 輸出檔案的路徑 private bool copyshp string sourcefilepath,string destfil...

ArcGIS Engine開啟shp檔案

shp檔案是目前主流的空間資料儲存檔案,ae載入shp檔案可以通過以下兩種方式 通過工作空間載入 通過mapcontrol的addshapefile方法載入shapefile檔案 通過工作空間載入 此方法使用於有複雜空間分析操作的情況 用到的引用 using esri.arcgis.geodatab...