0

I am using ArcGIS Pro 2.3. I have a point layer, for which I need to calculate a unique increasing number. I am trying to calculate a field "BlockUnique" with a sequential number sequence (1, 2, 3, and so on). I have another field "BlockID". I need the BlockUnique field to calculate the increasing number sequence and restart for every unique BlockID. An example below.

Is this able to be done without Python?

If python is required, how would I script this?

I am not even sure where to begin!

Example: BlockID on left, BlockUnique on right.

A 1
A 2
A 3
B 1
B 2
C 1
D 1
D 2
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Jessica
  • 96
  • 6

2 Answers2

1

If we frame it another way, you basically want BlockUnique to be the number of occurrences of BlockID seen up to the current row.

Code block:

from collections import defaultdict

lookup = defaultdict(int)

def get_id(value): lookup[value] += 1 return lookup[value]

Expression:

get_id(!BlockID!)
mikewatt
  • 5,083
  • 9
  • 21
  • I love defaultdict but I really dislike global. Fortunately in this case global isn't needed because Python dictionaries are mutable so they are passed by reference, which makes the global/local namespace issue moot when updating contents of the variable. – bixb0012 Apr 16 '22 at 16:04
  • Good call, edited. – mikewatt Apr 16 '22 at 23:42
0

This is a variation to mikewatt's answer and uses the same logic suggested by FelixIP's link.

Code block

lookup = {}
def get_id(value):
   lookup[value] = lookup.get(value, 0) + 1
   return lookup[value]

Expression

get_id(!BlockID!)
fatih_dur
  • 4,983
  • 2
  • 16
  • 35