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

作者:GIS小博工作室 时间:2023-07-27 04:56:36 

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

来源:https://blog.csdn.net/GISuuser/article/details/81664223

标签:Python,pyshp,shapefile
0
投稿

猜你喜欢

  • selenium切换标签页解决get超时问题的完整代码

    2023-08-26 09:41:25
  • PHP mysqli扩展库 预处理技术的使用分析

    2023-11-21 07:10:21
  • Nodejs封装类似express框架的路由实例详解

    2024-05-11 10:17:43
  • javascript中的关于类型转换的性能优化

    2023-06-26 16:25:48
  • webstorm中配置nodejs环境及npm的实例

    2024-05-11 10:16:09
  • 垂直栅格与渐进式行距(上)

    2009-04-01 18:30:00
  • Python爬虫实战之虎牙视频爬取附源码

    2021-04-02 01:23:27
  • python爬虫框架talonspider简单介绍

    2021-05-14 06:27:01
  • 使用urllib库的urlretrieve()方法下载网络文件到本地的方法

    2021-11-27 11:21:08
  • 一篇jQuery小教程

    2007-10-15 12:49:00
  • 详解如何运行vue项目

    2024-05-13 09:09:47
  • class和id命名探讨

    2007-10-16 17:55:00
  • 设计提升满意度

    2010-05-16 15:00:00
  • python和shell监控linux服务器的详细代码

    2021-11-09 06:23:22
  • 教你怎么用Python实现自动生日祝福

    2022-04-08 01:03:25
  • Python面向对象程序设计示例小结

    2023-08-24 13:31:24
  • 教你快速掌握如何向MySQL的表中录入数据

    2008-11-27 16:45:00
  • Python中使用PDB库调试程序

    2022-02-24 11:25:49
  • Python使用PyAV提取视频关键帧的实践

    2023-04-29 23:45:04
  • Golang实现常见的限流算法的示例代码

    2024-04-25 13:22:35
  • asp之家 网络编程 m.aspxhome.com