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

http://blog.csdn.net/alexbnlee/article/details/6965276

 

加入字段:

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

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

Buffer缓冲区

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

集合面积与几何长度

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

改变工作空间

  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 
>>> arcpy.env.workspace = "F:/Data"
>>> result = arcpy.Buffer_analysis("thermal","t_Buffer","10 kilometers")
>>> print result
F:/Data\t_Buffer.shp

返回要素数目

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

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

字段名称:

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

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

  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 
>>> fes = arcpy.ListFeatureClasses()
>>> for fe in fes:
...     print fe 
...     nl = ''
...     fs = arcpy.ListFields(fe)
...     for f in fs:
...         nl = nl + '  ' + f.aliasName
...     print nl

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

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

列表的一些函数

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

Python数据类型

  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. >>>  
>>> type(3)
<type 'int'>
>>> type(3.0)
<type 'float'>
>>> type(1111111111)
<type 'int'>
>>> type(111111111111111)
<type 'long'>
>>> type(3.00000000)
<type 'float'>
>>> type(3.000000000000)
<type 'float'>
>>> type(1+2j)
<type 'complex'>
>>> type(True)
<type 'bool'>
>>> type('Alex')
<type 'str'>
>>> type([2,4])
<type 'list'>
>>> type((3,4))
<type 'tuple'>
>>> 

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

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

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

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

地图文件mxd

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

数据框架data frame

  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 
>>> mxd = arcpy.mapping.MapDocument("current")
>>> dfs = arcpy.mapping.ListDataFrames(mxd)
>>> for df in dfs:
...     print df.name
... 
图层

Data Frame II

图层layer

  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 
>>> mxd = arcpy.mapping.MapDocument("current")
>>> df = arcpy.mapping.ListDataFrames(mxd)[0]
>>> ls = arcpy.mapping.ListLayers(df)
>>> for l in ls:
...     print l 
... 
Cities (population > 5 Million)

Geogrid

Rivers

Lakes

Continents

Ocean
  1. dataframe.extent = layers[0].getSelectedExtent() 
dataframe.extent = layers[0].getSelectedExtent()

 

 

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

 

http://blog.csdn.net/gisinfo/article/details/6674950

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脚本环境》(自定义查找函数预加载)

 

转载自:https://blog.csdn.net/sophiasy/article/details/29588757

You may also like...