当前位置: 移动技术网 > IT编程>脚本编程>Python > Python使用pyshp库读取shapefile信息的方法

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

2019年01月04日  | 移动技术网IT编程  | 我要评论

南平市公安局,猪饲料的配方,网校网

通过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 = 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信息的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网