AlexArcPy / registrant

Python package used for generating HTML reports about the contents of Esri geodatabases.
MIT License
71 stars 17 forks source link
arcgis arcgis-desktop arcgis-pro arcgis-python arcpy arcsde esri gdal geodatabase gis html-report ogr python reporting sde sql

Language grade: Python

General

This Python package is used for generating HTML reports about the contents of Esri geodatabases. It supports working with Esri personal/file geodatabases as well as RDBMS enterprise geodatabases (however, it also works with RDBMS databases that were not geodatabase enabled).

Example of report:

Sample report

Usage guidelines

In order to use this tool, you would need to have either:

The code written is a valid Python 2 as well as Python 3 code, so using the tool in both environments is supported. You will need pandas and beatifulSoup Python packages which can be installed from pip if you are ArcGIS Desktop/Server user or using conda if you are ArcGIS Pro or Anaconda user. See Installing Packages in the Python documentation (for ArcGIS Desktop users) and Install a package in the Conda documentation (for ArcGIS Pro and Anaconda users) to get help.

If the package is able to import arcpy, then it will use arcpy because it provides a more complete view into your geodatabase. The most time is spent in arcpy describe and listing functions iterating the datasets and pulling all the relevant information.

If arcpy is not found in your system, then the package will try to import ogr. The OpenFileGDB driver is used to access the key information about the geodatabase and its items. Please keep in mind that when using ogr, no information about tables/feature classes indexes and subtypes will be reported and many of the ArcGIS specific properties won't be shown either.

Output report

After HTML file is generated, you can open it in a web browser. The HTML file uses resources in other folders located in the app folder which means you cannot move the HTML file somewhere else without copying its dependency folders. If you would like to move the report somewhere else, you need to copy the whole app folder. While having the HTML file shown in a web browser, you can use the links to navigate throughout the page. Keep in mind that since navigation is built using the headers id, you can use the web browser's tools for navigating forward and back as you navigate between different sections of the report.

Requirements

Installation

python setup.py install

Please keep in mind that arcpy and GDAL won't be installed when installing the package. The arcpy package can be obtained by installing ArcGIS software and GDAL can be installed in many ways, for instance, using Anaconda Navigator or using a binary wheel.

Getting started

When creating a Reporter class, you'd need to supply path to your geodatabase and output folder for report data files. Then, calling Reporter.gdb2html() would let you optionally specify what information you would like to include into your output HTML report. Depending on the geodatabase size, number of chosen items to include in the report as well as the available system resources, it might take some minutes to run.

The package has convenience functions which can be used to specify what exactly do you want to generate report for. The gdb2html function will create a complete report. This function provides you with fine-grained control over what information will be included in the report, so you can use it providing booleans arguments (for instance, you may want to get only list of tables and feature classes without reporting their fields, subtypes, and indexes). However, you can specify if you want to report only domains, only tables, or only feature classes using the domains2html, tables2html, and fcs2html functions respectively.

To generate full geodatabase report:

import registrant
reporter = registrant.Reporter(
    r"C:\GIS\Production.gdb", r"C:\GIS\ReportFolder"
)
reporter.gdb2html()
print(reporter.report_file_path)

To generate report listing only tables and feature classes (with no information on fields, subtypes, and indexes):

import registrant
reporter = registrant.Reporter(
    r"C:\GIS\Production.gdb", r"C:\GIS\ReportFolder"
)
reporter.gdb2html(
    do_report_versions=False,
    do_report_replicas=False,
    do_report_domains=False,
    do_report_domains_coded_values=False,
    do_report_relclasses=False,
    do_report_tables=True,
    do_report_tables_fields=False,
    do_report_tables_subtypes=False,
    do_report_tables_indexes=False,
    do_report_fcs=True,
    do_report_fcs_fields=False,
    do_report_fcs_subtypes=False,
    do_report_fcs_indexes=False,
)
print(reporter.report_file_path)

To generate report listing only domains and coded values for domains:

import registrant
reporter = registrant.Reporter(
    r"C:\GIS\Production.gdb", r"C:\GIS\ReportFolder"
)
registrant.domains2html()

Architecture

This tool uses arcpy package (and if you don't have any ArcGIS software installed - ogr package) to read properties of geodatabase into Python dictionaries which are used then to construct pandas data frames. The data frames are exported into HTML tables (as large strings) using built-in pandas.DataFrame.to_html method. To merge all the HTML tables into a single page, beatifulSoup package is used. The HTML report page is built using the Bootstrap 3 Dashboard sample. Some extra functionality is added with the help of Bootstrap 3 DataTables extension. Additional navigation items in the table of contents are added to the HTML page on-the-fly while reading geodatabase tables and feature classes.

FAQ

Report contents

Added in v0.2:

Added in v0.3:

Added in v0.4:

Added in v0.5:

Added in v0.6:

Added in v0.7:

All fields in tables and feature classes have a property showing the order of the field (UI order) within the dataset as shown in the dataset properties window in ArcGIS Desktop or Pro that is the order in which the fields were added. This is the order in which fields appear when you open the Feature Class Properties or Table Properties window in ArcGIS Desktop or when you access the Fields window in ArcGIS Pro.

As a note, Unicode characters are supported in geodatabase table names, field aliases and so forth. The web page should be drawn using the utf-8 encoding. Should any characters appear strange, make sure you are viewing the report page in the proper encoding:

Report functionality

New functionality under consideration

Take each domain > list all tables/fcs that use this domain > list all fields that have this domain assigned > count rows using domain value group by code

Report design and contents

Running tests locally

  1. Cd to the tests folder and run coverage run -m unittest discover. This will create a .coverage file which contains the metadata about code coverage.

  2. Cd to the tests folder and run coverage html -d coverage_html. This will generate a nice .html report highlighting the covered code. Calls to arcpy are excluded in the report thanks to the .coveragerc file.

Keep in mind that you need to make sure that arcpy is not found when you run tests for OGR as this will make the tests fail. In Wing IDE, right-click OGR test files > File Properties menu > Testing tab > choose empty Custom for Python path for the Python environments used to run the OGR tests (Anaconda env). This will make sure ArcGIS paths won't be added to the sys.path.

You also need to make sure that the right initial diretory used when starting the tests. In Wing IDE, go to the launch configuration properties and under the Environment tab, choose Use default for the Initial Directory property. This is required to be able to find the sample geodatabase files.

Issues

Did you find a bug? Do you need report to include some other information? Please let me know by submitting an issue.

Licensing

MIT