Select to view content in your preferred language

Simple scripting help

3517
8
Jump to solution
10-12-2014 06:23 PM
stuartcassin1
Deactivated User

to assist with symbology, I'm trying to populate a column with alternate 1 & 0 so I can filter and symbolise alternate records. I need a simple method to auto complete a table of approx 5000 records. Can anyone help?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Stuart,

  Timothy's code is the complete copy and paste code that you need to put in the field calculator.

The only difference is that your field would be:

[FID] Mod 2

Just Copy and Paste the above line in the Field Calculator window in ArcMap.

View solution in original post

8 Replies
DanPatterson_Retired
MVP Emeritus

python processor, use the FID field or any other sequential field

>>> from math import fmod

>>> for i in range(20):

...  if fmod(i,2) == 0:

...      print 0

...  else:

...          print 1

...        

0

1

0

1

0

1

.......etc

1

0

1

0

1

0

1

>>>

python parser, enable the code block this is the function to use and in the expression box you could use ones_zeros(!FID!) (ps... haven't tried the code block but the above python syntax is the key

from math import fmod

def ones_zeros(your_field):

  if fmod(your_field,2) == 0:  print 0

  else:  print 1

0 Kudos
stuartcassin1
Deactivated User

Thanks for the suggestion Dan,

Unfortunately that didn't work. I mistakenly forgot to mention I'm using ArcGIS Basic 9.3.1 on an enterprise licence and I'm pretty sure the PythonWin Application hasn't been installed. Is there a way I can do this via the field calculator or the command line window?

I'm afraid my scripting / coding skills are pretty much zero.

0 Kudos
TimothyHales
Esri Notable Contributor

You should be able to just use the Mod operator in the Field Calculator:

[ObjectID] Mod 2

stuartcassin1
Deactivated User

Thanks Timothy,

Any chance you could supply the full script for the Field calculator (9.3.1)? I have no idea what the Mod operator is.

Sorry - scripting dummy here.

0 Kudos
yiqi
by
Deactivated User

I think it is just "mod", i mean, you can input "i=5 mod 2" which will make i=1. So, "[ObjectID] Mod 2", as Hales mentioned above, is what you can use directly.

0 Kudos
stuartcassin1
Deactivated User

Just some additional info for this question:

I'm using ArcGIS 9.3.1 Basic

I only have access to the command line window or the field calculator. All other scripting options are unavailable

I have pretty much no skills in scripting so really am looking for the complete answer (cut & paste??)

The only sequential field in the attribute table is the FID column.

Hopefully someone can help me with an appropriate code. Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Stuart,

  Timothy's code is the complete copy and paste code that you need to put in the field calculator.

The only difference is that your field would be:

[FID] Mod 2

Just Copy and Paste the above line in the Field Calculator window in ArcMap.

stuartcassin1
Deactivated User

Thanks guys.

Worked perfectly.