Arcpy basics-2. arcpy batch processing, arcpy-2

Source: Internet
Author: User

Arcpy basics-2. arcpy batch processing, arcpy-2
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.
Import arcpy is not allowed in Python. Always display ImportError: No module named arcpy Solution

Find the toptop10.1.path file under the directory... Python27 \ ArcGIS10.1 \ Lib \ site-packages, open the file, and add the directories of the arcpy and bin files, for example:
D: \ Program Files (x86) \ ArcGIS \ topics top10.1 \ bin
D: \ Program Files (x86) \ ArcGIS \ topics top10.1 \ arcpy

Q: How does Arcpy connect python to Arcgis?

It must be a reference to existing functions. All functions of arcgis can be called through python. Of course, the purpose of using python is to customize the workflow you need, it is convenient for users to process their own data.

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.