Select to view content in your preferred language

calculation within an IF statement in arcGIS Pro

2281
12
08-10-2018 08:24 AM
MáireDolan
New Contributor III

I'll begin by stating I am very new to the python world! 

My problem is this....

I am trying to use field calculator in ArcGIS Pro to return a calculation of values in other fields based on an if statement, if that makes sense! Not sure if it can be done?

The Calculation is 

Qrp=Sum(Qs*Ls)/SumLs

Basically thus;

weightAADT(!rp!,!Qs!,!Ls!)

Code Block

def weightAADT(rp, Qs, Ls):
       if rp=="Urban Two Lane":
            return sum(Qs * Ls) / sum(Ls)

my error is "TypeError: 'float' object is not iterable"

Any help appreciated

0 Kudos
12 Replies
MáireDolan
New Contributor III

Fair enough Dan,  I'll try and explain...

I have a database with 525 entries, which I will call 'sites'. Each site has a 'RP' field with 1 of 4 possible attributes, i.e. Urban Two Lane, Rural Two Lane etc.

I need to carry out a calculation, based on the RP attribute, that returns the sum of [Length of site (Ls) * Traffic Flow @ site (Qs)] divided by sum Ls.

So a calculation needs to be applied to each site belonging to a defined RP, before summing up for that RP, if that makes sense.

Below is a very simplified version of fields and attributes contained in said database

 

Site_IDLsQsRP
R1251.254445Urban Two Lane
R1480.988956Rural Two Lane
R5241.352350Urban Two Lane
R3850.8810253Urban Dual Carriageway
R4491.0115236Rural Dual Carriageway
R6211.11052Urban Two Lane

To be fair Dan I have used the summarise feature followed by a join to get the required result, my query was if there was a better way of doing it in Pro with field calculator alone.

0 Kudos
DanPatterson_Retired
MVP Emeritus

better way... no... only way... yes …. well, except for doing it in numpy from the start and producing the summary result table directly, but that would be a parallel solution

MáireDolan
New Contributor III

Thanks Dan

0 Kudos