Import ArcPy

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 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 Extensión ArcGIS Spatial Analyst 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.

Licencia:

The following sample requires the Extensión ArcGIS Spatial Analyst to run.

import arcpy
from arcpy.sa import *
out_raster = FocalStatistics("inRaster", NbrCircle(5, "CELL"), "SUM")

Temas relacionados