Skip To Content

MapFrame

サマリー

The MapFrame object is a page layout element that is used to display the contents of a map on a layout. It also provides access to page size and positioning, basic navigation methods, and export options.

説明

A MapFrame is a Layout element that displays the geographic information added to a Map. It also controls the size and positioning of itself on a layout. More than one MapFrame can reference the same Map.

The listElements function on the Layout object can be used to return MapFrame objects. Providing an element_type of MAPFRAME_ELEMENT allows you to return only MapFrame elements. You can also further refine your filter by providing a wildcard. It is important to uniquely name each map frame so it can be easily referenced using its name property.

Once a MapFrame is referenced, you can get its associated map using the map property, which would allow you to manage layers on a map, get to a map's bookmarks, and more. Even more important is that you can change the Map object a MapFrame is referencing. You can switch maps of the same dimension or different dimensions. If you change the dimension of a map, you must first change the type property on the MapViewer object. For example, if the Camera mode is MAP (for 2D), you must change the mode to LOCAL or GLOBAL (for 3D). Once this is done, you can change the map from 2D to 3D.

The camera property returns a reference to the Camera object. The Camera controls the location and viewing positions of the data being displayed within a map frame. It controls items like scale and extent for 2D maps and camera position information for 3D maps.

It is important to understand the navigation methods and how they work between map (2D) and scene (3D) map frames. Anytime a 2D map, bookmark, or method that uses an extent is applied to a 3D map frame, the result will be a planimetric view of the data. The getLayerExtent, panToExtent, and zoomToAllLayers will always result in a planimetric view. The zoomToBookmark method maintains a 3D view when working between 3D map frames, but once a 2D bookmark is used on a 3D map frame or the other way around, the result will be a planimetric view of the map frame's data.

The elementPositionX and elementPositionY parameters are based on the element's anchor position.

プロパティ

プロパティ説明データ タイプ
camera
(読み書き)

The Camera controls the location and viewing positions of the data being displayed within a map frame.

Camera
elementHeight
(読み書き)

The height of the map frame on the page layout. The units assigned or reported are in page units.

Double
elementPositionX
(読み書き)

The X location of the map frame's anchor position. The units assigned or reported are in page units.

Double
elementPositionY
(読み書き)

The Y location of the map frame's anchor position. The units assigned or reported are in page units.

Double
elementRotation
(読み書き)

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 heading property on the camera to rotate the data.

Double
elementWidth
(読み書き)

The width of the map frame on the page layout. The units assigned or reported are in page units.

Double
map
(読み書き)

The Map being displayed in the map frame.

Map
name
(読み書き)

The map's name as it appears in the Project window. It is important that all maps have a unique name so they can be easily referenced.

String
type
(読み取り専用)

Returns a value of MAPFRAME_ELEMENT.

String
visible
(読み書き)

Returns True if the map frame is visible on the layout. Rather than having to move unwanted objects off the page before printing or exporting, you can toggle the element's visibility.

Boolean

メソッドの概要

メソッド説明
exportToBMP (out_bmp, {resolution})

Exports the map frame to a Microsoft Windows Bitmap (BMP) format file.

exportToEMF (out_emf, {resolution})

Exports the map frame to an Enhanced Metafile (EMF) format file.

exportToEPS (out_eps, {resolution})

Exports the map frame to an Encapsulated PostScript (EPS) format file.

exportToGIF (out_gif, {resolution})

Exports the map frame to a Graphic Interchange Format (GIF) file.

exportToJPEG (out_jpg, {resolution}, {world_file}, {jpeg_color_mode}, {jpeg_quality})

Exports the contents of a MapFrame to the Joint Photographic Experts Group format (JPEG).

exportToPDF (out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality})

Exports the map frame to a Portable Document Format (PDF) file.

exportToPNG (out_png, {resolution}, {world_file}, {color_mode})

Exports the contents of a MapFrame to Portable Network Graphics format (PNG).

exportToSVG (out_svg, {resolution}, {compress_to_svgz})

Exports the map frame to a Scalable Vector Graphics (SVG) format file.

exportToTGA (out_tga, {resolution})

Exports the page layout to a Truevision Graphics Adapter (TGA) format file.

exportToTIFF (out_tif, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags})

Exports the page layout to the Tagged Image File Format (TIFF).

getLayerExtent (layer, {selection_only}, {symbolized_extent})

Returns a layer's extent for all features or only the selected features in a layer.

panToExtent (extent)

Pans and centers the MapFrame using a new Extent object without changing the map frame's scale.

zoomToAllLayers ({selection_only}, {symbolized_extent})

Modifies the MapFrame view to match the extent of all layers or selected layers in a map.

zoomToBookmark (bookmark)

Modifies the MapFrame view to match the view information stored with a spatial bookmark.

メソッド

exportToBMP (out_bmp, {resolution})
パラメーター説明データ タイプ
out_bmp

A string that represents the path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer

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.

exportToEMF (out_emf, {resolution})
パラメーター説明データ タイプ
out_emf

A string that represents the system path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer

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.

exportToEPS (out_eps, {resolution})
パラメーター説明データ タイプ
out_eps

A string that represents the system path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer

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.

exportToGIF (out_gif, {resolution})
パラメーター説明データ タイプ
out_gif

A string that represents the system path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer

GIF files are a legacy raster format for use on the web. GIF files cannot contain more than 256 colors (8-bits per pixel), which along with optional lossless compression, makes them smaller than other file formats.

exportToJPEG (out_jpg, {resolution}, {world_file}, {jpeg_color_mode}, {jpeg_quality})
パラメーター説明データ タイプ
out_jpg

A string that represents the path and file name for the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer
world_file

If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. If you export a 3D map frame, this parameter will be ignored regardless of the setting because world files are not applicable to 3D views.

(デフォルト値は次のとおりです False)

Boolean
jpeg_color_mode

This value specifies the number of bits used to describe color.

  • 8-BIT_GRAYSCALE8-bit grayscale
  • 24-BIT_TRUE_COLOR24-bit true color

(デフォルト値は次のとおりです 24-BIT_TRUE_COLOR)

String
jpeg_quality

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.

(デフォルト値は次のとおりです 80)

Integer

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. JPEGs can be generated with an accompanying world file for use as georeferenced raster data.

exportToPDF (out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality})
パラメーター説明データ タイプ
out_pdf

A string that represents the path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 300)

Integer
image_quality

A string that defines output image quality and the draw resolution of map layers that draw as rasters.

  • BESTAn output image quality resample ratio of 1
  • BETTERAn output image quality resample ratio of 2
  • NORMALAn output image quality resample ratio of 3
  • FASTERAn output image quality resample ratio of 4
  • FASTESTAn output image quality resample ratio of 5

(デフォルト値は次のとおりです BEST)

String
compress_vector_graphics

A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately.

(デフォルト値は次のとおりです True)

Boolean
image_compression

A string that defines the compression scheme used to compress image or raster data in the output file.

  • ADAPTIVEAutomatically selects the best compression type for each image on the page. JPEG will be used for large images with many unique colors. DEFLATE will be used for all other images.
  • DEFLATEA lossless data compression.
  • JPEGA lossy data compression.
  • LZWLempel-Ziv-Welch, a lossless data compression.
  • NONECompression is not applied.
  • RLERun-length encoded compression.

(デフォルト値は次のとおりです ADAPTIVE)

String
embed_fonts

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.

(デフォルト値は次のとおりです True)

Boolean
layers_attributes

A string that controls inclusion of PDF layers and PDF object data (attributes) in the export file.

  • LAYERS_ONLYExport PDF layers only.
  • LAYERS_AND_ATTRIBUTESExport PDF layers and feature attributes.
  • NONENo setting is applied.

(デフォルト値は次のとおりです LAYERS_ONLY)

String
georef_info

A Boolean that enables the export of coordinate system information for each data frame into the output PDF file.

(デフォルト値は次のとおりです True)

Boolean
jpeg_compression_quality

A number that controls compression quality value when image_compression is set to ADAPTIVE or JPEG. The valid range is 1 through 100. A jpeg_compression_quality of 100 provides the best quality images but creates large export files. The recommended range is 70 through 90.

(デフォルト値は次のとおりです 80)

Integer

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.

exportToPNG (out_png, {resolution}, {world_file}, {color_mode})
パラメーター説明データ タイプ
out_png

A string that represents the path and file name for the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer
world_file

If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. If you export a 3D map frame, this parameter will be ignored regardless of the setting because world files are not applicable to 3D views.

(デフォルト値は次のとおりです False)

Boolean
color_mode

This value specifies the number of bits used to describe color.

  • 8-BIT_ADAPTIVE_PALETTE8-bit adaptive palette
  • 8-BIT_GRAYSCALE8-bit grayscale
  • 24-BIT_TRUE_COLOR24-bit true color
  • 32-BIT_WITH_ALPHA32-bit with alpha

(デフォルト値は次のとおりです 24-BIT_TRUE_COLOR)

String

PNG is a versatile raster format that can display in web browsers and 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. PNGs can be generated with an accompanying world file for use as georeferenced raster data.

exportToSVG (out_svg, {resolution}, {compress_to_svgz})
パラメーター説明データ タイプ
out_svg

A string that represents the path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer
compress_to_svgz

If set to True, the output is compressed.

(デフォルト値は次のとおりです False)

Boolean

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 still view SVG exports with proper symbology. You can also produce compressed SVG files. The file extension changes to *.svgz when this option is enabled.

exportToTGA (out_tga, {resolution})
パラメーター説明データ タイプ
out_tga

A string that represents the path and file name of the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer

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.

exportToTIFF (out_tif, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags})
パラメーター説明データ タイプ
out_tif

A string that represents the path and file name for the output export file.

String
resolution

A number that defines the resolution of the export file in dots per inch (dpi).

(デフォルト値は次のとおりです 96)

Integer
world_file

If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. If you export a 3D map frame, this parameter will be ignored regardless of the setting because world files are not applicable to 3D views.

(デフォルト値は次のとおりです False)

Boolean
color_mode

This value specifies the number of bits used to describe color.

  • 8-BIT_ADAPTIVE_PALETTE8-bit adaptive palette
  • 8-BIT_GRAYSCALE8-bit grayscale
  • 24-BIT_TRUE_COLOR24-bit true color
  • 32-BIT_WITH_ALPHA32-bit with alpha

(デフォルト値は次のとおりです 24-BIT_TRUE_COLOR)

String
tiff_compression

This value represents a compression scheme.

  • DEFLATEA lossless data compression.
  • JPEGJPEG compression.
  • LZWLempel-Ziv-Welch, a lossless data compression.
  • NONECompression is not applied.
  • PACK_BITSPack bits compression.

(デフォルト値は次のとおりです LZW)

String
geoTIFF_tags

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.

(デフォルト値は次のとおりです False)

Boolean

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. TIFFs also support georeferencing information in GeoTIFF tags or in a separate world file for use as raster data.

getLayerExtent (layer, {selection_only}, {symbolized_extent})
パラメーター説明データ タイプ
layer

A reference to a Layer object.

Layer
selection_only

If True, it returns the extent for selected features; if False, it returns the extent for all features.

(デフォルト値は次のとおりです True)

Boolean
symbolized_extent

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.

(デフォルト値は次のとおりです True)

Boolean
戻り値
データ タイプ説明
Extent

A geoprocessing Extent object.

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.

panToExtent (extent)
パラメーター説明データ タイプ
extent

A geoprocessing Extent object.

Extent

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.

zoomToAllLayers ({selection_only}, {symbolized_extent})
パラメーター説明データ タイプ
selection_only

If True, it sets the extent based on the selected features; if False, it sets the extent for all features in a map.

(デフォルト値は次のとおりです True)

Boolean
symbolized_extent

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.

(デフォルト値は次のとおりです True)

Boolean

If zoomToAllLayers is used on a MapFrame with a global or local scene, the result will be a planimetric view.

zoomToBookmark (bookmark)
パラメーター説明データ タイプ
bookmark

A reference to a Bookmark object.

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.

コードのサンプル

MapFrame example 1

The following script will set the extent of a map frame named Yosemite National Park on a layout named Main Attractions at Yosemite National Park to match the extent of a layer named Ranger Stations.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")

m = aprx.listMaps("Yose*")[0]
lyr = m.listLayers("Ranger Stations")[0]
lyt = aprx.listLayouts("Main Attr*")[0]
mf = lyt.listElements("mapframe_element", "Yosemite National Park")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

aprx.saveACopy(r"C:\Projects\YosemiteNP\Yosemite_Updated.aprx")
del aprx
MapFrame example 2

The following script demonstrates how to change a map frame that is referencing a 2D map to reference a 3D map. First, the script imports two documents into a blank project. Next, it references the appropriate maps and map frames. Finally, it changes the Camera type property to GLOBAL before changing the map property from a 2D map to a 3D map.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\Blank.aprx")

#Import documents into project
aprx.importDocument(r"C:\Projects\YosemiteNP\Documents\Yosemite.mxd")
aprx.importDocument(r"C:\Projects\YosemiteNP\Documents\Yosemite_3DViews.3dd")

#Reference maps
m_scenic = aprx.listMaps("Globe layers")[0]

#Reference Layout and map frames
lyt = aprx.listLayouts()[0]
mf_inset1 = lyt.listElements("MapFrame_Element", "Inset1")[0]
mf_inset2 = lyt.listElements("MapFrame_Element", "Inset2")[0]

#Convert inset maps into Globe Views
mf_inset1.camera.type = "GLOBAL"
mf_inset1.map = m_scenic
mf_inset2.camera.type = "GLOBAL"
mf_inset2.map = m_scenic

aprx.saveACopy(r"C:\Projects\YosemiteNP\Yosemite.aprx")