I have a feature class composed of Overhead and Underground Electric Conductor, along with a different feature class of main water lines. I am attempting to build a python script that I can use to add into a tool for a "One-Click Button" to calculate and display the TOTAL distance of all of the lines in and feature class. To start, I am looking for some direction on designing and writing the Python script that will do this and produce the results of the total distance of conductor, water line in feet and miles. Any help on what tools to use to give the results would be great.
There are many ways to do this, including:
- Dissolve (collapse lines into one feature)
- Summary Statistics (sum all length)
- da.SearchCursor (add lengths, feature by feature)
It will depend on exactly what form you want the output to take (feature class, table, just a number stored in a python variable, etc.).
I have a good idea on the SearchCursor and the Summary Statistics. Been able to get the sum total of all the lines and it automatically saves into a table. What I need to do is run this in IDLE and have the results from the field that shows the total, "Print" in the python Shell once the script is complete.
I must be missing something, because if you get all this information once, that seems to be it. Are upgrades done hourly? daily? weekly? The tools that Darren describes take very little time to use so why the one-click?
The way I have been doing it is export the data into an Excel file and then use the Sum tool in Excel and than manually convert it. I want to be able to have the ability to do this in Python. Right now, i am building it in IDLE and want the final result to show in the IDLE Shell. Not sure how I get the results that are populated in the Geodatabase table to "Print" to the shell.
Like Darren Wiens said, there are many ways. I'd use da.SearchCursor and for loop to iterate through each row in the conductor feature class and use an If/Else statement to determine if it the record is an OH or UG line. From there you can add the value in the Shape.Length field to keep a running sum of each. You could easily convert back and forth between feet and miles after that. For the water main feature class, the Summary Statistics tool would be good since you need total length only, not broken down into sub-categories.
You can hardcode the variables in and once the python script is 100% correct, create a script tool in ArcCatalog that references the python script for a "one-click-button".
All of these are really helpful. The only thing that I do not know how to do and not being answered is when the results are produced in the Geodatabase Table from the Summary Statistics tool into a specific field is how to tell the Python script to "print/report" the value in that field in the Python shell. I know it may not make sense why I am doing it that way, but for me it works. I want to use the Python scripts that I am designing to run outside of ArcGIS, so when the script is complete, the data/results display in the Python Shell window.