arcpy站点包中常用方法与函数

arcpy站点包中常用方法与函数

1.feature class 记录数
    arcpy.GetCount_management(“c:/wlgt/pms_gt_l.shp”)
2.feature class 默认网格索引(3级)
   arcpy.CalculateDefaultGridIndex_management(“c:/wlgt/pms_gt_l.shp”)
3.列出系统工具箱
   arcpy.ListToolboxes()
4.列出别名为management的工具
   arcpy.ListTools(“*_management”)
5.导入自定义开发工具箱
   arcpy.ImportToolbox(“c:/PCovertL.tbx”)

6.加载mxd文档

   acrpy.mapping.MapDocument()

7.list已知mxd文档中的layername

   arcpy.mapping.ListLayers()

8.list已知mxd文档中失去连接的数据源的layername

   arcpy.mapping.ListBrokenDataSources()

9. 查看对象类型

    type()比较常用在实例化类以后判断属性,方法

10.查看arcpy包中方法的具体参数与描述信息

    arcpy.Usage()

11.查看类,开发包工具箱下的方法种类

    dir()  此处可以参考《定制python脚本环境》(自定义查找函数预加载)

加入字段:

[python] view plain copy

  1. >>> arc = [‘A’,‘B’,‘C’,‘D’,‘E’]  
  2. >>> for i in range(5):  
  3. …     arcpy.AddField_management(“idcounty”,arc[i],“TEXT”)  

给idcounty空间数据批量加入五个字段~

Buffer缓冲区

[python] view plain copy

  1. arcpy.Buffer_analysis(“thermal”,“buffer”,“10 kilometers”)  

集合面积与几何长度

[python] view plain copy

  1. >>> arcpy.CalculateField_management(“idcounty”,“ID_Area”,“!shape.area@squarekilometers!”,“PYTHON_9.3”)  
[python] view plain copy

  1. >>> arcpy.CalculateField_management(“idcounty”,“ID_Area”,“!shape.length@kilometers!”,“PYTHON_9.3”)  

改变工作空间

[python] view plain copy

  1. >>> arcpy.env.workspace = “F:/Data”  
  2. >>> result = arcpy.Buffer_analysis(“thermal”,“t_Buffer”,“10 kilometers”)  
  3. >>> print result  
  4. F:/Data\t_Buffer.shp  

返回要素数目

[python] view plain copy

  1. >>> result = arcpy.GetCount_management(“idcounty”)  
  2. >>> print result.getOutput(0)  
  3. 44  

调用工具的方法,就是工具的英文名称,去掉中间的空格,然后下划线,加入工具集的名称

字段名称:

[python] view plain copy

  1. >>> fieldList = arcpy.ListFields(“idcounty”)  
  2. >>> for field in fieldList:  
  3. …     print field.aliasname + field.type  

获取工作空间内所有要素类的字段名:

[python] view plain copy

  1. >>> fes = arcpy.ListFeatureClasses()  
  2. >>> for fe in fes:  
  3. …     print fe   
  4. …     nl =   
  5. …     fs = arcpy.ListFields(fe)  
  6. …     for f in fs:  
  7. …         nl = nl + ‘  ‘ + f.aliasName  
  8. …     print nl  

复制(工作空间中的可以直接写名字)

[python] view plain copy

  1. arcpy.Copy_management(“i_Copy.shp”,“F:/Data/data/qq.shp”)  

列表的一些函数

[python] view plain copy

  1. >>> a = [1]*10  
  2. >>> for i in range(10):  
  3. …     a[i] = i  
  4. …   
  5. >>> a  
  6. [0123456789]  
  7. >>> b = [1]*2  
  8. >>> b  
  9. [11]  
  10. >>> a.extend(b)  
  11. >>>   
  12. >>> a  
  13. [012345678911]  
  14. >>> a + b  
  15. [01234567891111]  
  16. >>> a   
  17. [012345678911]  
  18. >>> a.count(1)  
  19. 3  
  20. >>> a.append(100)  
  21. >>> a  
  22. [012345678911100]  
  23. >>> a.index(100)  
  24. 12  
  25. >>> a.insert(0,‘I’)  
  26. >>> a  
  27. [‘I’012345678911100]  
  28. >>> a.pop(0)  
  29. ‘I’  
  30. >>> a  
  31. [012345678911100]  
  32. >>> a.remove(100)  
  33. >>> a  
  34. [012345678911]  
  35. >>> a.reverse()  
  36. >>> a  
  37. [119876543210]  
  38. >>> a.sort()  
  39. >>> a  
  40. [011123456789]  
  41. >>>   

Python数据类型

[python] view plain copy

  1. >>> type(3)  
  2. <type ‘int’>  
  3. >>> type(3.0)  
  4. <type ‘float’>  
  5. >>> type(1111111111)  
  6. <type ‘int’>  
  7. >>> type(111111111111111)  
  8. <type ‘long’>  
  9. >>> type(3.00000000)  
  10. <type ‘float’>  
  11. >>> type(3.000000000000)  
  12. <type ‘float’>  
  13. >>> type(1+2j)  
  14. <type ‘complex’>  
  15. >>> type(True)  
  16. <type ‘bool’>  
  17. >>> type(‘Alex’)  
  18. <type ‘str’>  
  19. >>> type([2,4])  
  20. <type ‘list’>  
  21. >>> type((3,4))  
  22. <type ‘tuple’>  
  23. >>>   

详见:http://blog.sina.com.cn/s/blog_4b5039210100e9ya.html

——————————————————————————————————————————————————————————–

———————————————— ESRI培训 ———————————————————————————————————————-

——————————————————————————————————————————————————————————–

地图文件mxd

[python] view plain copy

  1. >>> mxd = arcpy.mapping.MapDocument(“current”)  
  2. >>> print mxd.filePath  
  3. F:\MY_OWN_WORK\Exercise\中国.mxd  

数据框架data frame

[python] view plain copy

  1. >>> mxd = arcpy.mapping.MapDocument(“current”)  
  2. >>> dfs = arcpy.mapping.ListDataFrames(mxd)  
  3. >>> for df in dfs:  
  4. …     print df.name  
  5. …   
  6. 图层  
  7.   
  8. Data Frame II  

图层layer

[python] view plain copy

  1. >>> mxd = arcpy.mapping.MapDocument(“current”)  
  2. >>> df = arcpy.mapping.ListDataFrames(mxd)[0]  
  3. >>> ls = arcpy.mapping.ListLayers(df)  
  4. >>> for l in ls:  
  5. …     print l   
  6. …   
  7. Cities (population > 5 Million)  
  8.   
  9. Geogrid  
  10.   
  11. Rivers  
  12.   
  13. Lakes  
  14.   
  15. Continents  
  16.   
  17. Ocean  

You may also like...