Skip to main content

changePageSize

汇总

Layout 对象将引用 ArcGIS Pro 工程 (.aprx) 中的单个页面布局。 可用于访问常见属性(如页面大小)和多个不同的导出方法。

讨论

ArcGIS Pro 工程可包含多个页面布局。 可使用 ArcGISProject 对象上的 listLayouts 方法访问布局,这将返回 Layout 对象的 Python 列表。 有必要确保每个布局均具有唯一名称,因为这样可以通过 name 轻松引用布局。

可以通过 listElements 方法访问页面布局上的所有元素: GraphicElementGroupElementLegendElementMapFrameElementMapSurroundElementPictureElementTableFrameElementTextElement

通过 Layout 对象可访问多个 exportTo 方法。 如果想要导出整个页面布局,可使用 Layout 导出方法。 如果只想要导出单个地图框的内容,还可使用 MapFrame 类上的一组相似的导出方法。

布局可以包括单个 MapSeries 。 如果 mapSeries 属性返回 None ,则表明尚未在布局中创建地图系列。 在尝试操作地图系列属性之前,应先检查地图系列是否为 enabled

通过 ArcGISProject 对象上的 createLayout 方法,可以完全自动化布局创建过程。 如果存在布局,则有许多其他创建方法可用于创建不同类型的布局元素。 layout 对象具有三种创建方法,可用于创建仅存在于布局中的元素。 包括 createMapFramecreateMapSurroundElementcreateTableFrameElementArcGISProject 对象包括更多创建方法,允许您在 map 中的布局或图形图层中创建元素。 这些方法包括 createGraphicElementcreateGroupElementcreatePictureElementcreatePredefinedGraphicElementcreateTextElement

openView 方法允许您打开布局的新视图窗格。 由于无法查询视图,目前无法确定视图是否已经打开,或者您的布局视图是否处于活动状态。 您可以使用 ArcGISProject 对象上的 closeViews 方法,并在布局上调用 openView 。 这将打开并激活布局,以使其具有您可能需要的区域和焦点。

注:

openViewcloseViews 方法仅适用于从应用程序内运行的脚本。 独立脚本无法访问视图窗格。

语法

changePageSize()

属性

名称 说明 数据类型

colorModel

(读取和写入)

返回分配给 Layout 对象的颜色模型。 有效值为 CMYKRGB

String

mapSeries

(只读)

如果地图系列存在且已启用,则返回 MapSeries 对象或 BookmarkMapSeries 对象,否则返回 NoneType

MapSeries

metadata

(读取和写入)

获取或设置布局的 Metadata 类信息。

注:

设置元数据取决于 isReadOnly 属性值。

Metadata

name

(读取和写入)

布局的名称。 建议所有布局都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。

String

pageHeight

(读取和写入)

布局的页面高度取决于当前的 pageUnits

Double

pageUnits

(读取和写入)

布局的页面单位。 下面是设置页面单位时可使用的有效字符串列表。

  • CENTIMETER—厘米

  • INCH—英寸

  • MILLIMETER—毫米

  • POINT—磅

String

pageWidth

(读取和写入)

布局的页面宽度取决于当前的 pageUnits

Double

URI

(只读)

布局的统一资源指示符。 这是项目中布局的唯一标识符,使用 Python CIM 访问 时有时需要它。 添加布局并建立 URI 后,该值不会随时间变化。 例如,如果您修改布局的名称,则 URI 不会更改。

String

方法

changePageSize(page_width, page_height, {resize_elements})

changePageSize 方法修改布局的大小。

名称 说明 数据类型

page_width

A double that indicates the width of a layout and is based on the page_units value.

Double

page_height

A double that indicates the height of a layout and is based on the page_units value.

Double

resize_elements

(可选)

Specifies whether the elements will be resized. If set to True, the elements on the layout will be resized proportionally. If set to False, only the page size will change, the elements will remain their original size.

(默认值为 True)

Boolean

createBookmarkMapSeries(mapframe, {bookmarks[bookmarks,...]})

此方法为布局创建一个新的 BookmarkMapSeries

名称 说明 数据类型

mapframe

A MapFrame that will have its camera settings driven by the information persisted in the bookmarks provided.

MapFrame

bookmarks[bookmarks,...]

(可选)

A list of Bookmark objects from either a single map, or multiple maps. If a list is not provided, the bookmarks that belong to the map associated with the map frame will be used instead.

List

返回值

数据类型 说明

Object

返回对新的 BookmarkMapSeries 对象的引用。

createMapFrame(geometry, {map}, {name})

createMapFrame 方法用于在布局中创建 MapFrame 元素。

名称 说明 数据类型

geometry

The appropriate Point, or Polygon object that will be used to construct the element using page units.

Object

map

(可选)

The Map associated with the MapFrame. If the default value of None is used, it can be changed at a later time.

(默认值为 None)

Map

name

(可选)

An optional string that represents the name of the new MapFrame element. If a name is not provided, the default name value will follow the automatic sequencing nomenclature, for example, Map Frame, Map Frame 1, Map Frame 2, and so on.

String

返回值

数据类型 说明

MapFrame

如果提供了变量,则其将引用新返回的 MapFrame 对象。

createMapSurroundElement(geometry, mapsurround_type, {mapframe}, {style_item}, {name})

createMapSurroundElement 方法用于在布局中创建 MapSurroundElement

名称 说明 数据类型

geometry

A Point or a Polygon object that will be used to construct the element. The map surround types have different anchor locations so if you are creating an element with a point geometry, you will need to consider positioning relative to the default anchor location.

Object

mapsurround_type

A string that represents the map surround element that will be created

  • DUAL_SCALE_BAR—A dual scale bar element will be created.

  • GRID—A grid or graticule will be created.

  • LEGEND—A legend element will be created.

  • NORTH_ARROW—A north arrow element will be created.

  • SCALE_BAR—A scale bar element will be created.

String

mapframe

(可选)

The MapFrame element that will be associated with the map surround. If the default value of None is used, it can be changed at a later time.

(默认值为 None)

MapFrame

style_item

(可选)

An optional reference to a StyleItem value. It must match the mapsuround_type input parameter. If a style_item value is not provided, a default style will be applied.

String

name

(可选)

An optional string that represents the name of the new MapSurroundElement. If a name is not provided, the default name value will follow the automatic sequencing nomenclature, for example, North Arrow, North Arrow 1, North Arrow 2, and so on.

String

返回值

数据类型 说明

MapSurroundElement

返回对新的 MapSurroundElementLegendElement 对象的引用。

createSpatialMapSeries(mapframe, index_layer, name_field, {sort_field})

此方法可为布局创建空间 MapSeries object

名称 说明 数据类型

mapframe

A MapFrame object that has an associated map that includes the index layer needed for creating the spatial map series pages.

MapFrame

index_layer

The index Layer object needed for the extents and attribute information for each page.

(默认值为 None)

Layer

name_field

The field name of the field used to control the name of each page in the map series. Ideally, all field values are unique so each page can be uniquely identified.

String

sort_field

(可选)

The name of the field that will be used to sort the map series pages.

String

返回值

数据类型 说明

MapSeries

返回对新的 MapSeries 对象的引用。

createTableFrameElement(geometry, {mapframe}, {table[table,...]}, {fields}, {style_item}, {name})

createTableFrameElement 方法用于在布局中创建 TableFrameElement 对象。

名称 说明 数据类型

geometry

A Point or a rectangular Polygon object using layout page units.

Object

mapframe

(可选)

The MapFrame element that will be associated with the table frame element. If the default value of None is used, it can be changed at a later time using the mapframe property on the TableFrameElement class.

(默认值为 None)

MapFrame

table[table,...]

(可选)

The Layer or Table object associated with the table frame element. If the default value of None is used, it can be changed at a later time using the table property on the TableFrameElement class.

(默认值为 None)

Object

fields

(可选)

A list of strings that represent the table field names to display in the table frame. If the default value of None is used, it can be changed at a later time using the fields property on the TableFrameElement class.

String

style_item

(可选)

An optional reference to a StyleItem value. When using the listStyleItems method on the ArcGISProject class, you must use the TABLE_FRAME keyword for the style_class parameter. If a style_item value is not provided, a default style will be applied.

String

name

(可选)

An optional string that represents the name of the new table frame element. If no name is provided, the default name value will follow the automatic sequencing nomenclature, for example, Table Frame, Table Frame 1, Table Frame 2, and so on.

String

返回值

数据类型 说明

Object

返回对新的 TableFrameElement 对象的引用。

deleteElement(element)

deleteElement 函数用于删除布局元素。

名称 说明 数据类型

element

An object that represents a layout element to be deleted.

Object

export(export_format, {display_options})

export 方法可使用指定 export_format 导出 Layout

名称 说明 数据类型

export_format

The supported export format objects are: AIXFormat, BMPFormat, EMFFormat, EPSFormat, GIFFormat, JPEGFormat, PDFFormat, PNGFormat, SVGFormat, TGAFormat and TIFFFormat.

Object

display_options

(可选)

The DisplayOptions object includes antialiasing mode options.

Object

exportToAIX(out_aix, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {jpeg_compression_quality}, {embed_fonts}, {embed_color_profile}, {clip_to_elements}, {keep_layout_background}, {convert_markers})

将布局导出为 Adobe Illustrator Exchange (AIX) 格式。 可在 ArcGIS Maps for Adobe Creative Cloud 扩展模块或 Adobe Illustrator 中使用 AIX 文件。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_aix

用于表示输出导出文件的路径和文件名的字符串。

String

resolution

(可选)

用于定义导出文件分辨率的数字,单位为每英寸点数 (dpi)。

(默认值为 300)

Integer

image_quality

(可选)

用于指定输出图像质量、作为栅格绘制的地图图层的绘制分辨率的字符串。

  • BEST—An output image quality resample ratio of 1

  • BETTER—An output image quality resample ratio of 2

  • NORMAL—An output image quality resample ratio of 3

  • FASTER—An output image quality resample ratio of 4

  • FASTEST—An output image quality resample ratio of 5

(默认值为 BEST)

String

compress_vector_graphics

(可选)

用于控制输出文件的矢量和文本部分压缩的布尔值。 图像压缩单独定义。

(默认值为 True)

Boolean

image_compression

(可选)

用于指定在输出文件中压缩图像或栅格数据时使用的压缩方案的字符串。

  • ADAPTIVE—Automatically 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.

  • DEFLATE—A lossless data compression.

  • JPEG—A lossy data compression.

  • JPEG2000—Offers higher quality compression with smaller file size than JPEG. This compression is lossless if jpeg_compression_quality is set to 100.

  • LZW—Lempel-Ziv-Welch, a lossless data compression.

  • NONE—Compression is not applied.

  • RLE—Run-length encoded compression.

(默认值为 ADAPTIVE)

String

jpeg_compression_quality

(可选)

image_compression 设置为 ADAPTIVEJPEG 时,用于控制压缩质量值的数字。 有效范围为 1 到 100。 jpeg_compression_quality 为 100 时可提供最佳图像质量,但会创建较大的导出文件。 推荐范围为 70 到 90。

(默认值为 80)

Integer

embed_fonts

(可选)

用于控制导出文件中的字体嵌入的布尔值。 当在未安装所需字体的计算机上查看文档时,可通过字体嵌入正确显示文本和字符标记。

(默认值为 True)

Boolean

embed_color_profile

(可选)

如果设置为 True ,则颜色配置文件信息将嵌入在图像的元数据中。

(默认值为 True)

Boolean

clip_to_elements

(可选)

如果设置为 True ,则布局将被裁剪为包含所有布局元素的最小边界框。

(默认值为 False)

Boolean

keep_layout_background

(可选)

如果设置为 True ,则保留布局的白色背景。

(默认值为 False)

Boolean

convert_markers

(可选)

用于控制将基于字符的标记符号转换为面的布尔值。 如果符号字体不可用或无法嵌入,则可用于正确显示符号。 但是,将此参数设置为 True 将禁用所有基于字符的标记符号的字体嵌入,由此会导致其外观发生变化。

(默认值为 False)

Boolean

exportToBMP(out_bmp, {resolution}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile}, {clip_to_elements})

将布局导出为 Microsoft Windows 位图格式 (BMP)。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_bmp

用于表示输出导出文件的路径和文件名的字符串。

String

resolution

(可选)

用于定义导出文件分辨率的数字,单位为每英寸点数 (dpi)。

(默认值为 96)

Integer

bmp_color_mode

(可选)

该值可指定用于描述颜色的位数。

  • 8-BIT_ADAPTIVE_PALETTE—8-bit adaptive palette

  • 8-BIT_GRAYSCALE—8-bit grayscale

  • 24-BIT_TRUE_COLOR—24-bit true color

(默认值为 24-BIT_TRUE_COLOR)

String

bmp_image_compression

(可选)

用于指定在输出文件中压缩图像或栅格数据时使用的压缩方案的字符串。 此选项仅适用于 8 位 bmp_color_mode 选项。

  • NONE—Compression is not applied.

  • RLE—Run-length encoded compression.

(默认值为 NONE)

String

embed_color_profile

(可选)

如果设置为 True ,则颜色配置文件信息将嵌入在图像的元数据中。

(默认值为 True)

Boolean

clip_to_elements

(可选)

如果设置为 True ,则布局将被裁剪为包含所有布局元素的最小边界框。

(默认值为 False)

Boolean

exportToEMF(out_emf, {resolution}, {image_quality}, {output_as_image}, {clip_to_elements}, {convert_markers})

将布局导出为增强型图元文件 (EMF) 格式。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_emf

A string that represents the system 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

image_quality

(可选)

A string that specifies output image quality, the draw resolution of map layers that draw as rasters.

  • BEST—An output image quality resample ratio of 1

  • BETTER—An output image quality resample ratio of 2

  • NORMAL—An output image quality resample ratio of 3

  • FASTER—An output image quality resample ratio of 4

  • FASTEST—An output image quality resample ratio of 5

(默认值为 BEST)

String

output_as_image

(可选)

If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output.

(默认值为 False)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

convert_markers

(可选)

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.

(默认值为 False)

Boolean

exportToEPS(out_eps, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})

将布局导出为封装 PostScript (EPS) 格式文件。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_eps

A string that represents the system 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

image_compression

(可选)

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

  • DEFLATE—A lossless data compression.

  • LZW—Lempel-Ziv-Welch, a lossless data compression.

  • NONE—Compression is not applied.

  • RLE—Run-length encoded compression.

(默认值为 DEFLATE)

String

image_quality

(可选)

A string that specifies output image quality, the draw resolution of map layers that draw as rasters.

  • BEST—An output image quality resample ratio of 1.

  • BETTER—An output image quality resample ratio of 2.

  • NORMAL—An output image quality resample ratio of 3.

  • FASTER—An output image quality resample ratio of 4.

  • FASTEST—An output image quality resample ratio of 5.

(默认值为 BEST)

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

output_as_image

(可选)

If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output.

(默认值为 False)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

convert_markers

(可选)

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.

(默认值为 False)

Boolean

exportToGIF(out_gif, {resolution}, {gif_color_mode}, {clip_to_elements})

将布局导出为图形交换格式 (GIF)。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_gif

A string that represents the system 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

gif_color_mode

(可选)

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

  • 8-BIT_ADAPTIVE_PALETTE—8-bit adaptive palette

  • 8-BIT_GRAYSCALE—8-bit grayscale

(默认值为 8-BIT_ADAPTIVE_PALETTE)

String

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

exportToJPEG(out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile}, {clip_to_elements})

将布局导出为联合图像专家组 (JPEG) 格式文件。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_jpg

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

jpeg_color_mode

(可选)

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

  • 8-BIT_GRAYSCALE—8-bit grayscale

  • 24-BIT_TRUE_COLOR—24-bit true color

(默认值为 24-BIT_TRUE_COLOR)

String

jpeg_quality

(可选)

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.

(默认值为 80)

Integer

embed_color_profile

(可选)

If set to True, color profile information is embedded in the image's metadata.

(默认值为 True)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

exportToPAGX(out_pagx)

将布局导出至页面文件 (.pagx)。

名称 说明 数据类型

out_pagx

A string used to save a layout to a page file (.pagx).

String

exportToPDF(out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {output_as_image}, {embed_color_profile}, {pdf_accessibility}, {keep_layout_background}, {convert_markers}, {simulate_overprint})

用于将布局导出为便携文档格式 (PDF)。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_pdf

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).

(默认值为 300)

Integer

image_quality

(可选)

A string that specifies output image quality, the draw resolution of map layers that draw as rasters.

  • BEST—An output image quality resample ratio of 1

  • BETTER—An output image quality resample ratio of 2

  • NORMAL—An output image quality resample ratio of 3

  • FASTER—An output image quality resample ratio of 4

  • FASTEST—An 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 specifies the compression scheme used to compress image or raster data in the output file.

  • ADAPTIVE—Automatically 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.

  • DEFLATE—A lossless data compression.

  • JPEG—A lossy data compression.

  • JPEG2000—Offers higher quality compression with smaller file size than JPEG. This compression is lossless if jpeg_compression_quality is set to 100.

  • LZW—Lempel-Ziv-Welch, a lossless data compression.

  • NONE—Compression is not applied.

  • RLE—Run-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 specifies whether the PDF layer and PDF object data (attributes) will be included in the export file.

  • LAYERS_ONLY—Export PDF layers only

  • LAYERS_AND_ATTRIBUTES—Export PDF layers and feature attributes

  • NONE—None

(默认值为 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 between 70 and 90.

(默认值为 80)

Integer

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

output_as_image

(可选)

If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output.

(默认值为 False)

Boolean

embed_color_profile

(可选)

If set to True, color profile information is embedded in the image's metadata.

(默认值为 True)

Boolean

pdf_accessibility

(可选)

Output a tagged PDF file where text can be read by screen readers or other assistive technology. A tagged PDF file can include alt text—a text description of a graphic element that a screen reader uses to describe the element—for map frames, pictures, and chart frames. Alt text is added in the Element Pane for each element.

(默认值为 False)

Boolean

keep_layout_background

(可选)

If set to True, the white background will be included in the export.

(默认值为 True)

Boolean

convert_markers

(可选)

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.

(默认值为 False)

Boolean

simulate_overprint

(可选)

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.

(默认值为 False)

Boolean

exportToPNG(out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements})

将布局导出为便携式网络图形 (PNG) 格式文件。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_png

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

color_mode

(可选)

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

  • 8-BIT_ADAPTIVE_PALETTE—8-bit adaptive palette

  • 8-BIT_GRAYSCALE—8-bit grayscale

  • 24-BIT_TRUE_COLOR—24-bit true color

  • 32-BIT_WITH_ALPHA—32-bit with alpha

(默认值为 32-BIT_WITH_ALPHA)

String

transparent_background

(可选)

If set to True, the white page background is set to transparent.

(默认值为 False)

Boolean

embed_color_profile

(可选)

If set to True, color profile information is embedded in the image's metadata.

(默认值为 True)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

exportToSVG(out_svg, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})

将布局导出为可伸缩矢量图形 (SVG) 格式。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_svg

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

compress_to_svgz

(可选)

If set to True, the output is compressed.

(默认值为 False)

Boolean

image_quality

(可选)

A string that specifies output image quality, the draw resolution of map layers that draw as rasters.

  • BEST—An output image quality resample ratio of 1.

  • BETTER—An output image quality resample ratio of 2.

  • NORMAL—An output image quality resample ratio of 3.

  • FASTER—An output image quality resample ratio of 4.

  • FASTEST—An output image quality resample ratio of 5.

(默认值为 BEST)

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

output_as_image

(可选)

If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output.

(默认值为 False)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

convert_markers

(可选)

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.

(默认值为 False)

Boolean

exportToTGA(out_tga, {resolution}, {color_mode}, {transparent_background}, {clip_to_elements})

将布局导出为 Truevision 图形适配器 (TGA) 格式。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_tga

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

color_mode

(可选)

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

  • 8-BIT_ADAPTIVE_PALETTE—8-bit adaptive palette

  • 8-BIT_GRAYSCALE—8-bit grayscale

  • 24-BIT_TRUE_COLOR—24-bit true color

  • 32-BIT_WITH_ALPHA—32-bit with alpha

(默认值为 32-BIT_WITH_ALPHA)

String

transparent_background

(可选)

If set to True, the white page background is set to transparent.

(默认值为 False)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

exportToTIFF(out_tif, {resolution}, {color_mode}, {tiff_compression}, {jpeg_compression_quality}, {transparent_background}, {embed_color_profile}, {clip_to_elements}, {world_file}, {geoTIFF_tags}, {georef_mapframe})

将布局导出为标记图像文件格式 (TIFF) 文件。

旧版本:

此方法在 ArcGIS Pro 3.4 中已被 export 取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。

名称 说明 数据类型

out_tif

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

color_mode

(可选)

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.

  • 8-BIT_ADAPTIVE_PALETTE—8-bit adaptive palette. Available to RGB and CMYK.

  • 8-BIT_GRAYSCALE—8-bit grayscale. Available to RGB and CMYK.

  • 24-BIT_TRUE_COLOR—24-bit true color. Available only to RGB.

  • 32-BIT_WITH_ALPHA—32-bit with alpha. Available only to RGB.

  • 32-BIT_CMYK_TRUE_COLOR—32-bit CMYK true color. Available only to CMYK.

  • 40-BIT_CMYK_WITH_ALPHA—40-bit CMYK with alpha. Available only to CMYK.

(默认值为 24-BIT_TRUE_COLOR)

String

tiff_compression

(可选)

This value represents a compression scheme.

  • DEFLATE—A lossless data compression.

  • JPEG—JPEG compression.

  • LZW—Lempel-Ziv-Welch, a lossless data compression.

  • NONE—Compression is not applied.

  • PACK_BITS—Pack bits compression.

(默认值为 LZW)

String

jpeg_compression_quality

(可选)

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.

(默认值为 80)

Integer

transparent_background

(可选)

If set to True, the white page background is set to transparent.

(默认值为 False)

Boolean

embed_color_profile

(可选)

If set to True, color profile information is embedded in the image's metadata.

(默认值为 True)

Boolean

clip_to_elements

(可选)

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(默认值为 False)

Boolean

world_file

(可选)

If set to True and a valid georef_mapframe is set, a world file will be generated based on the map frame's coordinate system.

(默认值为 False)

Boolean

geoTIFF_tags

(可选)

If set to True and a valid georef_mapframe is set, geoTIFF tags will be embedded in the resulting image based on the map frame's coordinate system.

(默认值为 False)

Boolean

georef_mapframe

(可选)

The MapFrame used to control the coordinate system when geoTIFF_tags are set to True.

(默认值为 None)

MapFrame

getDefinition(cim_version)

获取布局的 CIM 定义。

名称 说明 数据类型

cim_version

A string that represents the major version of the CIM.

String

返回值

数据类型 说明

Object

返回 Layout 对象的 CIM 定义。

listElements({element_type}, {wildcard})

返回 Layout 对象包含的页面布局元素的 Python 列表。

名称 说明 数据类型

element_type

(可选)

A string that represents the element type that will be used to filter the returned list of elements.

(默认值为 None)

String

wildcard

(可选)

A wildcard is based on the element name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the results.

(默认值为 None)

String

返回值

数据类型 说明

List

页面布局元素的 Python 列表。 可返回的对象类型为 GraphicElementGroupElementLegendElementMapFrameMapsurroundElementPictureElementTableFrameElementTextElement

openView()

在应用程序中打开并激活一个新的布局视图窗格。

setColorModel(color_model)

用于设置与布局关联的颜色模型的字符串常量。

名称 说明 数据类型

color_model

以下是有效字符串列表。

  • CMYK— Cyan, Magenta, Yellow, Black

  • RGB— Red, Green, Blue

String

setDefinition(definition_object)

设置布局的 CIM 定义。

名称 说明 数据类型

definition_object

使用 getDefinition 最初检索的已修改 CIM 定义对象。

Object

代码示例

布局示例 1

以下脚本遍历当前工程中的所有布局,并打印每个布局的基本信息,包括名称、页面大小和单位、地图框数量、地图框名称以及布局元素的总数。

aprx = arcpy.mp.ArcGISProject('CURRENT')
print(f'Total Project Layout Count: {str(len(aprx.listLayouts()))} \n')
for lyt in aprx.listLayouts():
    print(f'Layout Name: {lyt.name}')
    print(f'    Width x height: {lyt.pageWidth} x {lyt.pageHeight} units are {lyt.pageUnits}')
    print(f'    MapFrame count: {str(len(lyt.listElements("MapFrame_Element")))}')
    for mf in lyt.listElements("MapFrame_Element"):
        if len(lyt.listElements("MapFrame_Element")) > 0:
            print(f'        MapFrame name: {mf.name}')
    print(f'    Total element count: {str(len(lyt.listElements()))} \n')
布局示例 2

以下脚本遍历布局名称列表,并将每个布局导出为 PDF 文件两次。 第一次 export 将使用默认 PDFFormat 设置。 第二次 export 会生成一个小得多的输出文件,因为将相应地在 PDFFormat 对象上设置 resolutionimage_qualityoutput_as_image 属性。

import arcpy, os
prjPath = r'C:\Projects\YosemiteNP'
p = arcpy.mp.ArcGISProject(os.path.join(prjPath, 'YosemiteTrails.aprx'))

layoutNames = ['Main Attractions', 'Scenic Views']
for lytName in layoutNames:
    lyt = p.listLayouts(lytName)[0]

    #export to PDF - default settings
    pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(prjPath, 'Output', f'{lytName}_defaults.pdf'))
    lyt.export(pdf)

    #export to PDF - smaller file size
    pdf.filePath = os.path.join(prjPath, 'Output', f'{lytName}_small.pdf')
    pdf.setImageQuality("FASTEST")
    pdf.outputAsImage = True
    pdf.resolution = 72
    lyt.export(pdf)
布局示例 3

以下脚本创建了一个地图和布局。 它还在布局中创建了一个地图框、指北针和比例尺。 矩形辅助函数用于创建地图框和比例尺所需的几何。 最后,它确保在应用程序中打开并激活新布局。

def MakeRec_LL(llx, lly, w, h):
    xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]
    array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
    rec = arcpy.Polygon(array)
    return rec

p = arcpy.mp.ArcGISProject('current')

#Create a new map and layout
m = p.createMap('New Map', 'MAP')
lyt = p.createLayout(8.5, 11, 'INCH')

#Create a map frame
mf = lyt.createMapFrame(MakeRec_LL(0.5,5.5,7.5,5), m, "New Map Frame")

#Create a north arrow
naStyle = p.listStyleItems('ArcGIS 2D', 'North_Arrow', 'Compass North 1')[0]
na = lyt.createMapSurroundElement(arcpy.Point(7,7), 'North_Arrow', mf,
                                      naStyle, "Compass North Arrow")
na.elementWidth = 0.5

#Create a scale bar
sbName = 'Double Alternating Scale Bar 1 Metric'
sbStyle = p.listStyleItems('ArcGIS 2D', 'Scale_bar', sbName)[0]
sbEnv = MakeRec_LL(0.5, 5.5, 2.5, 0.5)
sb = lyt.createMapSurroundElement(sbEnv, 'Scale_bar', mf, sbStyle, 'New Scale Bar')

#Close all view and open and active the layout view
p.closeViews()
lyt.openView()
布局示例 4

以下脚本展示了使用 deleteElement 的不同方式。 请注意,要移除可能存在于其他组元素内部的组元素,必须以相反的顺序删除组元素,因为在删除父元素之前,必须先删除子元素。

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]

#Delete one element by name
elm = lyt.listElements('GRAPHIC_ELEMENT', 'Point')[0]
lyt.deleteElement(elm)

#Delete all the group elements and their children in reverse order
for elm in reversed(lyt.listElements('GROUP_ELEMENT')):
    lyt.deleteElement(elm)

#Delete remaining elements
for elm in lyt.listElements():
    lyt.deleteElement(elm)
布局示例 5

以下脚本演示了如何使用 Python CIM 访问 向布局添加参考线。 它在布局中创建了四条距离布局边缘 0.5 英寸的新参考线。

#CAUTION - this script will remove any existing guides

p = arcpy.mp.ArcGISProject('CURRENT')

for lyt in p.listLayouts():
    lyt_cim = lyt.getDefinition('V3')

    newGuides = []

    #Bottom horizontal guide
    botHorz = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
    botHorz.position = 0.5
    botHorz.orientation = 'Horizontal'
    newGuides.append(botHorz)

    #Top horizontal guide
    topHorz = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
    topHorz.position = lyt.pageHeight - 0.5
    topHorz.orientation = 'Horizontal'
    newGuides.append(topHorz)

    #Left vertical guide
    leftVert = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
    leftVert.position = 0.5
    leftVert.orientation = 'Vertical'
    newGuides.append(leftVert)

    #Right vertical guide
    rightVert = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
    rightVert.position = lyt.pageWidth - 0.5
    rightVert.orientation = 'Vertical'
    newGuides.append(rightVert)

    #Add guides and make sure they are turned on
    lyt_cim.page.guides = newGuides
    lyt_cim.page.showGuides = True

    #Set back to layer
    lyt.setDefinition(lyt_cim)