-
Notifications
You must be signed in to change notification settings - Fork 0
Import Highway Project Coding
This page describes import_hwyproj_coding.py, which imports highway project coding and checks its validity. To use this tool, run
[path-to-tool].
This script is a translation of the Import Highway Projects tool in the mhn_programs repository.
Ensure your input directory has this structure:
input
|-- input_years.csv
`-- 1_travel
`-- MHN.gdb
|-- import_hwyproj_coding.xlsx
You need a csv file called input_years.csv to specify the scenario years and a copy of the MHN as MHN.gdb. (While the scenario years are not logically relevant here, it is required for the code to work.)
If you just want to check the validity of the project table, you do not need import_hwyproj_coding.xlsx. However, if you do want to import new project coding, you must have an excel file called import_hwyproj_coding.xlsx. There are 28 required columns in this excel file, and in the templates directory, there is a template file called import_hwyproj_coding_template.xlsx which you can just fill in.
The column "remove" indicates rows to be dropped from the project table. Set remove = Y if you want to remove that row.
There are 4 major steps in the script.
The feature classes (nodes, links, and projects) are checked for errors. If there are any errors with the feature classes, then the program will be crashed.
If there is new project coding to import, the project coding will be imported.
- Each row must have all four required fields filled in: TIPID, ANODE, BNODE, and ACTION CODE.
- ANODE-BNODE must correspond to a valid link in the highway network (so that ABB can be calculated).
- Each row must be uniquely identifiable by its TIPID-ABB combination.
If any of the rows fail, the program crashes. Offending rows will be written to a file called import_project_coding_errors.csv.
The imported rows are then divided into 3 groups.
- Group 1 - rows to delete, where the TIPID-ABB combination already exists in the project table and remove = Y. These rows are removed from the project coding table.
- Group 2 - rows to update, where the TIPID-ABB combination already exists in the project table. These rows are updated (overwritten) by the imported rows.
- Group 3 - rows to insert, where the TIPID-ABB combination does not already exist in the project table. The imported rows are inserted into the project table.
The project coding table is checked for errors. If there are any rows with errors, the script will keep running, but a field called "USE" will be flagged (by setting it to 0 as opposed to 1) that this row is invalid.
The project coding table drops all invalid rows (where USE = 0). The project feature class has its geometry recalculated with the rows of hwyproj_coding which were kept. If a project no longer has a single valid corresponding row in the project coding table, then it is written to a file called removed_projects.txt.
More cleanup is done (removing temporary fields + adding relationship classes).