Report

概要

The Report object references a report in an ArcGIS Pro project (.aprx) file. It provides access to common properties such as definition query and export.

ディスカッション

An ArcGIS Pro project can contain multiple reports. Reports are accessed using the listReports method on the ArcGISProject object, and it returns a Python list of Report objects. It is important to uniquely name each report so that a specific report can be easily referenced by its name.

A Report has a data source that provides the data to power the report generation. You can identify the current data source for the report using the referenceDataSource property. To change the report's data source, you can use the setReferenceDataSource method. The method maps the fields from the new data source to the fields of the report that were defined by the original data source. The field names, not the field aliases, must be an exact, case-sensitive match.

In addition to the report's data source having a definition query, the report can also have a definition query. Records are first filtered based on the data source's definition query, and the records can be further filtered using the report's definitionQuery property.

Use the exportToPDF method to export the report to a PDF document.

プロパティ

 プロパティ 説明 データ タイプ definitionQuery(読み書き) The reports's definition query. This is applied in addition to the report's reference data source definition query. String metadata(読み書き) Get or set the report's Metadata class information. Note, setting metadata is dependent on the isReadOnly property value. Metadata name(読み書き) The report's name. It is important that all reports in a project have a unique name so they can be easily referenced by name. String referenceDataSource(読み取り専用) Returns the report's reference data source connection information as a Python dictionary. Dictionary

手法の概要

 手法 説明 exportToPDF (out_pdf, {page_range_type}, {page_range}, {starting_page_number}, {total_page_number}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {jpeg_compression_quality}) Exports a report to a Portable Document Format (PDF) file. setReferenceDataSource (data_source) Sets a report's reference data source.

手法

exportToPDF (out_pdf, {page_range_type}, {page_range}, {starting_page_number}, {total_page_number}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {jpeg_compression_quality})
 パラメーター 説明 データ タイプ out_pdf A string that represents the path and file name of the output export file. String page_range_type A string that defines the type of page range to export. The default is ALL.ALL —Export all pages of the report.LAST —Export the last page of the report.EVEN —Export the even numbered pages of the report.ODD —Export the odd numbered pages of the report.RANGE —Export the pages listed in the page_range parameter . (デフォルト値は次のとおりです ALL) String page_range A string that identifies the pages to be exported if the RANGE option in the page_range_type parameter is used (for example, 1, 3, 5-12). If any other page_range_type value is used, the page_range value will be ignored. String starting_page_number Applies an offset to the page numbering to add additional pages to the beginning of the report. The default offset is 1.(デフォルト値は次のとおりです 1) Integer total_page_number The total number of pages to label, for example, when your report displays X of Y pages. This is useful when you want to combine multiple reports into one. The default is -1, which means there is no override.(デフォルト値は次のとおりです None) Integer resolution An integer that defines the resolution of the export file in dots per inch (dpi).(デフォルト値は次のとおりです 96) Integer image_quality A string that defines output image quality.BEST —An output image quality resample ratio of 1BETTER —An output image quality resample ratio of 2NORMAL —An output image quality resample ratio of 3FASTER —An output image quality resample ratio of 4FASTEST —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 defines 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.JPEG —A lossy data compression.DEFLATE —A lossless data compressionLZW —Lempel-Ziv-Welch, a lossless data compressionNONE —Compression is not appliedRLE —Run-length encoded compression(デフォルト値は次のとおりです ADAPTIVE) String embed_fonts A Boolean that controls the embedding of fonts in an 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 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 70 through 90.(デフォルト値は次のとおりです 80) Integer

PDF files are designed to be consistently viewable and printable across platforms. They are commonly used for distributing documents on the web and are a standard interchange format for content delivery. PDF files are editable in many graphics applications and retain annotation, labeling, and attribute data for map layers. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.

setReferenceDataSource (data_source)
 パラメーター 説明 データ タイプ data_source The data reference that powers the 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

The setReferenceDataSource method sets the data source that the report references using a Layer object, a Table object, or a string that represents the path to an external data source

コードのサンプル

Report example 1

The following script selects the Counties Report by name and exports it to PDF.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\USA_States\USA_States.aprx")
report = aprx.listReports("Counties Report")[0]
report.exportToPDF(r"C:\Project\USA_States\CA_Counties_Report.pdf")
Report example 2

The following script repairs the report's broken data source and saves the project.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\USA_States\USA_States.aprx")
report = aprx.listReports("Counties Report")[0] # has a broken data source
report.setReferenceDataSource(r"C:\Project\USA_States\usa.gdb\states")
print(report.referenceDataSource)
#{'dataset':'states', 'workspace_factory':'File Geodatabase',
# 'connection_info':{'database':'C:\\Project\\USA_States\\usa.gdb'}}
aprx.save()
Report example 3

The following script uses the PDFDocument class to merge multiple reports into one multipage PDF.

import arcpy
pdf_name = "StatesReport.pdf"
cover_page = r"C:\path\to\StatesCoverPage.pdf"
part_one_pdf = r"C:\path\to\part_one.pdf"
part_two_pdf = r"C:\path\to\part_two.pdf"
final_pdf_path = r"C:\path\to\StatesReport.pdf"
report1 = self.aprx.listReports("States Report")[0] # Attribute List template
report2 = self.aprx.listReports("States Report Summaries")[0] # Summaries only using Basic Summary template
report1.exportToPDF(part_one_pdf, starting_page_number=2, total_page_number=13, page_range_type="RANGE",
page_range="1-2")
report2.exportToPDF(part_two_pdf, starting_page_number=3, total_page_number=13, page_range_type="RANGE",
page_range="2-11")

pdfMerge = arcpy.mp.PDFDocumentCreate(final_pdf_path) # Creates an empty PDF
pdfMerge.appendPages(cover_page)
pdfMerge.appendPages(part_one_pdf)
pdfMerge.appendPages(part_two_pdf)
pdfMerge.saveAndClose()