脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python使用pyshp库读取shapefile信息的方法

Python使用pyshp库读取shapefile信息的方法

2021-05-09 00:57GIS小博工作室 Python

今天小编就为大家分享一篇Python使用pyshp库读取shapefile信息的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

通过pyshp库,可以读写Shapefile文件,查询相关信息,github地址为

https://github.com/GeospatialPython/pyshp#reading-shapefile-meta-data

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import shapefile # 使用pyshp库
 
file = shapefile.Reader("data\\市界.shp")
shapes = file.shapes()
 
# <editor-fold desc="读取元数据">
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的范围
# </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信息的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/GISuuser/article/details/81664223

延伸 · 阅读

精彩推荐