通過pyshp庫,可以讀寫Shapefile文件,查詢相關信息,github地址為
https://github.com/GeospatialPython/pyshp#reading-shapefile-meta-data
import shapefile # 使用pyshp庫 file = shapefile.Reader("data//市界.shp")shapes = file.shapes() # <editor-fold desc="讀取元數據">print(file.shapeType) # 輸出shp類型'''NULL = 0POINT = 1POLYLINE = 3POLYGON = 5MULTIPOINT = 8POINTZ = 11POLYLINEZ = 13POLYGONZ = 15MULTIPOINTZ = 18POINTM = 21POLYLINEM = 23POLYGONM = 25MULTIPOINTM = 28MULTIPATCH = 31'''print(file.bbox) # 輸出shp的范圍# </editor-fold># print(shapes[1].parts)# print(len(shapes)) # 輸出要素數量# print(file.numRecords) # 輸出要素數量# print(file.records()) # 輸出所有屬性表 # <editor-fold desc="輸出字段名稱和字段類型">'''字段類型:此列索引處的數據類型。類型可以是:“C”:字符,文字。“N”:數字,帶或不帶小數。“F”:浮動(與“N”相同)。“L”:邏輯,表示布爾值True / False值。“D”:日期。“M”:備忘錄,在GIS中沒有意義,而是xbase規范的一部分。'''# fields = file.fields# print(fields)# </editor-fold> # <editor-fold desc="輸出幾何信息">for index in range(len(shapes)): geometry = shapes[index] # print(geometry.shapeType) # print(geometry.points)# </editor-fold>以上這篇Python使用pyshp庫讀取shapefile信息的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答