0

In this example, previously posted as Calculating sequential numbers into sorted table using ArcGIS Desktop? :

How do you construct a Python code that would give the Seq field sequencing such as:

1963.......1
1963.......1
1965.......2
1966.......3
1967.......4
1967.......4
1967.......4
1968.......5

Etc.... ???

enter image description here

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Charles
  • 11
  • 1
  • 1
    Welcome to GIS SE. As a new user, please take the [Tour]. Coding questions here are expected to contain code. You reference "previously posted" without a link. Please [Edit] the question. – Vince Jun 01 '18 at 11:53
  • @Charles, hey do you want the Seq field to be unique or you want it to be based on the Year field (that is all 1963 years will have 1 in the Seq and all 1965 will have 2 in the Seq)? In the question body you duplicate values, but in the screenshot you don't, I am puzzled. – Alex Tereshenkov Jun 01 '18 at 12:06
  • I would like it to be based on the year field but same year should have the same seq value. – Charles Jun 01 '18 at 12:08
  • This references: https://gis.stackexchange.com/questions/193681/calculating-sequential-numbers-into-sorted-table-using-arcgis-desktop – Charles Jun 01 '18 at 12:10
  • You could create a csv file with two columns (Years and corresponding Seq codes - a couple of minutes in a spreadsheet). Read the csv file into a python dictionary with Years as keys and Seq code as values. With the update cursor you can write the right Seq value for the corresponding Year into your feature table. – ZrSiO4 Jun 01 '18 at 16:28

1 Answers1

1

You should be able to get the attribute values for a given feature, and then do the following field calculator operation for all features:

Seq = Year - (year zero)

So for your example it would be Seq = Year - 1962

These two pages for ArcGIS for Desktop and ArcGIS Pro have further details on how to do this and other field calculator operations, including some example python scripts.

http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/calculate-field-examples.htm http://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field-examples.htm

ycartwhelen
  • 2,392
  • 10
  • 20
  • Can you give a few more details on where you're getting stuck? This page has a lot more specific syntax details on arcpy.CalculateField_management() http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/calculate-field.htm – ycartwhelen Jun 01 '18 at 13:31
  • How do you construct a code to accomplish the pattern above, where for the same year value, Seq value is the same but for the next year it updates bu an increment of 1, etc? – Charles Jun 01 '18 at 13:55
  • That's the whole idea behind subtracting the year zero value. In your example: 1963 - 1962 = 1, 1964 - 1962 = 2, 1965-1962 = 3, etc. Although now I take a second look your example doesn't do this exactly (differently in the text and the picture). Are you intentionally skipping 1964=2, or is that a typo? – ycartwhelen Jun 01 '18 at 18:12
  • No; and would the sequence be the same for each occurrence of say 1967, etc.? – Charles Jun 01 '18 at 18:30
  • The OP is confusing because the two images are inconsistent: in the first example Seq increments by one only when Year changes, but in the second example Seq increments for each record. – Stu Smith Jun 03 '18 at 17:16