2

I have a gas main feature that I was asked to add MEASUREDLENGTH field to. I currently have a model that uses Shape_Length to sum overall pipe, but was asked to alter the model to use the new MEASUREDLENGTH field if populated, else use the Shape_Length field to sum overall pipe.

Can this be done with the Calculate Tool?

  • can you change the schema of the table? If so I would add a column for lengthToUse or something, then calculate = MEASUREDLENGTH where MEASUREDLENGTH is not null, then = Shape_Length where lengthToUse is (still) null – maverickGIS Dec 20 '16 at 16:15
  • That'd work, but the model would have to do that for every project that it'd need to run on. I was looking for a check rather than creating another new column to fill in NULL values from the MEASUREDLENGTH column. – j.stanfield Dec 20 '16 at 18:04
  • Add Field and Calculate Field are tools that can be added to your model, is your concern the time it would take to add and populate a single field to work from? It could be done in a Python script as well, with a da.SearchCursor and some clever summing, but that solution would depend on how you use/report the sum of each main. I don't know of any if/else logic in modelbuilder – maverickGIS Dec 20 '16 at 18:37
2
  1. Select by attributes on MEASUREDLENGTH is not Null or maybe MEASUREDLENGHT>0 depending on your data
  2. Summarize MEASUREDLENGTH, for example with Summary Statistics
  3. Switch selection with Select Layer By Location using selection_type SWITCH_SELECTION
  4. Summarize Shape_Length
  5. Sum the two sums

Or you could do it with python:

import arcpy
input_fc=r'C:\Test.gdb\pipes'
fieldlist=['MEASUREDLENGHT','SHAPE@LENGTH']
sumlist=[]

with arcpy.da.SearchCursor(in_table=input_fc,field_names=fieldlist) as cursor:
    for row in cursor:
        if (row[0] is None or row[0]==0):
            sumlist.append(row[1])
        else:
            sumlist.append(row[0])
print sum(sumlist)
  • This would certainly work if the sum of all main is the only sum needed, I was thinking there may need to be subtotals by material, pressure, system... but then I suppose those could just be done via different table views. – maverickGIS Dec 20 '16 at 20:43
  • Yes but for now he is only asking for total sum. – BERA Dec 21 '16 at 10:32
  • I was only providing more context surrounding the different suggestions ;) – maverickGIS Dec 21 '16 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.