ArcPy is a Python site package that provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python. ArcGIS applications and scripts written using ArcPy benefit from being able to access and work with the numerous Python modules developed by GIS professionals and programmers from many different disciplines.
# Import arcpy
import arcpy
# Set the workspace environment and run Clip
arcpy.env.workspace = 'C:/Data/Tongass'
arcpy.analysis.Clip('standb4', 'clipcov', 'standby_clip', 1.25)
Once you have imported ArcPy, you can run all geoprocessing tools found in the standard toolboxes installed with ArcGIS.
Of course, Python has many other core and third-party modules. If you wanted to also work with the os and sys modules, you can use a similar import:
# Import arcpy, os and sys
import arcpy
import os
import sys
Another version of importing is the form from-import-*. The contents of the module import directly into the namespace, meaning you can then use all those contents directly without needing to prefix them. There are some risks associated with this approach. Other objects, variables, modules, and so forth with the same name are overwritten, and with large modules, your namespace can become particularly crowded.
However, in some cases, from-import-* can simplify your code, as in the case of the ArcGIS Spatial Analyst extension sa module. One of the benefits of the sa module is that you can nest multiple classes and functions in a single line to produce an output raster object.
Lizenz:
The following sample requires the ArcGIS Spatial Analyst extension to run.
import arcpy
from arcpy.sa import *
out_raster = FocalStatistics("inRaster", NbrCircle(5, "CELL"), "SUM")
ArcPy modules
A module is a Python file that generally includes functions and classes. ArcPy is supported by a series of modules, including the following:
- Diagramm-Modul (arcpy.charts)
- Data Access-Modul (arcpy.da)
- Geokodierungsmodul (arcpy.geocoding)
- Bildanalysemodul (arcpy.ia)
- Mapping-Modul (arcpy.mp)
- Metadatenmodul (arcpy.metadata)
- Network Analyst-Modul (arcpy.nax und arcpy.na)
- Freigabemodul (arcpy.sharing)
- Spatial Analyst-Modul (arcpy.sa)
- Workflow Manager (Classic)-Modul (arcpy.wmx)