What is arcpy.mp?
Arcpy.mp is a Python sub module that is part of the ArcPy site package. It gets installed with ArcGIS Pro and is available to all licenses. It was designed primarily to manipulate the contents of existing projects (.aprx) and layer files (.lyr or .lyrx). It also provides functions to automate exporting and printing. Arcpy.mp can be used to automate map production and is required to build complete map books because it includes functions to export to, create, and manage PDF documents.
It is easier to understand the capabilities of Arcpy.mp by describing some scenarios it facilitates. Here are only a few of the many scenarios that an arcpy.mp Python script can accomplish:
- Create a report on information contained in projects such as layers and their data sources, layers with broken data sources, the extents of the data being displayed, or layout element properties.
- Update, repair, or replace layer data sources in a map or layer file.
- Find and replace a text string for all layouts in a project.
- Automate sharing project items to be hosted in your organization online.
- Create geographic data in batch using map export commands, such as a series of GeoTIFF images driven by a list of features in a map.
- Build a variety of PDF map books, for example, a reference map book or a thematic map book with title page, multiple map pages, and any number of additional pages with supporting content, such as tabular reports and contact lists.
Who is arcpy.mp for? Why was it built?
Arcpy.mp was built for the professional GIS analyst and for developers. Traditionally, the scenarios listed above had to be done using ArcObjects and it often proved to be a very difficult programming environment to learn for the average GIS professional. Arcpy.mp is a coarser-grained object model, meaning that the functions are designed in a way that a single arcpy.mp function can replace many lines of ArcObjects code. The following is a very simple example of how arcpy.mp can be used to reference an existing layout in a project and export it to a PDF document with only three lines of code.
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
lyt = aprx.listLayouts("Main Attractions*")
lyt.exportToPDF(r"C:\Project\YosemiteNP\Output\Yosemite.pdf", resolution = 300)
The first line loads the arcpy module and is required for all scripts that are run external to ArcGIS Pro . The second line references an ArcGIS Pro project on disk. The third line finds the first layout (using a zero-based index) with a name that begins with the words Main Attractions. The last line of code exports the layout to PDF with an output resolution of 300.
Best ways to get started
- Try the Getting started with arcpy.mp tutorial.
- Review Guidelines for arcpy.mp
- If you used arcpy.mapping in earlier versions of the software and are now usingArcGIS Pro, review Migrating from arcpy.mapping to ArcGIS Pro.
- Review Alphabetical list of arcpy.mp functions and the Alphabetical list of arcpy.mp classes to get a sense of the functionality that is available. These are also nice printouts to have available when scripting with arcpy.mp.
- All arcpy.mp functions and class help topics have detailed explanations and contain sample snippets of code that can be copied and pasted directly into the Python window.