Python使用pyshp库读取shapefile信息

通过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>

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GIS开发者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值