Select to view content in your preferred language

efficient code for field calculation

865
10
04-01-2024 04:29 AM
Labels (2)
RavenSchmidt
Emerging Contributor

Hi, I would like to calculate a single layer in one field from the value of another field. The problem lies within the size of the dataset. My Computer is very fast, but the calculation seems to slow down considerably over time until it barely moves anymore. I stopped it after three days.
Here are two versions of the codeblock I have tried so far.
Does anybody have suggestions how to calculate the field more efficiently?
Curiouse side note: I used this code several times already and sometimes it just seems to be significantly faster as on other times with no major changes in background load on the system...
Also this seems to apply both to running the code in PyCharm and ArcGIS Pro Field Calculator

A

expression = "hierarchy_creator_feet(!highway!)"
codeblock = """def hierarchy_creator_feet(p_highway):
if p_highway in ('footway', 'pedestrian', 'residential', 'living_street', 'crossing', 'track', 'path'):
return 3
elif p_highway in ('tertiary', 'tertiary_link', 'unclassified', 'steps', 'service'):
return 23
elif p_highway in ('secondary', 'secondary_link', 'primary', 'road'):
return 33
elif '[' in p_highway: return 32
else:
return 0"""


B

highway_hierarchy = {
'footway': 3,
'pedestrian': 3,
'residential': 3,
'living_street': 3,
'crossing': 3,
'track': 3,
'path': 3,
'tertiary': 23,
'tertiary_link': 23,
'unclassified': 23,
'steps': 23,
'service': 23,
'secondary': 33,
'secondary_link': 33,
'primary': 33,
'road': 33
}

expression = "hierarchy_creator_feet(!highway!)"
codeblock = """def hierarchy_creator_feet(p_highway):
return highway_hierarchy.get(p_highway, 0)"""
0 Kudos
10 Replies
RavenSchmidt
Emerging Contributor

It's just lying around on my C: drive, not hosted, shared or connected anywhere. I assume that I could just delete the Network Dataset, calculate the field in memory, rewrite the FC to disc and create the NDS again, but if it's possible to avoid having to create the NDS I would prefer so

0 Kudos