网站建设工,标书制作的六步骤,响应式网站是指自适应吗,做电子元器件的网站安装
pip install pyshp
引入
import shapefile读取
sfshapefile.Reader({路径名},encodingutf-8) # 仅仅读取
shapes与shape
shapessf.shapes() 返回值是一个列表#xff0c;包含该文件中所有的”几何数据”对象shapesf.shape(0) Shape是第1个”几何数据”…安装
pip install pyshp
引入
import shapefile读取
sfshapefile.Reader({路径名},encodingutf-8) # 仅仅读取
shapes与shape
shapessf.shapes() 返回值是一个列表包含该文件中所有的”几何数据”对象shapesf.shape(0) Shape是第1个”几何数据”对象shapeType返回集合类型
返回第1个对象的数据类型属性 几何类型NULL 0POINT 1POLYLINE 3POLYGON 5MULTIPOINT 8POINTZ 11POLYLINEZ 13POLYGONZ 15MULTIPOINTZ 18POINTM 21POLYLINEM 23POLYGONM 25MULTIPOINTM 28MULTIPATCH 31print(shape.shapeType)bbox 返回数据范围
shape.bbox 返回第一个集合对象的数据范围(左下角的xy坐标和右上角的xy坐标)points 所有坐标点
shape.points 返回第一个集合对象的所有坐标点parts 返回’块’的第一个点坐标
shape.parts 返回第一个对象的每个”块”的第一个点坐标records与record
获取属性列表
records
获取属性列表是个函数
sf.records();
返回的值是个listrecord
获取一条数据
sf.record(0)
返回的值是classshapeRecords
同时获取record和shape
# 同时读取geometry and records
sf.shapeRecords()
获取所有
redsf.shapeRecords()[0] #获取第一条数据
print(red.record) #获取record
print(red.shape) #获取shapefields
获取shp文件属性字段
print(sf.fields)[(DeletionFlag, C, 1, 0), [OBJECTID, N, 9, 0], [BSM, C, 12, 0], [PXZQDM, C, 2, 0], [PXZQMC, C, 50, 0]]写入
import shapefile
outshp a.shplandlist[ 84.60212,45.03658,84.60794,45.03938,84.61473,45.04151,84.62442,45.04375,84.62727,45.03632,84.63939,45.0367,84.64906,45.03277,84.63886,45.02233,84.58063,45.05523,84.57974,45.04717,84.59864,45.04792,84.60078,45.05523,84.58758,45.05473,84.58223,45.05523
]
def tramform(lat_lng):str lat_lngstr str.split(,)arr []for i in range(len(str) - 1):# 第一列第二列作为经纬度xy创建点if i % 2 0:arr.append([float(str[i]), float(str[i 1])])return arr
fileWrite shapefile.Writer(create/1.shp,encodingutf-8) # 新建数据存放位置# shp文件属性字段 Fid,Shape会自动生成。
fileWrite.field(landid)
fileWrite.field(landName)for i in range(len(landlist)):# 第一步塞入形状## 这个形状指的就是那些点的集合## 由于源码中要求的输入是列表因此就算只塞入一个也要套一个列表arr[]arrtramform(landlist[i])#[[84.60212, 45.03658], [84.60794, 45.03938], [84.61473, 45.04151], [84.62442, 45.04375], [84.62727, 45.03632], [84.63939, 45.0367], [84.64906, 45.03277], [84.63886, 45.02233]]#poly 写入面点线面使用不同函数fileWrite.poly([arr])# 第二步塞入属性值fileWrite.record(str(i), 地块)
# 保存结束
fileWrite.close()