Select to view content in your preferred language

Field Calculate Sequential Numbers starting with specific 18 digit number

7471
29
Jump to solution
05-09-2016 07:41 AM
anayoung
Regular Contributor

Hello,

I am need to field calculate sequential numbers starting with 033900000100191511. So, the numbering would be 033900000100191511, 033900000100191512, 033900000100191513 etc...

Can anyone help me with a python script for this?

With much appreciation,

Ana

0 Kudos
29 Replies
DanPatterson_Retired
MVP Emeritus

Ana... for completeness, Joshua is using a generator... you might want to read up on them if you plan to use them in the field calculator a lot

https://wiki.python.org/moin/Generators

anayoung
Regular Contributor

Hi Dan,

I will work on this tomorrow again. Thank you all for your suggestions. I will get back to you.

Ana

0 Kudos
anayoung
Regular Contributor

Hi Abdullah,

I think you have a point in that I have about 1100 records that need these 18 digit numbers. So, the code would probably need to be alphanumeric after 033900000100191999. So the numbers would go something like - 0339000001001915AA, 0339000001001915AB, 0339000001001915AC, ..., 0339000001001915AZ, 0339000001001915BA...0339000001001915ZZ, 0339000001001916AA..etc. until all 1100 records have unique numbers. This set of 1100 isn't the only set I will need to do; I have 21 other sets.

Can the code be adjusted to calculate like this?

Thank you!

0 Kudos
DanPatterson_Retired
MVP Emeritus

Yes, just adjust the length of the string and starting value in either my example or Joshua's.

However, now you are introducing unique letter combinations that weren't in the original post.

Perhaps you can elaborate on the significance of the original coding system.

If it has to be maintained, can you explain why, and where the switch to letters is to begin.

If it doesn't have to be maintained, is there a coding system that you wish to employ.

Since you are working with a string encoding system, there are far more unique values that can be generated than I suspect you have data for.  Is your record set in the millions? tens of millions?

A background to your current system would be helpful.

anayoung
Regular Contributor

Hi Dan,

Yes, I apologize for not thinking it all the way through. I'm kind of new to this kind of thinking.

In my roads feature class there are over 800,000 segments of road polylines. Each of these segments has a road name and a unique road identifier; these roads are either one way or both ways. The case of a one way there is only one identifier e.g. 033900000100191511. If both ways then there are two identifiers - one for each way. The number is broken down as follows from left to right using 033900000100191511 as an example:

1) first three characters are the parish number "033" (East Baton Rouge Parish in Louisiana)

2) the 4th character is the prefix code "9" (this road has no prefix so it is 9)

3) the next 6 characters are a name code "000001" (this is for "UNNAMED" streets)

4) the next 3 are the roadway type "001" (this is a NULL value but it would normally tell you if it was a street, drive, blvd, etc)

5) the next 1 character is the suffix code "9" ( this road has no suffix so it is 9)

6) the next 1 character is feature type code "1" (this tells you that the road is traveling in the primary direction; it would be a 2 if in the secondary)

7) the last 3 characters represent the sequential occurrence of the feature type "511"

The thing I would need to keep in mind before simply calculating is that some of these segments are the same road; so, those will have the same 18 digit number.

The problem is that since the UNNAMED streets all have the same numbers until they reach the sequential occurrence number at the end (i.e. 033900000100191???) or 033900000100192??? the sequential occurrence numbers need to be unique. The switch to letters needs to begin after the last three numbers reach 999 but in a sequence as mentioned in my previous comment. After 999 it should start 5AA, 5AB -> 5AZ then start with 6AA -6ZZ then after the sequence reaches 9ZZ it should probably go to something like Z01. No duplicates should exist, obviously.

These numbers will remain in the data set until such time they are retired or we find out there's actually a name associated with them.

Does this clarify my problem?

0 Kudos
anayoung
Regular Contributor

To add to my last comment. the last three numbers just need to be unique so however that is derived it would be fine.

0 Kudos
DanPatterson_Retired
MVP Emeritus

beginning to see the pattern, but I just want to make sure that you will be starting at a known position and not from the beginning of the data set, so you will always need a start key, and then you just want to be able to extend up to ...999, then carry on using 5AA...5ZZ, 6AA...6ZZ....9AA..9ZZ which still limits your combinations but is more manageable.

0 Kudos
anayoung
Regular Contributor

Yes, each parish in the state will have a different starting number for the sequencing. Because the first three numbers in the 18 digit number defines the parish the road is in, I won't have to worry about duplicate numbers in that regard. I'm assuming the "start key" is the "pStart" in the code?

0 Kudos
DanPatterson_Retired
MVP Emeritus

getting waylaid for a while, but some useful code in case someone else is working on this.  It produces the 676 combinations of uppercase

UC = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

cr_vals = [c + r for c in UC for r in UC]

RandyBurton
MVP Alum

This will produce the codes, but it should be in a generator.

def base(decimal ,base) : 
    list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
    answer = "" 
    while decimal != 0 : 
        answer  += list[decimal % base] 
        decimal /= base
    return answer[::-1]

# prints 3379 codes - 5AA to 9ZZ
for j in range(5, 10) :
    for i in range(0,676) :
        x = base(int(i % 676),26)
        if len(x) == 0 :
            print str(j) +'AA'
        elif len(x) == 1 :
            print str(j) +'A' + str(x)
        else : print str(j) + str(x)