桌面ArcGIS包含800多種可在Python腳本中運行的地理處理工具。ide
經過Python腳原本運行地理處理工具,能夠處理複雜的工做和執行批處理任務。工具
案例一:使用腳本執行地理處理工具(以裁剪爲例) spa
查看幫助文檔模仿的代碼:3d
1 # Name: Clip_Example2.py 2 3 # Description: Clip major roads that fall within the study area. 4 5 6 # Import system modules 7 8 import arcpy 9 10 from arcpy import env 11 12 13 # Set workspace 14 15 env.workspace = "F:\【the_path_of_grace】\ArcpyBook" 16 17 18 # Set local variables 19 20 in_features = "data/CityOfSanAntonio.gdb/Burglary" 21 22 clip_features = "Ch5/EdgewoodSD.shp" 23 24 out_feature_class = "Ch5/ClpBurglary.shp" 25 26 xy_tolerance = "" 27 28 29 # Execute Clip 30 31 arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)
工做原理:code
在Python腳本中,能夠參照<toolname>_<toolboxalias>語法來調用工具。blog
注:toolboxalias是工具箱的別名ip
拓展:文檔
效果圖:it
案例二:將一個工具的輸出做爲另外一個工具的輸入io
步驟:①緩衝區分析->②建立要素圖層->③按位置選擇圖層
查看幫助文檔模仿的代碼:
1 # Import system modules 2 import arcpy 3 from arcpy import env 4 5 # Set workspace 6 env.workspace = "F:\【the_path_of_grace】\ArcpyBook\data\TravisCounty" 7 try: 8 # Buffer areas of impact around major roads 9 streams = "Streams.shp" 10 streamsBuffer = "StreamsBuffer" 11 distanceField = "2640 Feet" 12 sideType = "FULL" 13 endType = "ROUND" 14 dissolveType = "ALL" 15 schools2mile = "Schools.shp" 16 schoolsLyrFile = 'Schools2Mile_lyr' 17 18 arcpy.Buffer_analysis(streams, streamsBuffer, distanceField,sideType,endType,dissolveType) 19 20 # First, make a layer from the feature class 21 arcpy.MakeFeatureLayer_management(schools2mile, schoolsLyrFile) 22 23 # Then add a selection to the layer based on location to features in another feature class 24 arcpy.SelectLayerByLocation_management (schoolsLyrFile, "intersect", streamsBuffer) 25 except Exception as e: 26 print e.message
效果圖:
謝謝觀看!