## Setup

Download the source code as a zipped file (or if you'd like you can clone the repository)

![](../media/ToolDownload.PNG)

Unzip the file to a folder of your choosing. This will extract a single folder named `s3ds-main`.

In ArcGIS Pro's 'catalog' view or pane, navigate to `Toolboxes` and right click `add Toolbox`. Navigate to and select the 'geol_contact_fitter.atbx' file in the folder you just unzipped. You can find more instructions on adding toolboxes from [ESRI's documentation](https://pro.arcgis.com/en/pro-app/latest/help/projects/connect-to-a-toolbox.htm)

![](../media/AddToolboxScreencap.PNG)

## Usage

This toolbox contains just two simple tools at present, 'build database' and 'validate database'. Future iterations may include other tools, but in general we would like to seperate tools that are used for just building/validating databases (which may be agnostic to the type of data) and tools designed for working with data in a particular standard.

### 1) Build database

This tool calls the s3ds 'builddatabase.py' function to build a database with the requested tables.

![](../media/BuildDatabase.png)

The arguments of the tool are as follows:

* **Path to database** -- The path to the geodatabase of geopackage file.
* **Tables** -- Please select the types of data you will include. The code will ensure all required tables are also included.
* **EPSG** --Please specify an EPSG code for the coordinate system you would like to use (e.g., '4326' for WGS84, '32615' for WGS84 UTM Zone 15N, and so on) 
* **Enforce relational integrity?** -- If true, this will make all `<tablename>_id` values auto-incrementing (so that a user doesn't need to populate them) and ensure that records can not be created in the database if they violate relational integrity. For example, you can not create a record that references a 'datasource' that doesn't exist or doesn't reference a datasource at all. 

### 2) Add tables to existing database

This tool assists with creating tables in an existing database, in the event new data types need to be added to a project after editing has begun.   
This tool calls the s3ds 'builddatabase.py' function, which defaults to adding content to existing tables. It is therefore identical to the 'Build database' tool, 
but the database is set as an 'input' in the script tool parameters as opposed to 'output' - ArcPro uses these parameters to control dialog boxes and detect
file conflicts / the need to overwrite data.

![](../media/AddToDatabase.png)

The arguments of the tool are as follows:

* **Path to database** -- The path to the geodatabase of geopackage file.
* **Tables** -- Please select the types of data you will include. The code will ensure all required tables are also included.
* **EPSG** --Please specify an EPSG code for the coordinate system you would like to use (e.g., '4326' for WGS84, '32615' for WGS84 UTM Zone 15N, and so on) 
* **Enforce relational integrity?** -- If true, this will make all `<tablename>_id` values auto-incrementing (so that a user doesn't need to populate them) and ensure that records can not be created in the database if they violate relational integrity. For example, you can not create a record that references a 'datasource' that doesn't exist or doesn't reference a datasource at all. 

### 3) Validate database

This will validate a supplied database and generate a text file error log, you must open that text file to evaluate for errors.

![](../media/ValidateDatabase.png)

* **Database path** - The path to the geodatabase of geopackage file.
* **Error log** - This is the path to a .txt file that will be created to log errors in. We will improve the file type/export options in the future - but for now this is simple.

After the tool completes running, view the details of the geoprocessing tool and click the output file to open and examine it for errors:

![](../media/ValidationToolboxDetails.png)


### 4) Apply / Refresh domains

In ArcPro domains enable drop-down selection from a controlled list to populate a field. This tool builds this controlled lists and assigns them to appropriate fields in the database. The lists are 
created from fields in the database, some of which (for example *datasource* records or *modelelements*) may need to be periodically refreshed as new values are added. This helps enforce relational integrity and streamlines data population. An equivalent tool isn't present for geopackages, because this behavior is embedded in the relationships of geopackages when editing in QGIS.

![](../media/AddDomains.png)

* **Database path** - The path to the geodatabase of geopackage file. This is where domains will be applied AND where values from domains will be determined from.

* **field to domain-ify** - This is the list of fields that will be domain-ified. This list of options is based on those fields that have values defined in other tables throughout the database.



### Potential future tools

### 4) Build database metadata

This would be a tool to populate FGDC metadata and USGS data dictionaries for a supplied database

