使用Python开发ArcGIS应用1-获取数据相关信息

八 15 2010 Published by Jack under Python, arcgis

这几天抽空写了一些arcgis python入门类的脚本,详细信息注解以后加入.首先是获取数据信息类的应用.
获取信息函数直接copy的.看起来有点繁琐.先不改了.嗯嗯=.=

import arcgisscripting
####  get field's info function
def PrintFiledsInfo(fc):
    des = gp.Describe(fc)
    fields = des.Fields
    fields.reset()
    field = fields.next()
    while field:
        print "|fieldname: |" + field.Name + "  |" + "fieldtype: |" + field.Type +" |"
        print "--------------------------------------------"
        field = fields.next()
#### print feature's Area function
def PrintArea(fc):
    rows = gp.searchcursor(fc)
    rows.reset()
    row = rows.next()
    while row:
        geom = row.GetValue("Shape")
        print geom.Type
        print "area: "  + float.__str__( geom.Area)
        row = rows.next()
 
###print feature's length function
def PrintLength(fc):
    rows = gp.searchcursor(fc)
    rows.reset()
    row = rows.next()
    i = 0
    while row and i < 10:
        geom = row.GetValue("Shape")
        print geom.Type
        print "line: "  + float.__str__( geom.length)
        i = i + 1
        row = rows.next()
## print point x&y
def PrintPoint(fc):
    rows = gp.searchcursor(fc)
    rows.reset()
    row = rows.next()
    i = 0
    while row and i < 10:
        geom = row.GetValue("Shape")
        print geom.Type
        print "point: "  +  geom.firstpoint
        i = i + 1
        row = rows.next()
 
#######main func
 
if __name__ == "__main__":
 
    gp = arcgisscripting.create()
    gp.Workspace = r"C:\ArcGIS\DeveloperKit\SamplesNET\data\SanFranciscoNetwork"
 
    fcs = gp.ListFeatureClasses()
    fcs.reset()
    fc = fcs.next()
    while fc:
        print "**************"
        print "* " + fc + " "
        print "**************"
 
        PrintFiledsInfo(fc)
 
        des = gp.Describe(fc)
 
        if des.shapetype == "Polygon":
            PrintArea(fc)
 
        if des.shapetype == "Polyline":
            PrintLength(fc)
 
        if des.shapetype == "Point":
            PrintPoint(fc)
 
        fc = fcs.next()
Tags: ,

2 responses so far

  • hmfly 说:

    arcpy是一个新的python包吗?那跟以前的写法会不会变化很大?

    • Jack 说:

      新的包.支持800+geoprocessing工具和全部的地圖代數的分析工具.
      寫法變化不大.
      循環遍歷更方便了.
      改天寫點上來.

发表评论

click to changeSecurity Code