MapView

摘要

MapView 类旨在用于两个工作流中。 首先,它可以用于 ArcGIS Pro 工程中以访问当前活动的地图视图。 其次,可以在 web 地图打印应用程序中将其与 ConvertWebMapToArcGISProject 配合使用,以访问要打印或导出的地图视图。

说明

ArcGIS Pro 工程中,MapView 类可用于获取对活动地图视图的访问权限。 如果地图视图处于活动状态,则 ArcGISProject 类中的 activeView 属性将返回 MapView 对象,如果布局视图或报表视图处于活动状态,则其将返回 LayoutReport 对象。 任何其他类型的视图都会返回 NoneactiveView 属性适用于要在 ArcGIS Pro 应用程序中执行的脚本,例如在 Python 窗格中运行的脚本或者与 脚本工具相关联的脚本。

activeView 属性返回的 MapView 是更改与视图相关联的照相机范围的主要方法。 还可以在调用 openView 方法之前在 Map 对象上更改 defaultCamera 属性,新打开的视图将采用这些照相机设置。 ArcGISProject 类具有 closeViews 方法,用于在打开视图之前关闭不必要的视图,从而更集中地查看该视图。

MapView 类也可以用于 web 地图打印工作流。 MapView 类可提供对地图视图的访问权限,以便打印或导出不包含页面布局周围要素(例如,标题、图例和比例尺)的 web 地图。 这通常由正在创建 Web 地图打印应用程序的 Web 应用程序开发人员使用。 有关详细信息,请参阅 ConvertWebMapToArcGISProject

警告:

并非所有 MapView 方法均适用于 web 应用程序开发人员。 Web 地图打印应用程序中不支持以下方法:

  • getLayerExtent
  • panToExtent
  • zoomToAllLayers
  • zoomToBookmark

属性

属性说明数据类型
camera
(可读写)

Camera 属性用于控制数据在地图视图中显示的位置和查看位置。可以更改照相机属性,例如范围。

Camera
map
(只读)

MapView 相关联的地图

Map

方法概述

方法说明
createBookmark ({name}, {description})

createBookmark 方法可使用当前相机设置为与地图视图相关联的地图创建书签

exportToAIX (out_aix, width, height, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {jpeg_compression_quality}, {embed_fonts}, {embed_color_profile}, {convert_markers})

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

exportToBMP (out_bmp, width, height, {resolution}, {world_file}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile})

用于将 MapView 导出为 Microsoft Windows 位图 (BMP) 格式文件。

exportToEMF (out_emf, width, height, {resolution}, {image_quality}, {output_as_image}, {convert_markers})

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

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

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

exportToGIF (out_gif, width, height, {resolution}, {world_file}, {gif_color_mode})

用于将 MapView 导出为图形交换格式 (GIF) 文件。

exportToJPEG (out_jpg, width, height, {resolution}, {world_file}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile})

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

exportToPDF (out_pdf, width, height, {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})

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

exportToPNG (out_png, width, height, {resolution}, {world_file}, {color_mode}, {embed_color_profile})

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

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

将 MapView 导出为可伸缩矢量图形 (SVG) 格式文件。

exportToTGA (out_tga, width, height, {resolution}, {world_file}, {color_mode})

用于将 MapView 导出为 Truevision 图形适配器 (TGA) 格式文件。

exportToTIFF (out_tif, width, height, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags}, {jpeg_compression_quality}, {embed_color_profile})

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

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

返回图层中所有要素或仅仅所选要素的图层范围。

panToExtent (extent)

使用新 Extent 对象可平移和居中 MapView,而无需更改地图视图的比例。

zoomToAllLayers ({selection_only}, {symbolized_extent})

修改 MapView 视图以便与所有图层或地图中所选图层的范围相匹配。

zoomToBookmark (bookmark)

修改 MapView 视图以便与通过空间书签存储的视图信息相匹配。

方法

createBookmark ({name}, {description})
参数说明数据类型
name

An optional string that represents the name of the new bookmark. If a name is not provided, the default name value will follow the sequencing nomenclature, for example, Bookmark, Bookmark [1], Bookmark [2], and so on.

String
description

An optional string that represents the bookmark's description.

(默认值为 Map)

String
返回值
数据类型说明
Bookmark

书签对象。

此方法会返回对新 Bookmark 类的参考。 请参阅 Bookmark 类帮助主题中的代码示例。

exportToAIX (out_aix, width, height, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {jpeg_compression_quality}, {embed_fonts}, {embed_color_profile}, {convert_markers})
参数说明数据类型
out_aix

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

  • 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 specifies 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.
  • JPEG2000Offers higher quality compression with smaller file size than JPEG. This compression is lossless if jpeg_compression_quality is set to 100.
  • LZWLempel-Ziv-Welch, a lossless data compression.
  • NONECompression is not applied.
  • RLERun-length encoded compression.

(默认值为 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
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, width, height, {resolution}, {world_file}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile})
参数说明数据类型
out_bmp

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

(默认值为 False)

Boolean
bmp_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

(默认值为 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.

  • NONECompression is not applied.
  • RLERun-length encoded compression.

(默认值为 NONE)

String
embed_color_profile

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

(默认值为 True)

Boolean

BMP 文件属于本地 Windows 栅格图像。 BMP 文件可以使用多个位深度存储像素数据。 BMP 图像的大小通常比 JPEG 或 PNG 等其他格式的图像大很多。

exportToEMF (out_emf, width, height, {resolution}, {image_quality}, {output_as_image}, {convert_markers})
参数说明数据类型
out_emf

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

  • 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
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
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, width, height, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {convert_markers})
参数说明数据类型
out_eps

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

  • DEFLATEA lossless data compression.
  • LZWLempel-Ziv-Welch, a lossless data compression.
  • NONECompression is not applied.
  • RLERun-length encoded compression.

(默认值为 DEFLATE)

String
image_quality

A string that specifies output image quality, 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
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
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, width, height, {resolution}, {world_file}, {gif_color_mode})
参数说明数据类型
out_gif

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

(默认值为 False)

Boolean
gif_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

(默认值为 8-BIT_ADAPTIVE_PALETTE)

String

GIF 文件属于 Web 中使用的旧的栅格格式。 GIF 文件无法显示 256 种以上的颜色(每像素 8 位),并且使用的是可选的无损压缩,因此,该类文件的大小比其他格式的文件要小。

exportToJPEG (out_jpg, width, height, {resolution}, {world_file}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile})
参数说明数据类型
out_jpg

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

Integer
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
embed_color_profile

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

(默认值为 True)

Boolean

JPEG 文件属于经过压缩的图像文件。 它支持 24 位颜色并且是 Web 上流行的使用格式,因为 JPEG 文件大小通常要比许多其他图像格式小很多。 但是,JPEG 压缩算法会有损质量,多数地图图像中都不推荐使用,因为线绘图以及文本或图标图形会因压缩产生的伪影而变得模糊。 因此,通常 PNG 格式才是地图图像的首选。 在生成 JPEG 文件的同时,还将生成一个坐标文件,可用作地理配准栅格数据。

exportToPDF (out_pdf, width, height, {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})
参数说明数据类型
out_pdf

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

Integer
resolution

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

(默认值为 300)

Integer
image_quality

A string that defines the 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 the 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.
  • JPEG2000Offers higher quality compression with smaller file size than JPEG. This compression is lossless if jpeg_compression_quality is set to 100.
  • 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 the 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.
  • NONENone.

(默认值为 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 the 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
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
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, width, height, {resolution}, {world_file}, {color_mode}, {embed_color_profile})
参数说明数据类型
out_png

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

Integer
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

(默认值为 32-BIT_WITH_ALPHA)

String
embed_color_profile

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

(默认值为 True)

Boolean

PNG 格式属于通用型栅格格式,可在各种 Web 浏览器上显示并且还可插入其他文档。 它支持高位深度颜色并使用无损压缩。 对于地图而言,PNG 通常是最佳的栅格格式,因为无损压缩可防止产生 JPEG 格式中的那种压缩伪影,从而使文本和线作业始终清晰可辨。 PNG 文件还可定义透明颜色。 在生成 PNG 文件的同时,还将生成一个坐标文件,可用作地理配准栅格数据。

exportToSVG (out_svg, width, height, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {convert_markers})
参数说明数据类型
out_svg

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

  • 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
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
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, width, height, {resolution}, {world_file}, {color_mode})
参数说明数据类型
out_tga

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

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

(默认值为 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

(默认值为 32-BIT_WITH_ALPHA)

String

TGA 文件以往用于其他应用程序中的内容(例如,动画游戏的 Image Sprites),许多受欢迎的图形艺术应用程序均可对该文件进行读取和写入。 TGA 格式支持多位深度,包括支持 alpha(透明)的 32 位。

exportToTIFF (out_tif, width, height, {resolution}, {world_file}, {color_mode}, {tiff_compression}, {geoTIFF_tags}, {jpeg_compression_quality}, {embed_color_profile})
参数说明数据类型
out_tif

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

String
width

A number that defines the width of the export in pixels.

Integer
height

A number that defines the height of the export in pixels.

Integer
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. The available options are dependent on the specified Color Model set in the layout's Color Management properties.

  • 8-BIT_ADAPTIVE_PALETTE8-bit adaptive palette. Available to RGB and CMYK.
  • 8-BIT_GRAYSCALE8-bit grayscale. Available to RGB and CMYK.
  • 24-BIT_TRUE_COLOR24-bit true color. Available only to RGB.
  • 32-BIT_WITH_ALPHA32-bit with alpha. Available only to RGB.
  • 32-BIT_CMYK_TRUE_COLOR32-bit CMYK true color. Available only to CMYK.
  • 40-BIT_CMYK_WITH_ALPHA40-bit CMYK with alpha. Available only to CMYK.

(默认值为 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 the GeoTIFF format.

(默认值为 False)

Boolean
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
embed_color_profile

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

(默认值为 True)

Boolean

TIFF 文件最适合导入图像编辑应用程序,同时它也属于一种常用的 GIS 栅格数据格式。 但是却无法通过 Web 浏览器在本地查看这些文件。 TIFF 文件还支持在 GeoTIFF 标签中或在单独坐标文件中存储地理配准信息,以便用作栅格数据。

getLayerExtent (layer, {selection_only}, {symbolized_extent})
参数说明数据类型
layer

引用 Layer 对象。

Layer
selection_only

如果为 True,将返回选定要素的范围;如果为 False,将返回所有要素的范围。

(默认值为 True)

Boolean
symbolized_extent

如果值为 True,将返回图层的符号化范围;否则将返回几何范围。符号化范围会将符号覆盖的区域考虑在内,因此该区域不会被数据框边界切掉。

(默认值为 True)

Boolean
返回值
数据类型说明
Extent

地理处理 Extent 对象。

getLayerExtent 方法将支持图层定义查询,因此如果查询了要素子集,则将只返回这些要素的范围。如果未选择要素,则将返回图层的范围。

panToExtent (extent)
参数说明数据类型
extent

地理处理 Extent 对象。

Extent

此方法尤为适合比例未变而位置发生了变化的情况。无需设置范围以及每次都重置比例,panToExtent 保持比例不变,然后使照相机在新范围中居中。

zoomToAllLayers ({selection_only}, {symbolized_extent})
参数说明数据类型
selection_only

如果为 True,将根据选定要素设置范围;如果为 False,将为地图中的所有要素设置范围。

(默认值为 True)

Boolean
symbolized_extent

如果值为 True,将返回图层的符号化范围;否则将返回几何范围。符号化范围会将符号覆盖的区域考虑在内,因此该区域不会被地图框边界切掉。

(默认值为 True)

Boolean

如果对含有全局或本地场景的 MapView 使用了 zoomToAllLayers,则将生成平面视图。

zoomToBookmark (bookmark)
参数说明数据类型
bookmark

引用 Bookmark 对象。

Bookmark

如果对引用了 2D 地图MapView 使用了 3D 书签(反之亦然),则将生成平面试图。

代码示例

活动地图视图示例

在本示例中,将 MapView 范围导出到 PNG 文件之前,将针对当前活动地图视图对其进行修改。 可以使用 current 关键词来引用 ArcGIS Pro 工程。 此脚本将在 Python 窗格或脚本工具中运行。

import arcpy, os

aprx = arcpy.mp.ArcGISProject('current')
mv = aprx.activeView

# Change the extent of the map view
ext = mv.camera.getExtent()
ext.XMin = ext.XMin + 100
ext.YMin = ext.YMin + 100
ext.XMax = ext.XMax - 100
ext.YMax = ext.YMax - 100
mv.camera.setExtent(ext)

# Export the map view
Output_File = os.path.join(arcpy.env.scratchFolder, 'ActiveMapView.png')
mv.exportToPNG(Output_File, width=1000, height=1000, world_file=True, color_mode="32-BIT_WITH_ALPHA")
MapView 网络地图打印示例

在本示例中,脚本在 Web 地图 JSON 中读取。 ConvertWebMapToArcGISProject 中的输出 MapView 将导出为 PNG 文件。

import arcpy
import os
import uuid

# Input web map json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# Convert the web map to an ArcGIS Project
result = arcpy.mp.ConvertWebMapToArcGISProject(Web_Map_as_JSON)
aprx = result.ArcGISProject

# Get the map view
m = aprx.listMaps()[0]
mv = m.defaultView

# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.png'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)

# Export the web map
mv.exportToPNG(Output_File, result.outputSizeWidth, result.outputSizeHeight, result.DPI)

# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(1, Output_File)

# Clean up
del mv, m, aprx, result
CreateMap 和打开地图视图示例

下面的脚本使用了关键字 current,因此可从 Python 窗口运行此脚本。 该脚本用于新建地图并向其添加新图层。 将更新地图的默认照相机属性,该属性用于控制新打开的视图的范围。 然后将地图视图导出为 PDF。 新建的地图随即从工程中移除。

aprx = arcpy.mp.ArcGISProject("CURRENT")

#Create a copy of an existing map
newMap = aprx.createMap("Ranger Stations", "Map")

#Add ranger stations layer file
lyrx1 = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\LayerFiles\Park Boundary.lyrx")
newMap.addLayer(lyrx1)
lyrx2 = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\LayerFiles\Ranger Stations.lyrx")
newMap.addLayer(lyrx2)

#Close any current map or layout views
aprx.closeViews("MAPS_AND_LAYOUTS")

#Set the default map camera to the extent of the park boundary before opening the new view
#default camera only affects newly opened views
lyr = newMap.listLayers("*Park Boundary")[-1]
newMap.defaultCamera.setExtent(arcpy.Describe(lyr).extent)
newMap.openView()

#export the newly opened active view to PDF, then delete the new map
mv = aprx.activeView
mv.exportToPDF(r"C:\Temp\RangerStations.pdf", width=700, height=500, resolution=96)
aprx.deleteItem(newMap)