- Programming ArcGIS 10.1 with Python Cookbook
- Eric Pimpler
- 334字
- 2021-07-30 17:29:56
Accessing a data frame
The ArcMap table of contents is composed of one or more data frames. Each data frame can contain layers and tables. Data frames can be used to filter lists that are returned from the various list functions such as ListLayers()
. For example, a DataFrame
object can be used as an input parameter to restrict the layers returned by the ListLayers() function to only those layers within a particular data frame. You can also use a DataFrame object to get or set the current map extent, which can be useful when creating map books. In this recipe you will learn how to access data frames from your Python scripts.
Getting ready
The ListDataFrames()
function returns a list of DataFrame
objects. Each data frame can hold layers and tables and can be used to restrict the lists returned by the ListLayers()
and ListTablesViews()
functions.
How to do it...
Follow the steps below to learn how to get a list of layers from a map document:
- Open c
:\ArcpyBook\Ch3\Crime_Ch3.mxd
with ArcMap. - Click on the Python window button from the main ArcMap toolbar.
- Import the
arcpy.mapping
module:import arcpy.mapping as mapping
- Reference the currently active document (
Crime_Ch3.mxd
) and assign the reference to a variable:mxd = mapping.MapDocument("CURRENT")
- Call the
ListDataFrames()
function and pass a reference to the map document along with a wildcard used to find only the data frames that begin with the letterC
:frames = mapping.ListDataFrames(mxd,"C*")
- Start a
for
loop and print out the name of each layer in the map document:for df in frames: print df.name
- Run the script to see the following output:
Crime Crime_Inset
How it works...
The ListDataFrames()
function returns a list of all the data frames in the ArcMap table of contents. Like any other Python list, you can iterate through the contents of the list using a for
loop. Inside the for
loop, each data frame is dynamically assigned to the df
variable and the name of the data frame is printed to the screen.
- 軟件安全技術
- Python自然語言處理實戰:核心技術與算法
- Microsoft Application Virtualization Cookbook
- 程序員考試案例梳理、真題透解與強化訓練
- Podman實戰
- Visual C
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- Learn React with TypeScript 3
- Visual Basic程序設計實驗指導(第二版)
- Nginx Lua開發實戰
- R語言與網絡輿情處理
- Learning Material Design
- C語言程序設計實訓教程與水平考試指導
- Instant jQuery Boilerplate for Plugins
- WordPress Search Engine Optimization(Second Edition)