Arcpy basics-2. Batch processing of arcpy

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.