Skip to main content

setReferenceDataSource

汇总

ReportSection 对象引用 报表 中的报表部分。 它可提供对常见属性(例如定义查询)的访问权限以及设置参考数据源的方法。

讨论

ArcGIS Pro 报表可以包含多个报表部分。 可使用 Report 对象上的 listSections 方法访问报表部分。 这将返回 ReportSection 和 ReportLayoutSection 对象的 Python 列表。 可通过唯一 name 引用每个报表部分,并且每个部分都具有 REPORT_SECTION type 。

ReportSection 具有可使用 referenceDataSource 属性识别的数据源。 要更改数据源,使用 setReferenceDataSource 方法。 该方法可将新数据源中的字段映射到原始数据源定义的报表字段。 字段名称(非字段别名)必须为区分大小写的精确匹配。

可以使用 fields 和 statistics 属性访问报表部分的字段列表和统计数据。 这些属性适用于主报表部分,不包括相关报表。

报表部分中的相关报表也具有源。 要更改源,使用 setRelatedReportSource 方法。 与更改主要数据源一样,字段将映射到由原始源定义的报表。

要过滤导出为 PDF 的记录,修改报表部分的 definitionQuery 属性。 要从导出的 PDF 中排除报表部分,将 visible 属性设置为 false 。

语法

setReferenceDataSource()

属性

名称 说明 数据类型

definitionQuery

(读取和写入)

报表部分定义查询。 使用此项可过滤导出至 PDF 的记录。

String

fields

(只读)

报表部分中的字段,包括字段名称、排序顺序和分组。 其中不包含相关报表。 字典的键定义如下:

  • fieldName—报表的字段名称。

  • sortOrder—报表字段的排序。

  • groupField—True :该字段是否应用作一个组。

可用的排序选项定义如下:

  • ASC—按升序对字段进行排序。

  • DESC—按降序对字段进行排序。

  • NONE—不会对字段进行排序,使用数据库顺序。

Dictionary

name

(读取和写入)

报表部分名称。 有必要确保工程中的所有报表部分都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。

String

referenceDataSource

(只读)

将报表部分的参考数据源连接信息返回为 Python 字典。 字典的键定义如下:

  • dataset—数据集名称。

  • workspace_factory—工作空间工厂类型。

  • connection_info—用于表示工作空间路径的字符串

Dictionary

statistics

(只读)

报表部分中的统计数据,包括字段名称和统计类型。 其中不包含相关报表。 字典的键定义如下:

  • fieldName—统计的字段名称

  • statistic—报表的统计类型。

报表的可用统计数据定义如下:

  • COUNT—将标识组或报表的行数。

  • MEAN—将计算组或报表的数值字段的平均值。

  • MEDIAN—将计算组或报表的数值字段的中值。

  • SUM—将计算组或报表的数值字段的总和。

  • STD_DEV—将计算组或报表的数值字段的标准差

  • MAX—将标识组或报表的字段的最大值。

  • MIN—将标识组或报表的字段的最小值。

Dictionary

type

(只读)

Report 对象上的 listSections 方法将返回 ReportSection 和 ReportLayoutSection 对象。 报表部分具有 REPORT_SECTION 类型。

String

visible

(读取和写入)

报表部分可见性。 将此项设置为 False 可在导出为 PDF 为排除部分。

Boolean

方法

setReferenceDataSource(data_source)

设置报表部分的参考数据源。

名称 说明 数据类型

data_source

The data reference for the report section. This parameter can be a Layer object, a Table object, or a string that represents the path to an external data source.

(默认值为 None)

Object

setRelatedReportSource(related_report_data_source, related_report_section_name, relate_or_relationship_class_name)

设置相关报表的数据源。

名称 说明 数据类型

related_report_data_source

The data source for the new related report. This parameter can be a Layer object, a Table object, or a string that represents the path to an external data source.

(默认值为 None)

Object

related_report_section_name

The name of the related report.

(默认值为 None)

String

relate_or_relationship_class_name

The name of the new relate or relationship class.

(默认值为 None)

String

SetRelatedReportSource 示例 1

以下脚本使用地图内关联设置新相关报表源:

aprx = arcpy.mp.ArcGISProject('current')
report = aprx.listReports("States Report with Relate")[0]
reportSection = report.listSections()[0]
map = aprx.listMaps("States with Capitals")[0]
newRelatedLayer = map.listLayers("Capitals")[0]
relatedReportName = "cities: Related Report"
newRelateName = "states_capitals"
reportSection.setRelatedReportSource(newRelatedLayer, relatedReportName, newRelateName)

代码示例

ReportSection 示例 1

以下脚本用于访问报表中的所有报表部分:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
sections = [s.name for s in report.listSections() if s.type=="REPORT_SECTION"] # Get list of report section names
for s in sections:
    print(s)
# National Parks Overview
# Park Highlights
# Annual Review
ReportSection 示例 2

以下脚本用于将报表部分可见性设置为 False :

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
section = report.listSections("National Parks Overview")[0] # Find the report section by name
section.visible = False
ReportSection 示例 3

以下脚本用于将报表中第二个报表部分的参考数据源设置为地图中的表:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
map = aprx.listMaps("National Parks")[0]  # Find a map in the project
table = map.listTables()[0] # Find the first table in the map
report = aprx.listReports("National Parks Report")[0]
section = report.listSections()[1] # Find the report section by index
section.setReferenceDataSource(table)
ReportSection 示例 4

以下脚本用于修改报表中第三个报表部分的定义查询:

aprx = arcpy.mp.ArcGISProject(r"C:\DemoData\NationalParks.aprx")
report = aprx.listReports("National Parks Report")[0]
section = report.listSections("Annual Review")[0] # Find the report section by name
section.definitionQuery = "ParkName = 'Yosemite'"
ReportSection 示例 5

以下脚本获取报表部分的字段和统计数据:

aprx = arcpy.mp.ArcGISProject(r'C:\temp\Parcels.aprx') # Find the project
report = aprx.listReports()[1] # Find the second report by index
report_section = report.listSections()[0] # Find the first report section

print(report_section.fields) # Get fields
# [{'fieldName': 'ASR_LANDUSE', 'sortInfo': 'ASC', 'groupField': True}, {'fieldName': 'APN_8', 'sortInfo': 'NONE', 'groupField': False}, {'fieldName': 'ACREAGE', 'sortInfo': 'NONE', 'groupField': False}]

print(report_section.statistics) # Get statistics
# [{'fieldName': 'APN_8', 'statistic': 'COUNT'}, {'fieldName': 'ACREAGE', 'statistic': 'MEAN'}]