I'm trying to create a route using Network Analyst. Just at the beginning stages of setting this up for a school project.
I have a feature class called RoadsClipped, and successfully set up a Network Dataset called Roads_ND using it.
Now I'm trying to customize the routing cost using evaluators. I want to use attributes in RoadsClipped, but anything I've tried to access those attributes results in a "Network element evaluator error". I've tried both VBScript and Python.
Some simple examples are below. I've tried literally hundreds of variations and nothing work unless I forego trying to look at the attribute entirely. These are just simple tests to see if I can get at the attributes in RoadsClipped, and not the real logic I'll eventually use.
Python:
def SetCost(value):
a=Edge.AttributeValueByName(value)
c=0
if l!=0:
c=100/a
return c
value=SetCost("SPEED_LIM")
VBScript:
a=0
a=Edge.AttributeValueByName("SPEED_LIM")
value = a
Any suggestions?
Did you remember to switch the language picker to python instead of VBScript?
Yes it is set to Python and "Verify" is successful.
Oops, sorry, just realized I told you wrong earlier. Don't use "is not null". Use "is not None". Sorry, my brain got python and Javascript garbled together.
Thanks!!! That works! (Note: It looks like the total cost variable can get to be too big, but I can scale it so it stays in range.)
Are you able to share your data? If so, please zip up your entire gdb and post it somewhere I can download, and I can take a look.
Otherwise, honestly at this point you might really need to contact Support, if you're able. This question is getting pretty complicated, and they would be better equipped to walk you through the process.
Thanks. I'll see if I can select out a small portion of the data and zip it up. I cannot get support through my student license.
Note: If I change the script to this:
def SetCost(lim):
cost=10000
if lim is not null:
cost=lim*lim
return cost
I only get an error on one object - the one that has a null for the speed limit. So my workaround is probably to select only the objects that have all the values I need, and ignore road segments that don't. I thought that was the correct syntax for checking for null but I'll try to confirm that.
Dear Brad,
try if lim is not None