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 (只读) |
报表部分中的字段,包括字段名称、排序顺序和分组。 其中不包含相关报表。 字典的键定义如下:
可用的排序选项定义如下:
|
Dictionary |
|
name (读取和写入) |
报表部分名称。 有必要确保工程中的所有报表部分都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。 |
String |
|
referenceDataSource (只读) |
将报表部分的参考数据源连接信息返回为 Python 字典。 字典的键定义如下:
|
Dictionary |
|
statistics (只读) |
报表部分中的统计数据,包括字段名称和统计类型。 其中不包含相关报表。 字典的键定义如下:
报表的可用统计数据定义如下:
|
Dictionary |
|
type (只读) |
|
String |
|
visible (读取和写入) |
报表部分可见性。 将此项设置为 |
Boolean |
方法
setReferenceDataSource(data_source)
设置报表部分的参考数据源。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
data_source |
The data reference for the report section. This parameter can be a (默认值为 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 (默认值为 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 |
以下脚本使用地图内关联设置新相关报表源:
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)
代码示例
以下脚本用于访问报表中的所有报表部分:
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
以下脚本用于将报表部分可见性设置为 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
以下脚本用于将报表中第二个报表部分的参考数据源设置为地图中的表:
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)
以下脚本用于修改报表中第三个报表部分的定义查询:
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'"
以下脚本获取报表部分的字段和统计数据:
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'}]