Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Donald Eric Pimpler, Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Donald Eric Pimpler, Eric Pimpler

Overview of this book

Table of Contents (22 chapters)
Programming ArcGIS with Python Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Changing the map extent


There will be many occasions when you will need to change the map extent. This is frequently the case when you are automating the map production process and need to create many maps of different areas or features. There are a number of ways that the map extent can be changed with arcpy. However, for this recipe, we'll concentrate on using a definition expression to change the extent.

Getting ready

The DataFrame class has an extent property that you can use to set the geographic extent. This is often used in conjunction with the Layer.definitionQuery property that is used to define a definition query for a layer. In this recipe, you will learn how to use these objects and properties to change the map extent.

How to do it...

Follow these steps to learn how to get a list of layers from a map document:

  1. Open c:\ArcpyBook\Ch2\Crime_Ch2.mxd with ArcMap.

  2. Click on the Python window button from the main ArcMap toolbar.

  3. Import the arcpy.mapping module:

    import arcpy.mapping as mapping...