ArcPy Mapping Module

ArcPy Mapping Module

GIS 5222

Jake K. Carr

Week 9

ArcPy Mapping Module

Jake K. Carr

Working with Map Files

The Arcpy Mapping Module allows us to automate a lot of map (.mxd) processing tasks. The three ArcPy Mapping objects that we deal with are:

Map Document (.mxd) Objects

Data Frame Objects

Layer Objects

Some of these automating capabilities can be very powerful.

ArcPy Mapping Module

Jake K. Carr

Map Document Objects

Map Documents have a .mxd extension (obvious).

We access/open .mxd with the MapDocument function in one of two ways:

import arcpy arcpy.env.workspace = r"C:\Lectures\Lecture 9\Maps"

# Access Currently Open Map Document myMXD = arcpy.mapping.MapDocument("Current")

OR

import arcpy arcpy.env.workspace = r"C:\Lectures\Lecture 9\Maps"

# Access Map Document and Change Some Properties myMXD = arcpy.mapping.MapDocument(r"C:\ Lectures\Lecture 9\ Maps\

Train Stations.mxd")

ArcPy Mapping Module

Jake K. Carr

"Current" Map Documents

We will reserve the use of accessing the "Current" map document when we are modifying a map document inside of a Python script tool:

myMXD = arcpy.mapping.MapDocument("Current")

If we try to use the "Current" map document and there is no map document open then ArcPy/Python won't run subsequent lines of code.

This is the option that we will prefer when our script tool produces some type of output and we want to add it to the map that we are running the script tool in.

ArcPy Mapping Module

Jake K. Carr

Non-opened Map Documents

If we want to operate on a map document outside of a script tool then we will have to specify the full path directory of the map document:

myMXD = arcpy.mapping.MapDocument(r"C:\ Lectures\Lecture 9\ Maps\ Train Stations.mxd")

Once we have created this map document object (called myMXD here) we can set some properties of Train Stations.mxd.

Open Train Stations.mxd and see what properties are set.

ArcPy Mapping Module

Jake K. Carr

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download