arcpy站点包中常用方法与函数
http://blog.csdn.net/alexbnlee/article/details/6965276
加入字段:
- >>> arc = [‘A’,‘B’,‘C’,‘D’,‘E’]
- >>> for i in range(5):
- … 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缓冲区
- arcpy.Buffer_analysis(“thermal”,“buffer”,“10 kilometers”)
arcpy.Buffer_analysis("thermal","buffer","10 kilometers")
集合面积与几何长度
- >>> arcpy.CalculateField_management(“idcounty”,“ID_Area”,“!shape.area@squarekilometers!”,“PYTHON_9.3”)
>>> arcpy.CalculateField_management("idcounty","ID_Area","!shape.area@squarekilometers!","PYTHON_9.3")
- >>> arcpy.CalculateField_management(“idcounty”,“ID_Area”,“!shape.length@kilometers!”,“PYTHON_9.3”)
>>> arcpy.CalculateField_management("idcounty","ID_Area","!shape.length@kilometers!","PYTHON_9.3")
改变工作空间
- >>> arcpy.env.workspace = “F:/Data”
- >>> result = arcpy.Buffer_analysis(“thermal”,“t_Buffer”,“10 kilometers”)
- >>> print result
- 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
返回要素数目
- >>> result = arcpy.GetCount_management(“idcounty”)
- >>> print result.getOutput(0)
- 44
>>> result = arcpy.GetCount_management("idcounty")
>>> print result.getOutput(0)
44
调用工具的方法,就是工具的英文名称,去掉中间的空格,然后下划线,加入工具集的名称
字段名称:
- >>> fieldList = arcpy.ListFields(“idcounty”)
- >>> for field in fieldList:
- … print field.aliasname + field.type
>>> fieldList = arcpy.ListFields("idcounty")
>>> for field in fieldList:
... print field.aliasname + field.type
获取工作空间内所有要素类的字段名:
- >>> fes = arcpy.ListFeatureClasses()
- >>> for fe in fes:
- … print fe
- … nl = ”
- … fs = arcpy.ListFields(fe)
- … for f in fs:
- … nl = nl + ‘ ‘ + f.aliasName
- … 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
复制(工作空间中的可以直接写名字)
- arcpy.Copy_management(“i_Copy.shp”,“F:/Data/data/qq.shp”)
arcpy.Copy_management("i_Copy.shp","F:/Data/data/qq.shp")
列表的一些函数
- >>> 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] - >>>
>>> 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数据类型
- >>> 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’>
- >>>
>>> 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
- >>> mxd = arcpy.mapping.MapDocument(“current”)
- >>> print mxd.filePath
- F:\MY_OWN_WORK\Exercise\中国.mxd
>>> mxd = arcpy.mapping.MapDocument("current")
>>> print mxd.filePath
F:\MY_OWN_WORK\Exercise\中国.mxd
数据框架data frame
- >>> mxd = arcpy.mapping.MapDocument(“current”)
- >>> dfs = arcpy.mapping.ListDataFrames(mxd)
- >>> for df in dfs:
- … print df.name
- …
- 图层
- Data Frame II
>>> mxd = arcpy.mapping.MapDocument("current")
>>> dfs = arcpy.mapping.ListDataFrames(mxd)
>>> for df in dfs:
... print df.name
...
图层
Data Frame II
图层layer
- >>> 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
>>> 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
- 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