摘要
Layout 对象将引用 ArcGIS Pro 工程 (.aprx) 中的单个页面布局。 可用于访问常见属性(如页面大小)和多个不同的导出方法。
说明
ArcGIS Pro 工程可包含多个页面布局。 可使用 ArcGISProject 对象上的 listLayouts 方法访问布局,这将返回 Layout 对象的 Python 列表。 有必要确保每个布局均具有唯一名称,因为这样可以通过 name 轻松引用布局。
可以通过 listElements 方法访问页面布局上的所有元素:GraphicElement、GroupElement、LegendElement、MapFrameElement、MapSurroundElement、PictureElement、TableFrameElement 和 TextElement。
通过 Layout 对象可访问多个 exportTo 方法。 如果想要导出整个页面布局,可使用 Layout 导出方法。 如果只想要导出单个地图框的内容,还可使用 MapFrame 类上的一组相似的导出方法。
布局可以包括单个 MapSeries。 如果 mapSeries 属性返回 None,则表明尚未在布局中创建地图系列。 在尝试操作地图系列属性之前,应先检查地图系列是否为 enabled。
通过 ArcGISProject 对象上的 createLayout 方法,可以完全自动化布局创建过程。 如果存在布局,则有许多其他创建方法可用于创建不同类型的布局元素。 layout 对象具有三种创建方法,可用于创建仅存在于布局中的元素。 包括 createMapFrame、createMapSurroundElement 和 createTableFrameElement。 ArcGISProject 对象包括更多创建方法,允许您在 map 中的布局或图形图层中创建元素。 这些方法包括 createGraphicElement、createGroupElement、createPictureElement、createPredefinedGraphicElement 和 createTextElement。
openView 方法允许您打开布局的新视图窗格。 由于无法查询视图,目前无法确定视图是否已经打开,或者您的布局视图是否处于活动状态。 您可以使用 ArcGISProject 对象上的 closeViews 方法,并在布局上调用 openView。 这将打开并激活布局,以使其具有您可能需要的区域和焦点。
注:
openView 和 closeViews 方法仅适用于从应用程序内运行的脚本。 独立脚本无法访问视图窗格。
属性
属性 | 说明 | 数据类型 |
mapSeries (只读) | 如果启用了空间地图系列,则将返回 MapSeries 对象。 如果地图系列不存在或者其为书签地图系列,则将返回 NoneType。 | MapSeries |
metadata (可读写) | 获取或设置布局的元数据类信息。 注:设置元数据取决于 isReadOnly 属性值。 | Metadata |
name (可读写) | 布局的名称。 有必要确保所有布局都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。 | String |
pageHeight (可读写) | 布局的页面高度取决于当前的 pageUnits。 | Double |
pageUnits (可读写) | 布局的页面单位。 下面是设置页面单位时可使用的有效字符串列表。
| String |
pageWidth (可读写) | 布局的页面宽度取决于当前的 pageUnits。 | Double |
URI (只读) | 布局的统一资源指示符。 这是项目中布局的唯一标识符,使用 Python CIM 访问时有时需要它。 添加布局并建立 URI 后,该值不会随时间变化。 例如,如果您修改布局的名称,则 URI 不会更改。 | String |
方法概述
方法 | 说明 |
changePageSize (page_width, page_height, {resize_elements}) | changePageSize 方法修改布局的大小。 |
createBookmarkMapSeries (mapframe, {bookmarks}) | 此方法为布局创建一个新的 BookmarkMapSeries。 |
createMapFrame (geometry, {map}, {name}) | createMapFrame 方法用于在布局中创建 MapFrame 元素。 |
createMapSurroundElement (geometry, mapsurround_type, {mapframe}, {style_item}, {name}) | createMapSurroundElement 方法用于在布局中创建 MapSurroundElement。 |
createSpatialMapSeries (mapframe, index_layer, name_field, {sort_field}) | 此方法可为布局创建空间 MapSeries object。 |
createTableFrameElement (geometry, {mapframe}, {table}, {fields}, {style_item}, {name}) | createTableFrameElement 方法用于在布局中创建 TableFrameElement 对象。 |
deleteElement (element) |
deleteElement 函数用于删除布局元素。 |
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 文件。 |
exportToBMP (out_bmp, {resolution}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile}, {clip_to_elements}) | 将布局导出为 Microsoft Windows 位图格式 (BMP)。 |
exportToEMF (out_emf, {resolution}, {image_quality}, {output_as_image}, {clip_to_elements}, {convert_markers}) | 将布局导出为增强型图元文件 (EMF) 格式。 |
exportToEPS (out_eps, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers}) | 将布局导出为封装 PostScript (EPS) 格式文件。 |
exportToGIF (out_gif, {resolution}, {gif_color_mode}, {clip_to_elements}) | 将布局导出为图形交换格式 (GIF)。 |
exportToJPEG (out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile}, {clip_to_elements}) | 将布局导出为联合图像专家组 (JPEG) 格式文件。 |
exportToPAGX (out_pagx) |
将布局导出至页面文件 (.pagx)。 |
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)。 |
exportToPNG (out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements}) | 将布局导出为便携式网络图形 (PNG) 格式文件。 |
exportToSVG (out_svg, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers}) | 将布局导出为可伸缩矢量图形 (SVG) 格式。 |
exportToTGA (out_tga, {resolution}, {color_mode}, {transparent_background}, {clip_to_elements}) | 将布局导出为 Truevision 图形适配器 (TGA) 格式。 |
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) 文件。 |
getDefinition (cim_version) | 获取布局的 CIM 定义。 |
listElements ({element_type}, {wildcard}) | 返回 Layout 对象包含的页面布局元素的 Python 列表。 |
openView () | 在应用程序中打开并激活一个新的布局视图窗格。 |
setDefinition (definition_object) | 设置布局的 CIM 定义。 |
方法
changePageSize (page_width, page_height, {resize_elements})
参数 | 说明 | 数据类型 |
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 |
输入大小参数基于布局的 page_units 值和无法更改的单位。
createBookmarkMapSeries (mapframe, {bookmarks})
参数 | 说明 | 数据类型 |
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 对象的引用。 |
为每个书签创建一个书签地图系列页面。 有关详细信息和代码示例,请参阅 BookmarkMapSeries 帮助主题。
createMapFrame (geometry, {map}, {name})
参数 | 说明 | 数据类型 |
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})
参数 | 说明 | 数据类型 |
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
| 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 | 返回对新的 MapSurroundElement 或 LegendElement 对象的引用。 |
如果元素使用点几何进行创建,则点位置将代表 anchor 位置,并且存在默认大小。 稍后,可以使用 elementWidth 和 elementHeight 属性调整元素的大小。
此方法会返回对新的 MapSurroundElement 或 LegendElement 类的引用。 默认锚点位置取决于地图整饰要素类型,但是可以在使用 setAnchor 方法将新元素添加到布局后进行更改。
有关详细信息和代码示例,请参阅 MapSurroundElement 或 LegendElement 类帮助主题。
createSpatialMapSeries (mapframe, index_layer, name_field, {sort_field})
参数 | 说明 | 数据类型 |
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 对象的引用。 |
将为索引图层中的每个要素创建一个地图系列页面。 有关详细信息和代码示例,请参阅 MapSeries 帮助主题。
createTableFrameElement (geometry, {mapframe}, {table}, {fields}, {style_item}, {name})
参数 | 说明 | 数据类型 |
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 theTABLE_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 对象的引用。 |
如果元素使用点几何进行创建,则点位置将代表 anchor 位置,并且将应用默认大小。 稍后可以使用 elementWidth 和 elementHeight 属性调整 TableFrameElement 对象的大小。 元素扩展或缩小的方向基于 anchor 位置。
此方法会返回对新 TableFrameElement 类的参考。 有关详细信息和代码示例,请参阅 TableFrameElement 类帮助主题。
deleteElement (element)
参数 | 说明 | 数据类型 |
element | An object that represents a layout element to be deleted. | 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})
参数 | 说明 | 数据类型 |
out_aix | 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) | 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) | String |
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 |
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 |
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 |
keep_layout_background | If set to True, the layout's white background will be kept. (默认值为 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 |
AIX 是从 ArcGIS 导出的 Adobe Illustrator Exchange 文件,可在 ArcGIS Maps for Adobe Creative Cloud 插件中使用。 与插件配合使用时,矢量地图和栅格地图内容将转换为可编辑的 Artwork 图层,以改善 Adobe Illustrator 中的编辑体验。 在 Illustrator 中打开 AIX 后,可用于高端图形设计或地图最后处理工作流,并可在其他 Adobe Creative Cloud 应用程序之间进行迁移。
exportToBMP (out_bmp, {resolution}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile}, {clip_to_elements})
参数 | 说明 | 数据类型 |
out_bmp | 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 |
bmp_color_mode | This value specifies the number of bits used to describe color.
(默认值为 24-BIT_TRUE_COLOR) | String |
bmp_image_compression | 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 bmp_color_mode options.
(默认值为 NONE) | String |
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 |
BMP 文件属于本地 Windows 栅格图像。 BMP 文件可以使用多个位深度存储像素数据。 BMP 图像的大小通常比 JPEG 或 PNG 等格式的图像大很多。
exportToEMF (out_emf, {resolution}, {image_quality}, {output_as_image}, {clip_to_elements}, {convert_markers})
参数 | 说明 | 数据类型 |
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) | 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 |
EMF 文件属于本地 Windows 图形文件,其中既包含矢量数据又包含栅格数据。 这些文件非常适合于嵌入 Windows 文档,因为 EMF 的矢量部分可以调整大小,而又不会降低质量。 但是,由于 EMF 不支持字体嵌入并且属于 Windows 专用格式,因此并不常用作用户之间的交换格式。
exportToEPS (out_eps, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})
参数 | 说明 | 数据类型 |
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) | String |
image_quality | A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
(默认值为 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 |
EPS 文件将通过 PostScript 页面描述语言描述矢量对象和栅格对象。 PostScript 是高端图形文件、制图和打印的出版行业标准。 许多绘图应用程序中都可编辑 EPS 文件,也可将此类文件作为图形置于大多数页面布局应用程序中。 EPS 文件支持字体嵌入,因此即使用户尚未安装 Esri 字体也可以查看正确的符号。
exportToGIF (out_gif, {resolution}, {gif_color_mode}, {clip_to_elements})
参数 | 说明 | 数据类型 |
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) | String |
clip_to_elements | If set to True, the layout is clipped to the smallest bounding box that includes all layout elements. (默认值为 False) | Boolean |
GIF 文件属于 Web 中使用的旧的栅格格式。 GIF 文件无法显示 256 种以上的颜色(每像素 8 位),并且使用的是可选的无损压缩,因此,该类文件的大小比其他格式的文件要小。
exportToJPEG (out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile}, {clip_to_elements})
参数 | 说明 | 数据类型 |
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.
(默认值为 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 |
JPEG 文件属于经过压缩的图像文件。 它支持 24 位颜色并且是 Web 上流行的使用格式,因为 JPEG 文件大小通常要比许多其他图像格式小很多。 但是,JPEG 压缩算法会有损质量,多数地图图像中都不推荐使用,因为线绘图以及文本或图标图形会因压缩产生的伪影而变得模糊。 因此,通常 PNG 格式才是地图图像的首选。
exportToPAGX (out_pagx)
参数 | 说明 | 数据类型 |
out_pagx | A string used to save a layout to a page file (.pagx). | String |
如果您希望将布局保存至页面文件,以供日后使用 ArcGISProject importDocument 方法将其导入到工程中,则此方法将非常有用。
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})
参数 | 说明 | 数据类型 |
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) | 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) | 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) | 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 |
PDF 文件可跨不同平台实现一致的查看和打印效果。 它们常用于在 Web 上分发文档,并且此格式现在属于文档交换的 ISO 官方标准。 PDF 文件在许多图形应用程序中均可编辑,并会保留地图的地理配准信息、注记、标注和要素属性数据。 PDF 导出支持字体嵌入,即使在用户尚未安装 Esri 字体时,也可以正确显示符号系统。
查看 PDFDocument 类以了解更多关于如何管理 PDF 文件的方法,如追加、插入以及设置属性。
exportToPNG (out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements})
参数 | 说明 | 数据类型 |
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.
(默认值为 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 |
PNG 文件属于通用型栅格格式文件,可在各种 Web 浏览器上显示并且还可插入其他文档。 它支持高位深度颜色并使用无损压缩。 对于地图而言,PNG 通常是最佳的栅格格式,因为无损压缩可防止产生 JPEG 格式中的那种压缩伪影,从而使文本和线作业始终清晰可辨。 PNG 文件还可定义透明颜色。
exportToSVG (out_svg, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})
参数 | 说明 | 数据类型 |
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) | 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 |
SVG 是一种基于 XML 的文件格式,专门适用于在 Web 上进行查看。 SVG 可以同时包含矢量信息和栅格信息。 一些 web 浏览器可能需要插件才能查看 SVG 文件。 较早版本的浏览器可能根本无法查看 SVG 文件。 SVG 支持字体嵌入,因此即使用户尚未安装 Esri 字体也可以使用正确符号系统查看导出的 SVG 文件。 也可以选择生成压缩的 SVG 文件。 如果启用此选项,文件扩展名变为 .svgz。
exportToTGA (out_tga, {resolution}, {color_mode}, {transparent_background}, {clip_to_elements})
参数 | 说明 | 数据类型 |
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.
(默认值为 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 |
TGA 文件以往用于其他应用程序中的内容(例如,动画游戏的 Image Sprites),许多受欢迎的图形艺术应用程序均可对该文件进行读取和写入。 TGA 格式支持多位深度,包括支持 alpha(透明)的 32 位。
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})
参数 | 说明 | 数据类型 |
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.
(默认值为 24-BIT_TRUE_COLOR) | String |
tiff_compression | This value represents a compression scheme.
(默认值为 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 |
TIFF 文件最适合导入图像编辑应用程序,同时它也属于一种常用的 GIS 栅格数据格式。 但是却无法通过 Web 浏览器在本地查看这些文件。
getDefinition (cim_version)
参数 | 说明 | 数据类型 |
cim_version | A string that represents the major version of the CIM. | String |
在 ArcGIS Pro 2.4 中引入了对其他对象属性的 CIM 级别访问权限。 要返回对象的 CIM 定义,必须指定 cim_version。 Esri 遵循语义版本规范。 这意味着在主要版本(例如 3.0)中允许突破性 API 更改。 如果可能在新版本中引入突破性更改,Python 脚本作者可通过该值控制脚本运行期间使用的 CIM 版本。 如果您正在为 ArcGIS Pro 2.x 创作脚本,可将 cim_version 指定为 'V2'。 如果您正在为 ArcGIS Pro 3.x 创作脚本,可将 cim_version 指定为 'V3'。 使用 cim_version 'V2' 创作的脚本可继续在 ArcGIS Pro 3.x 中使用。
有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问。
listElements ({element_type}, {wildcard})
参数 | 说明 | 数据类型 |
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 列表。 可返回的对象类型为 GraphicElement、GroupElement、LegendElement、MapFrame、MapsurroundElement、PictureElement、TableFrameElement 和 TextElement。 |
每个页面元素均具有 name 属性,该属性可在“元素属性”对话框中进行设置。 布局作者应负责确保每个页面元素被赋予唯一名称,以便可以唯一标识这些元素。 如果两个元素有相同名称,则没有办法确保它就是您要引用的元素。
listElements 方法会将元素组里的元素返回到平面列表。 这使您可以方便地搜索和替换文本字符串,例如不必通过组元素结构进行浏览。
可通过在 None 中传送或添加所跳过参数后面的所有参数的参数名称跳过 element_type 参数。 例如
elm = lyt.listElements(None, "Title")[0]
#or
elm = lyt.listElements(wildcard="Title")[0]
openView ()
如果布局视图尚未打开,或者应用程序中的另一个视图处于活动状态,则此方法将非常有用。 该方法将创建一个缩放至其全图范围的布局视图并将其激活。 在打开新视图之前,要关闭其他现有视图,请使用 ArcGISProject closeViews 方法。
注:
此方法旨在使用脚本工具、Notebook 或 Python 窗口在应用程序中运行。 如果在应用程序之外运行该方法,则其将无效。
setDefinition (definition_object)
参数 | 说明 | 数据类型 |
definition_object | 使用 getDefinition 最初检索的已修改 CIM 定义对象。 | Object |
有关使用 CIM 和示例的详细信息,请参阅 Python CIM 访问。
代码示例
以下脚本遍历当前工程中的所有布局,并打印每个布局的基本信息,包括名称、页面大小和单位、地图框数量、地图框名称以及布局元素的总数。
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')
以下脚本遍历布局名称列表,并将每个布局导出为 PDF 文件两次。 第一次导出使用 exportToPDF 默认设置。 第二次导出将相应地设置 resolution、image_quality 和 output_as_image 参数,从而显著缩小输出文件大小。
import arcpy, os
prjPath = r'C:\Projects\YosemiteNP'
p = arcpy.mp.ArcGISProject(os.path.join(prjPath, 'Yosemite.aprx'))
layoutNames = ['Main Attractions', 'Scenic Views']
for name in layoutNames:
lyt = p.listLayouts(name)[0]
#export to PDF - default settings
lyt.exportToPDF(os.path.join(prjPath, 'Output', name + '_defaults.pdf'))
#export to PDF - smaller file size
lyt.exportToPDF(os.path.join(prjPath, 'Output', name + '_small.pdf'), 100,
image_quality = 3,
output_as_image = True)
以下脚本创建了一个地图和布局。 它还在布局中创建了一个地图框、指北针和比例尺。 矩形辅助函数用于创建地图框和比例尺所需的几何。 最后,它确保在应用程序中打开并激活新布局。
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()
以下脚本展示了使用 deleteElement 的不同方式。 请注意,要移除可能存在于其他组元素内部的组元素,必须以相反的顺序删除组元素,因为在删除父元素之前,必须先删除子元素。
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]
#Delete one element by name
elm = lyt.listElement('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)
以下脚本演示了如何使用 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)