通過pyshp庫,可以讀寫shapefile文件,查詢相關信息,github地址為
import shapefile # 使用pyshp庫
file = shapefile.reader("data\\市界.shp")
shapes = file.shapes()
#
print(file.shapetype) # 輸出shp類型
'''
null = 0
point = 1
polyline = 3
polygon = 5
multipoint = 8
pointz = 11
polylinez = 13
polygonz = 15
multipointz = 18
pointm = 21
polylinem = 23
polygonm = 25
multipointm = 28
multipatch = 31
'''
print(file.bbox) # 輸出shp的范圍
#
# print(shapes[1].parts)
# print(len(shapes)) # 輸出要素數量
# print(file.numrecords) # 輸出要素數量
# print(file.records()) # 輸出所有屬性表
#
'''
字段類型:此列索引處的數據類型。類型可以是:
“c”:字符,文字。
“n”:數字,帶或不帶小數。
“f”:浮動(與“n”相同)。
“l”:邏輯,表示布爾值true / false值。
“d”:日期。
“m”:備忘錄,在gis中沒有意義,而是xbase規范的一部分。
'''
# fields = file.fields
# print(fields)
#
#
for index in range(len(shapes)):
geometry = shapes[index]
# print(geometry.shapetype)
# print(geometry.points)
#
以上這篇python使用pyshp庫讀取shapefile信息的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持萬仟網。
如您對本文有疑問或者有任何想說的,請點擊進行留言回復,萬千網友為您解惑!