python从shp文件中读取经纬度数据

python从shp文件中读取经纬度数据

没有接触过GIS的人来说shp文件很陌生而且很难打开查看,好在python可以从中提取出自己想要的数据

pyshp库的安装

python的pyshp库可以实现shp文件的读写功能。
pyshp的官方文档:https://pypi.org/project/pyshp/2.1.0/#overview
pyshp的GitHub主页:https://github.com/GeospatialPython/pyshp

安装pyshp可以用conda也可以用pip
conda install pyshp

查看shp文件属性

首先导入pyshp库,读取shp文件,然后就可以查看属性列表和属性值了

import shapefile
file = shapefile.Reader("shp_file_path.shp")
file.fields 
file.shapeRecords()

读取shp文件数据

shp文件可以包含有很多属性的数据,例如“point”点,“polyline”线,“polygon”多边形,等等
我们可以使用以下命令读取polyline线条的经纬度:

import numpy as np 
shape_records = file.shapeRecords()
for record in shape_records:
    points = shape_record.shape.points
    parts  = shape_record.shape.parts
    print(points[parts[-1]:])

对于其他属性可以参考这篇https://blog.csdn.net/u014523388/article/details/113041826

posted @ 2023-04-12 09:52  Philbert  阅读(877)  评论(0编辑  收藏  举报