arcgis的python脚本-在ArcGIS中写python脚本读取shapefile

ArcGIS帮助中的相关代码并不能直接运行,进行了小幅修改,现在就可以直接运行了。

python代码的大致思路是:

(1)先获得描述shp的相关信息,获得存储图形信息的字段名;

(2)然后获得游标;

(3)最后对游标进行遍历。

下面就贴上代码了:

import arcpy

#!!!please change the path!!!

shpPath = "D:/data/A156.shp"​

desc = arcpy.Describe(shpPath)

shapefieldname = desc.ShapeFieldName

rows = arcpy.SearchCursor(shpPath)

# Enter for loop for each feature/row

#

for row in rows:

# Create the

geometry object

#

feat =

row.getValue(shapefieldname)

# Print the current

multipoint's ID

#

print "Feature " +

str(row.getValue(desc.OIDFieldName)) + ":"

partnum =

0

# Count the number

of points in the current multipart feature

#

partcount =

feat.partCount

# Enter while loop

for each part in the feature (if a singlepart feature

# this will occur

only once)

#

while partnum

< partcount:

# Print the part number

#

print "Part " + str(partnum) + ":"

part = feat.getPart(partnum)

pnt = part.next()

pntcount = 0

# Enter while loop for each vertex

#

while pnt:

# Print

x,y coordinates of current point

#

print

pnt.X, pnt.Y

pnt =

part.next()

pntcount

+= 1

# If pnt

is null, either the part is finished or there is

an

#

interior ring

#

if not

pnt:

pnt = part.next()

if pnt:

print "Interior Ring:"

partnum += 1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值