ArcPy – 入门学习

加入字段:

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

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

Buffer缓冲区

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

集合面积与几何长度

  1. >>> 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”)  

改变工作空间

  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  

返回要素数目

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

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

字段名称:

  1. >>> fieldList = arcpy.ListFields(“idcounty”)  
  2. >>> for field in fieldList:  
  3. …     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  

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

  1. 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. [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数据类型

  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

  1. >>> mxd = arcpy.mapping.MapDocument(“current”)  
  2. >>> print mxd.filePath  
  3. 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  

图层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  
  1. dataframe.extent = layers[0].getSelectedExtent()  



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

转载自:https://blog.csdn.net/plutus_sutulp/article/details/8349204

You may also like...