MapFrame
Summary
The MapFrame object is a layout element that is used to display the contents of a map. It also provides access to layout size, positioning on the layout, basic navigation methods, and export options.
Discussion
A MapFrame is a layout element that displays the geographic information added to a map. The listElements method on the Layout object returns a Python list of layout elements. To return a list of only map frames, use the MAPFRAME_ELEMENT constant for the element_type parameter. A wildcard can also be used to further refine the search based on the element's name.
The createMapFrame method on the Layout class will also return a map frame reference.
Once a MapFrame is referenced, the properties and methods allow you to do a variety of operations. First, There are basic properties that allow your to control the size, positioning, and visibility of the map frame on the layout. Second, there are several navigation methods such as panToExtent, zoomToAllLayers, and zoomToBookmark that allow you to modify the area of interest that is displayed in the map frame. Third, the map property allows you to change or get access to the associated map. From here, you can directly manage the layers, tables and basemaps in the map and also get access to the map's camera information, which allows you to modify the area of interest even more. You can switch maps of the same dimension or different dimensions. Finally, there is an export method that allow you to export the map frame into a variety of export formats.
Tip:
Exporting a MapFrame on a layout will produce more consistent results than trying to export a MapView outside of the application. A limitation of exporting a MapView is that map views only work with Python scripts run inside of the application. This is because the size of the window and the area of interest is only known when the application and its view panes are open. MapFrame export has all of the sizing information persisted in the element so scripts run from inside the application or run as stand-alone scripts outside the application will produce the same export result.
Properties
| Name | Explanation | Data type |
|---|---|---|
|
altText (Read and Write) |
A description of the element that can be read by assistive technology when exported to |
String |
|
anchor (Read only) |
Returns one of the following string values that represent the current anchor position. To change the value, use the
|
String |
|
camera (Read and Write) |
The Camera controls the location and viewing positions of the data being displayed within a map frame. |
Camera |
|
elementHeight (Read and Write) |
The height of the map frame on the page layout. The units assigned or reported are in page units. |
Double |
|
elementPositionX (Read and Write) |
The x-location of the map frame's anchor position. The units assigned or reported are in page units. |
Double |
|
elementPositionY (Read and Write) |
The y-location of the map frame's anchor position. The units assigned or reported are in page units. |
Double |
|
elementRotation (Read and Write) |
The map frame's rotation angle in degrees. Positive values rotate clockwise and negative values rotate counterclockwise. This is the angle of the map frame on the layout, not the rotation of the data. Use the |
Double |
|
elementWidth (Read and Write) |
The width of the map frame on the page layout. The units assigned or reported are in page units. |
Double |
|
locked (Read and Write) |
When set to |
Boolean |
|
map (Read and Write) |
The Map being displayed in the map frame. |
Map |
|
name (Read and Write) |
The name of the element. It is important that all elements have a unique name so they can be uniquely referenced using the |
String |
|
time (Read only) |
Returns a MapTime object if time-enabled layers are present in the map frame. A value of |
MapTime |
|
type (Read only) |
Returns a value of |
String |
|
visible (Read and Write) |
Returns |
Boolean |
Methods
addGrid(style_item)
The addGrid method adds a grid or graticule to a MapFrame using a style item.
The addGrid method adds a grid or graticule to the topmost position if grids or graticules are already present. To change the order of how the grids and graticules appear in the Contents pane, first remove all the grids or graticules using the removeGrids method. Then, add them back starting with the bottommost grid using the addGrid method and work up to the topmost position.
| Name | Explanation | Data type |
|---|---|---|
|
style_item |
The reference to a grid |
StyleItem |
convertGridToFeatures(grid_name, output_geodatabase, {new_grid_name})
Converts a MapFrame grid or graticule into geodatabase features.
It is possible to have multiple grids and graticules associated with a map frame. Each one can be converted into features as long as a unique new_grid_name value is used. If the same value is used, features will be overwritten.
| Name | Explanation | Data type |
|---|---|---|
|
grid_name |
The name of the grid or graticule the way it appears in the Contents pane. |
String |
|
output_geodatabase |
The full path to a file geodatabase (*.gdb) or an enterprise geodatabase (*.sde) including the geodatabase name and extension. |
String |
|
new_grid_name (Optional) |
The new name of the group layer added to the map frame's map that will contain all the resulting feature layers. This value will also be added to the |
String |
createBookmark({name}, {description})
The createBookmark method creates a bookmark for the map associated with the map frame using the current camera settings.
This method returns a reference to a new bookmark class. See the code example in the Bookmark class help topic.
| Name | Explanation | Data type |
|---|---|---|
|
name (Optional) |
An string that represents the name of the new bookmark. If a name is not provided, the default |
String |
|
description (Optional) |
A string that represents the bookmark's description. If not specified, the value is an empty string. |
String |
Return value
| Data type | Explanation |
|---|---|
|
Bookmark |
A bookmark object. |
export(export_format, {display_options})
The export method exports a MapFrame using a specified export_format.
Refer to the specific export format or the DisplayOptions help topics to learn more details and get code samples.
| Name | Explanation | Data type |
|---|---|---|
|
export_format |
The supported export format objects are: |
Object |
|
display_options (Optional) |
The |
Object |
exportToAIX(out_aix, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {jpeg_compression_quality}, {embed_fonts}, {embed_color_profile}, {convert_markers})
Exports the MapFrame to Adobe Illustrator Exchange (AIX) format. AIX files can be used with the ArcGIS Maps for Adobe Creative Cloud extension or Adobe Illustrator.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
AIX is an Adobe Illustrator Exchange file exported from ArcGIS to be used with the ArcGIS Maps for Adobe Creative Cloud plug-in. When used with the plug-in, vector and raster map content is converted into editable, layered artwork for an improved editing experience in Adobe Illustrator. Once opened in Illustrator, it can be used for high-end graphic design or map finishing workflows and migrated across the other Adobe Creative Cloud applications.
| Name | Explanation | Data type |
|---|---|---|
|
out_aix |
A string that represents the path and file name for the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 300. |
Integer |
|
image_quality (Optional) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
The default value is BEST. |
String |
|
compress_vector_graphics (Optional) |
A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately. The default value is True. |
Boolean |
|
image_compression (Optional) |
A string that specifies the compression scheme used to compress image or raster data in the output file.
The default value is ADAPTIVE. |
String |
|
jpeg_compression_quality (Optional) |
A number that controls compression quality value when The default value is 80. |
Integer |
|
embed_fonts (Optional) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. The default value is True. |
Boolean |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
|
convert_markers (Optional) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. The default value is False. |
Boolean |
exportToBMP(out_bmp, {resolution}, {world_file}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile})
Exports the MapFrame to a Microsoft Windows Bitmap (BMP) format file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
BMP files are native Windows raster images. BMP files can store pixel data at several bit depths. BMP images are typically much larger than other formats such as JPEG or PNG.
| Name | Explanation | Data type |
|---|---|---|
|
out_bmp |
A string that represents the path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. The default value is False. |
Boolean |
|
bmp_color_mode (Optional) |
This value specifies the number of bits used to describe color.
The default value is 24-BIT_TRUE_COLOR. |
String |
|
bmp_image_compression (Optional) |
A string that specifies the compression scheme used to compress image or raster data in the output file. This option only applies to 8-bit
The default value is NONE. |
String |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
exportToEMF(out_emf, {resolution}, {image_quality}, {output_as_image}, {convert_markers})
Exports the MapFrame to an Enhanced Metafile (EMF) format file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
EMF files are native Windows graphics files that can contain a combination of vector and raster data. They are useful for embedding in Windows documents because the vector portions of the EMF file can be resized without loss of quality. However, since an EMF file does not support font embedding and is exclusively a Windows format, it is not commonly used as an interchange format between users.
| Name | Explanation | Data type |
|---|---|---|
|
out_emf |
A string that represents the system path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
image_quality (Optional) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
The default value is BEST. |
String |
|
output_as_image (Optional) |
If set to The default value is False. |
Boolean |
|
convert_markers (Optional) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. The default value is False. |
Boolean |
exportToEPS(out_eps, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {convert_markers})
Exports the MapFrame to an Encapsulated PostScript (EPS) format file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
EPS files use the PostScript page description language to describe vector and raster objects. PostScript is the publishing industry standard for high-end graphics files, cartography, and printing. EPS files can be edited in many drawing applications or placed as a graphic in most page layout applications. EPS files support embedding of fonts so users who do not have Esri fonts installed can still view the proper symbology.
| Name | Explanation | Data type |
|---|---|---|
|
out_eps |
A string that represents the system path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
image_compression (Optional) |
A string that specifies the compression scheme used to compress image or raster data in the output file.
The default value is DEFLATE. |
String |
|
image_quality (Optional) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
The default value is BEST. |
String |
|
embed_fonts (Optional) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. The default value is True. |
Boolean |
|
output_as_image (Optional) |
If set to The default value is False. |
Boolean |
|
convert_markers (Optional) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. The default value is False. |
Boolean |
exportToGIF(out_gif, {resolution}, {world_file}, {gif_color_mode})
Exports the MapFrame to a Graphic Interchange Format (GIF) file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
GIF files are a legacy raster format for use on the web. GIFs cannot contain more than 256 colors (8-bits per pixel), which along with optional lossless RLE or LZW compression, makes them smaller than other file formats. Like PNGs, GIF files can also define a transparent color. GIFs can be generated with an accompanying world file for use as georeferenced raster data.
| Name | Explanation | Data type |
|---|---|---|
|
out_gif |
A string that represents the system path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. The default value is False. |
Boolean |
|
gif_color_mode (Optional) |
This value specifies the number of bits used to describe color.
The default value is 8-BIT_ADAPTIVE_PALETTE. |
String |
exportToJPEG(out_jpg, {resolution}, {world_file}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile})
Exports the MapFrame to the Joint Photographic Experts Group (JPEG) format.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
JPEG files are compressed image files. They support 24-bit color and are a popular choice for use on the web because a JPEG file size is often substantially smaller than many other image formats. However, the JPEG compression algorithm is lossy and is not recommended for many map images, as line drawings, and text or icon graphics become blurred by compression artifacts. Therefore, PNG is usually a superior format for map images. JPEG files can be generated with an accompanying world file for use as georeferenced raster data.
| Name | Explanation | Data type |
|---|---|---|
|
out_jpg |
A string that represents the path and file name for the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to The default value is False. |
Boolean |
|
jpeg_color_mode (Optional) |
This value specifies the number of bits used to describe color.
The default value is 24-BIT_TRUE_COLOR. |
String |
|
jpeg_quality (Optional) |
This value (0–100) controls the amount of compression applied to the output image. For JPEG, image quality is adversely affected the more compression is applied. A higher quality (highest = 100) setting will produce sharper images and larger file sizes. A lower quality setting will produce more image artifacts and smaller files. The default value is 80. |
Integer |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
exportToPDF(out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {output_as_image}, {embed_color_profile}, {convert_markers}, {simulate_overprint})
Exports the MapFrame to a Portable Document Format (PDF) file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
PDF files are designed to be consistently viewable and printable across different platforms. They are commonly used for distributing documents on the web, and the format is now an official ISO standard for document interchange. PDF files are editable in many graphics applications and retain map georeference information, annotation, labeling, and feature attribute data. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.
Review the PDFDocument class to learn more about how to manage PDF files, such as appending, inserting, and setting properties.
| Name | Explanation | Data type |
|---|---|---|
|
out_pdf |
A string that represents the path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 300. |
Integer |
|
image_quality (Optional) |
A string that defines the output image quality and the draw resolution of map layers that draw as rasters.
The default value is BEST. |
String |
|
compress_vector_graphics (Optional) |
A Boolean that controls the compression of vector and text portions of the output file. Image compression is defined separately. The default value is True. |
Boolean |
|
image_compression (Optional) |
A string that defines the compression scheme used to compress image or raster data in the output file.
The default value is ADAPTIVE. |
String |
|
embed_fonts (Optional) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. The default value is True. |
Boolean |
|
layers_attributes (Optional) |
A string that controls the inclusion of PDF layers and PDF object data (attributes) in the export file.
The default value is LAYERS_ONLY. |
String |
|
georef_info (Optional) |
A Boolean that enables the export of coordinate system information for each data frame into the output PDF file. The default value is True. |
Boolean |
|
jpeg_compression_quality (Optional) |
A number that controls the compression quality value when The default value is 80. |
Integer |
|
output_as_image (Optional) |
If set to The default value is False. |
Boolean |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
|
convert_markers (Optional) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. The default value is False. |
Boolean |
|
simulate_overprint (Optional) |
Sometimes called soft proofing, simulating overprinting shows a representation of how overlapping areas of ink will appear when printed on a page. You set up overprinting on symbol layers. The default value is False. |
Boolean |
exportToPNG(out_png, {resolution}, {world_file}, {color_mode}, {embed_color_profile})
Exports the MapFrame to Portable Network Graphics (PNG) format.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
PNG is a versatile raster format that can display in web browsers and when inserted into other documents. It supports high-bit-depth color and uses a lossless compression. For maps, PNG is often the best raster format, since the lossless compression keeps text and line work legible by preventing the compression artifacts that can occur in JPEG format. PNG files can also define a transparent color. PNG files can be generated with an accompanying world file for use as georeferenced raster data.
| Name | Explanation | Data type |
|---|---|---|
|
out_png |
A string that represents the path and file name for the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to The default value is False. |
Boolean |
|
color_mode (Optional) |
This value specifies the number of bits used to describe color.
The default value is 32-BIT_WITH_ALPHA. |
String |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
exportToSVG(out_svg, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {convert_markers})
Exports the MapFrame to a Scalable Vector Graphics (SVG) format file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
The SVG format is an XML-based file format that is specifically designed for viewing on the web. An SVG file can contain both vector and raster information. Some web browsers may require a plug-in to view SVG files. Older browsers may not be able to view SVG files at all. The SVG format supports the embedding of fonts so users who do not have Esri fonts installed can view SVG exports with proper symbology. You can also produce compressed SVG files. The file extension changes to .svgz when this option is enabled.
| Name | Explanation | Data type |
|---|---|---|
|
out_svg |
A string that represents the path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
compress_to_svgz (Optional) |
If set to True, the output is compressed. The default value is False. |
Boolean |
|
image_quality (Optional) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
The default value is BEST. |
String |
|
embed_fonts (Optional) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. The default value is True. |
Boolean |
|
output_as_image (Optional) |
If set to The default value is False. |
Boolean |
|
convert_markers (Optional) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. The default value is False. |
Boolean |
exportToTGA(out_tga, {resolution}, {world_file}, {color_mode})
Exports the MapFrame to a Truevision Graphics Adapter (TGA) format file.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
TGA files have historically been used for content that is meant to be used in other applications (for example, image sprites for animated games) and is read and written by many popular graphic arts applications. TGA format supports multiple bit depths including 32-bit with alpha (transparency) support.
| Name | Explanation | Data type |
|---|---|---|
|
out_tga |
A string that represents the path and file name of the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. The default value is False. |
Boolean |
|
color_mode (Optional) |
This value specifies the number of bits used to describe color.
The default value is 32-BIT_WITH_ALPHA. |
String |
exportToTIFF(out_tif, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags}, {jpeg_compression_quality}, {embed_color_profile})
Exports the MapFrame to Tagged Image File Format (TIFF).
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
TIFF files are the best choice for importing into image editing applications and are also a common GIS raster data format. However, they cannot be natively viewed by a web browser. TIFF files also support georeferencing information in GeoTIFF tags or in a separate world file for use as raster data.
| Name | Explanation | Data type |
|---|---|---|
|
out_tif |
A string that represents the path and file name for the output export file. |
String |
|
resolution (Optional) |
A number that defines the resolution of the export file in dots per inch (dpi). The default value is 96. |
Integer |
|
world_file (Optional) |
If set to The default value is False. |
Boolean |
|
color_mode (Optional) |
This value specifies the number of bits used to describe color. The available options are dependent on the specified Color Model set in the layout's Color Management properties.
The default value is 24-BIT_TRUE_COLOR. |
String |
|
tiff_compression (Optional) |
This value represents a compression scheme.
The default value is LZW. |
String |
|
geoTIFF_tags (Optional) |
If set to True, georeferencing tags are included in the structure of the TIFF export file. The tags contain pixel scale information and real-world coordinate information. These tags can be read by applications that support GeoTIFF format. The default value is False. |
Boolean |
|
jpeg_compression_quality (Optional) |
This value (0–100) controls the amount of compression applied to the output image. With a JPEG image, quality is adversely affected the more compression is applied. A higher quality (highest = 100) setting will produce sharper images and larger file sizes. A lower quality setting will produce more image artifacts and smaller files. The default value is 80. |
Integer |
|
embed_color_profile (Optional) |
If set to The default value is True. |
Boolean |
getDefinition(cim_version)
Returns a map frame element's CIM definition.
For more information about working with the CIM and samples, see Python CIM access.
| Name | Explanation | Data type |
|---|---|---|
|
cim_version |
A string that represents the major version of the CIM that will be used.
|
String |
Return value
| Data type | Explanation |
|---|---|
|
Object |
Returns the CIM definition for a |
getLayerExtent(layer, {selection_only}, {symbolized_extent})
Returns a layer's extent for all features or only the selected features in a layer.
The getLayerExtent method will honor a layer's definition query, so if a subset of features are queried, it will return the extent for only those features. If there are no selected features, the extent for the layer will be returned.
| Name | Explanation | Data type |
|---|---|---|
|
layer |
A reference to a Layer object. |
Layer |
|
selection_only (Optional) |
If The default value is True. |
Boolean |
|
symbolized_extent (Optional) |
A value of True will return the layer's symbolized extent; otherwise, it will return the geometric extent. The symbolized extent takes into account the area the symbology covers so that it does not get cut off by the data frame's boundary. The default value is True. |
Boolean |
Return value
| Data type | Explanation |
|---|---|
|
Extent |
A geoprocessing Extent object. |
panToExtent(extent)
Pans and centers the MapFrame using a new Extent object without changing the map frame's scale.
This method is perfect for situations where the MapFrame scale should not change but the location should. Rather than setting the extent and then having to reset the scale each time, panToExtent maintains the scale and centers the current map frame on the new extent.
| Name | Explanation | Data type |
|---|---|---|
|
extent |
A geoprocessing Extent object. |
Extent |
removeGrids({wildcard})
The removeGrids method removes one or more grids or graticules from a map frame.
If no wildcard value is specified, all grids and graticules will be removed from the map frame. If a wildcard value is specified, all grids or graticules that meet its condition will be removed.
| Name | Explanation | Data type |
|---|---|---|
|
wildcard (Optional) |
A wildcard is based on the grid or graticule name in the Contents pane and is not case sensitive. A combination of asterisks (*) and characters can be used to limit the resulting list. The default value is None. |
String |
setAnchor(anchor)
The setAnchor method controls the anchor position for a MapFrame element.
Setting the anchor position is helpful because you can control how the element might expand when resized. For example, the default anchor position for a map frame element is BOTTOM_LEFT_CORNER. If you change the anchor location to TOP_RIGHT_CORNER, changing elementHeight will expand the element downward instead of upward (the default), and changing elementWidth will expand the element to the left.
| Name | Explanation | Data type |
|---|---|---|
|
anchor |
A string that specifies the location of the anchor position.
|
String |
setDefinition(definition_object)
Sets a map frame element's CIM definition.
For more information about working with the CIM and samples, see Python CIM access.
| Name | Explanation | Data type |
|---|---|---|
|
definition_object |
A modified CIM definition object originally retrieved using |
Object |
zoomToAllLayers({selection_only}, {symbolized_extent})
Modifies the MapFrame view to match the extent of all layers or selected layers in a map.
If zoomToAllLayers is used on a MapFrame with a global or local scene, the result will be a planimetric view.
| Name | Explanation | Data type |
|---|---|---|
|
selection_only (Optional) |
If The default value is True. |
Boolean |
|
symbolized_extent (Optional) |
A value of True will return the layer's symbolized extent; otherwise, it will return the geometric extent. The symbolized extent takes into account the area the symbology covers so that it does not get cut off by the map frame's boundary. The default value is True. |
Boolean |
zoomToBookmark(bookmark)
Modifies the MapFrame view to match the view information stored with a spatial bookmark.
If a 3D bookmark is used for a MapFrame referencing a 2D Map, or the other way around, the result will be a planimetric view.
| Name | Explanation | Data type |
|---|---|---|
|
bookmark |
A reference to a Bookmark object. |
Bookmark |
Code sample
The following script sets the map frame extent in a variety of ways and exports each result to PDF. It first sets the extent using feature selection. Next it zooms to a single layer's extent and applies a slight buffer. Finally, it does the same but zooms to the extent of each feature.
import arcpy, os
aprx = arcpy.mp.ArcGISProject(r'C:\Projects\GreatLakes\GreatLakes.aprx')
m = aprx.listMaps('Map')[0]
lyr = m.listLayers('GreatLakes')[0]
lyt = aprx.listLayouts('Layout')[0]
mf = lyt.listElements('mapframe_element', 'Map Frame')[0]
#Zoom to ALL selected features and export to PDF
arcpy.SelectLayerByAttribute_management(lyr, 'NEW_SELECTION', "NAME = 'Lake Superior'")
mf.zoomToAllLayers(True)
pdf = arcpy.mp.CreateExportFormat('PDF', r'C:\Projects\GreatLakes\Selection.pdf')
mf.export(pdf)
arcpy.SelectLayerByAttribute_management(lyr, 'CLEAR_SELECTION')
#Set the map frame extent to the extent of a layer and export to PDF
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
mf.camera.scale = mf.camera.scale * 1.1 #add a slight buffer
pdf.filePath = r'C:\Projects\GreatLakes\GreatLakesExtent.pdf'
mf.export(pdf)
#Set the map frame extent based on each feature in a layer and export to PDF
for row in arcpy.da.SearchCursor(lyr, ['SHAPE@', 'NAME']):
mf.camera.setExtent(row[0].extent)
mf.camera.scale = mf.camera.scale * 1.1 #add a slight buffer
pdf.filePath = os.path.join(r'C:\Projects\GreatLakes', f'{row[1]}.pdf')
mf.export(pdf)
The following script imports an MXD and 3DD document into a blank project. After referencing the appropriate elements, it changes each of the 2D inset maps to 3D scenes and applies the appropriate bookmarks to each map frame. Finally, the entire layout is exported to PDF.
import arcpy
p = arcpy.mp.ArcGISProject(r'C:\Projects\Blank.aprx')
#Import documents into project
p.importDocument(r'C:\Projects\YosemiteNP\Documents\Yosemite.mxd')
p.importDocument(r'C:\Projects\YosemiteNP\Documents\Yosemite_3DViews.3dd')
#Reference maps
scene = p.listMaps('Globe layers')[0]
#Reference Layout and map frames
lyt = p.listLayouts()[0]
mainMF = lyt.listElements('MapFrame_Element', 'Yosemite National Park*')[0]
inset1MF = lyt.listElements('MapFrame_Element', 'Inset1*')[0]
inset2MF = lyt.listElements('MapFrame_Element', 'Inset2*')[0]
#Convert imported 2D insets into 3D views and zoom to bookmarks
mainMF.zoomToBookmark(mainMF.map.listBookmarks('Yosemite Valley')[0])
inset1MF.map = scene
inset1MF.zoomToBookmark(inset1MF.map.listBookmarks('Yosemite Yalley (looking East)')[0])
inset2MF.map = scene
inset2MF.zoomToBookmark(inset2MF.map.listBookmarks('Yosemite Yalley (looking West)')[0])
#Export the resulting imported layout and changes to PDF
pdf = arcpy.mp.CreateExportFormat('PDF', r'C:\Projects\YosemiteNP\Example2_Export.pdf')
lyt.export(pdf)
The following script demonstrates how to create a map frame using a Polygon geometry and a Point geometry.
p = arcpy.mp.ArcGISProject("CURRENT")
#Create a new map, layout
m = p.createMap('New Map', 'MAP')
lyt = p.createLayout(8.5, 11, 'INCH', 'New Layout')
lyt.openView()
#Create a new map frame using a polygon geometry
envCoordList = [[0.5, 5.75], [0.5, 10.5], [8, 10.5], [8, 5.75], [0.5, 5.75]]
envArray = arcpy.Array([arcpy.Point(*coords) for coords in envCoordList])
mf1 = lyt.createMapFrame(arcpy.Polygon(envArray), m, 'New MF - Poly')
#Create a new bookmark set to the map frame's default extent
bkmk = mf1.createBookmark('Default Extent', "The map's default extent")
bkmk.updateThumbnail()
#Create a new map frame using a point geometry
mf2 = lyt.createMapFrame(arcpy.Point(0.5,0.5), m, 'New MF - Point')
mf2.elementWidth = 7.5
mf2.elementHeight = 4.75
The following script demonstrates how to use Python CIM Access to modify the border symbology of each map frame in a layout.
p = arcpy.mp.ArcGISProject('CURRENT')
lyt = p.listLayouts('Layout')[0]
lyt_cim = lyt.getDefinition('V3')
for elm in lyt_cim.elements:
if type(elm).__name__ == 'CIMMapFrame':
if elm.graphicFrame.borderSymbol.symbol.symbolLayers:
sym = elm.graphicFrame.borderSymbol.symbol.symbolLayers[0]
sym.width = 5
sym.color.values = [255, 0, 0, 100]
else:
print(elm.name + ' has NO symbol layers')
lyt.setDefinition(lyt_cim)