Network dataset - Costs: How to create a evaluator expression referencing a field of the feature class

997
3
Jump to solution
01-07-2023 03:44 AM
ConnieSu
New Contributor III

Hello! I have a network dataset and I want to create a evaluator expression in "Costs" referencing a field of the feature class. Can somebody help me, please?

These are my current costs of the ND.

ConnieSu_0-1673091289440.png

For the edges feature class "PNL2017_Rodovias_Completo", I would like to create a expression like this:

if(TYPENO=="7001"):
    return 0.069001*[Shape]
else:
    return 0.039429*[Shape]

 And for the junctions feature class "PNL2017_Suporte_Pontos_Rodo", I would like something like this:

if(TYPENO=="7001"):
    return 17.1361
else:
    return 35.18

Could you please help me? 

Thanks and regards!

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

You can do this with a field script evaluator.  Those evaluator dialogs are a little hard to use, though, so I can see why you need a hint!

First, for the evaluator you want to update, double click in the Value column until you see the box on the far right with the green X.

MelindaMorang_0-1673281373907.png

You'll get a pop-up box where you can create an expression for the field script evaluator.  You will want something like this:

MelindaMorang_1-1673282368913.png

Basically the Result box calls a custom-defined function called get_value() and passes the TYPENO and Shape field values to it.  The ! surrounding the field names is what's used for Python evaluators.  I'm using Python instead of VBScript because it's easier to code in (for me), and VBScript evaluators will be deprecated soon.

Here's the code for the codeblock:

def get_value(typeno, shape):
    if typeno == "7001":
        return 0.069001 * shape
    else:
        return 0.039429 * shape

 

Your expression for the junctions source will be very similar, but you won't need to pass the Shape field into the function.

View solution in original post

0 Kudos
3 Replies
MelindaMorang
Esri Regular Contributor

You can do this with a field script evaluator.  Those evaluator dialogs are a little hard to use, though, so I can see why you need a hint!

First, for the evaluator you want to update, double click in the Value column until you see the box on the far right with the green X.

MelindaMorang_0-1673281373907.png

You'll get a pop-up box where you can create an expression for the field script evaluator.  You will want something like this:

MelindaMorang_1-1673282368913.png

Basically the Result box calls a custom-defined function called get_value() and passes the TYPENO and Shape field values to it.  The ! surrounding the field names is what's used for Python evaluators.  I'm using Python instead of VBScript because it's easier to code in (for me), and VBScript evaluators will be deprecated soon.

Here's the code for the codeblock:

def get_value(typeno, shape):
    if typeno == "7001":
        return 0.069001 * shape
    else:
        return 0.039429 * shape

 

Your expression for the junctions source will be very similar, but you won't need to pass the Shape field into the function.

0 Kudos
ConnieSu
New Contributor III

Thanks for your reply Melinda! It worked!

I've read that VBScript processes faster than Python. Will Python be faster when VBScript is deprecated?

Thanks and regards!

0 Kudos
MelindaMorang
Esri Regular Contributor

For field script evaluators like these, all the processing is done when you call Build Network.  The values are stored in the network dataset and are just looked up at solve time, so there shouldn't be any performance difference between Python and VBScript evaluators.  If there is, that performance difference would be incurred at build time, not at solve time.

However, I believe the performance difference is mostly historical at this point.  There certainly was some difference back in the ArcMap days, but I think that is either gone or significantly less now, although I don't have specific data to back that up.

Note that element script evaluators are different from field script evaluators.  Their code is run at solve time, so the solve may be slower, depending on the efficiency of the code itself.  This does not apply to your situation.

0 Kudos