In tutorial 1, we briefly talked about how to use arcpy. This should be in line with China's national conditions. This section describes the use of arcpy. Let's talk about the batch processing function of arcpy.
As the world's leading platform GIS software, ArcGIS is widely used and has a good user experience. ArcGIS constructs the entire platform from three aspects: Geographical Database, geographical processing framework, and geographical data visualization. Like many platforms, arcgis effectively encapsulates its core code and provides function customization. This is also a function provided by many platform software, such as the macro commands provided by CAD.
Let's take a look at the sample code:
Import arcpy
Arcpy. env. workspace = r "C: \ Users \ Administrator \ Desktop \ H48G026039. gdb"
Fcs = arcpy. ListFeatureClasses ()
FcCount = len (fcs)
For fc in fcs:
Arcpy. RepairGeometry_management (fc)
Print fc
Print fcCount
This code traverses a gdb database and fixes each element class layer. I believe you should have used the RepairGeometry tool, but you can only fix one element layer each time. The Batch function in arcmap can only add element layers one by one, which is very troublesome, the above code solves this problem well.
This is the first use of arcpy.
Direct processing and batch processing of a workspace (database or file directory)Insufficient functionality.
Let's take a look at the sample code:
Import arcpy, OS, time
Path = r 'd: \ accessibility analytics'
Res = 100
Print 'Program start: '+ str (time. ctime ())
For afile in OS. listdir (path ):
If afile [-3:]. lower () = 'mxd ':
Mxd = arcpy. mapping. MapDocument (OS. path. join (path, afile ))
Arcpy. mapping. ExportToJPEG (mxd, OS. path. join (path, afile [:-3] + 'jpg '), resolution = res)
Del mxd
Print 'Program ended: '+ str (time. ctime ())
This code traverses the mxd files in a folder and exports them as jpg files, which facilitates batch processing of large batches of mxd files.
Arcpy basics-2. Batch processing of arcpy