对python 读取线的shp文件实例详解

yipeiwu_com5年前Python基础

如下所示:

import shapefile
sf = shapefile.Reader("E:\\1.2\\cs\\DX_CSL.shp")
shapes = sf.shapes()
print shapes[1].parts
print len(shapes) #79条记录
#print len(list(sf.iterShapes())) #79条记录
#for name in dir(shapes[3]): #不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表
 #       if not name.startswith('__'):
 #           print  name


print sf.numRecords
recds = sf.records()
for i in range(sf.numRecords):
    rcd = sf.record(i)
    #sp = rcd.shape 没有shape属性
    #print sp.points
#recds.shape
#读取记录
print sf.shapeRecord(1).shape.shapeType
print sf.shapeRecord(1).record
print sf.fields


print ''          
for shp in range(len(shapes)):
    shap = shapes[shp]
    print shap.points
    print shap.shapeType
    print len(shap.points)
    for i in range(len(shap.points)):
        print shap.points[i]
        for x in range(len(shap.points[i])):
            print shap.points[i][x]

以上这篇对python 读取线的shp文件实例详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

值得收藏的10道python 面试题

值得收藏的10道python 面试题

Q1:PEP8是什么?Python之禅(import this)是什么? 这题是考察你对编码规范的认识,无论是自己写代码还是在团队中写代码,了解并遵循代码规范是很基础的要求。企业中在提交...

python实现移位加密和解密

python实现移位加密和解密

本文实例为大家分享了python实现移位加密和解密的具体代码,供大家参考,具体内容如下 代码很简单,就不多做解释啦。主要思路是将字符串转为Ascii码,将大小写字母分别移位密钥表示的位...

python统计字母、空格、数字等字符个数的实例

如下所示: # -*- coding: utf-8 -*- # 要求:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 def count(s): count_a...

基于Django的python验证码(实例讲解)

基于Django的python验证码(实例讲解)

验证码 在用户注册、登录页面,为了防止暴力请求,可以加入验证码功能,如果验证码错误,则不需要继续处理,可以减轻一些服务器的压力 使用验证码也是一种有效的防止crsf的方法 验证码效果如下...

关于numpy中np.nonzero()函数用法的详解

np.nonzero函数是numpy中用于得到数组array中非零元素的位置(数组索引)的函数。一般来说,通过help(np.nonzero)能够查看到该函数的解析与例程。但是,由于例程...