Select to view content in your preferred language

Attribute Assistant - MOD Operator for Address Parity

1496
6
Jump to solution
07-28-2022 11:26 AM
JasonBalmut
Frequent Contributor

I am trying to calculate values for my NENA NextGen 9-1-1 parity fields by using the VBScript MOD operator.  The results should be (E)ven, (O)dd, (Z)ero, or (B)oth.  Here's what I have so far, although I do not get results with the ValueInfo expressions I have listed.  I'm unsure if this is a problem with the parentheses or the MOD operator itself.

Left Parity

  • TableName: MasterStreetName
  • FieldName: Parity_L
  • ValueMethod: EXPRESSION
  • ValueInfo (expressions tried):
    • IIF([FromAddr_L] MOD 2 = 0 and [ToAddr_L] MOD 2 = 0, "E", IIF([FromAddr_L] MOD 2 = 1 and [ToAddr_L] MOD 2 = 1, "O", IIF([FromAddr_L] = 0 and [ToAddr_L] = 0, "Z", "B")))
    • IIF(([FromAddr_L] MOD 2 = 0 and [ToAddr_L] MOD 2 = 0), "E", IIF(([FromAddr_L] MOD 2 = 1 and [ToAddr_L] MOD 2 = 1), "O", IIF(([FromAddr_L] = 0 and [ToAddr_L] = 0), "Z", "B")))

Right Parity

  • TableName: MasterStreetName
  • FieldName: Parity_R
  • ValueMethod: EXPRESSION
  • ValueInfo (expressions tried):
    • IIF([FromAddr_R] MOD 2 = 0 and [ToAddr_R] MOD 2 = 0, "E", IIF([FromAddr_R] MOD 2 = 1 and [ToAddr_R] MOD 2 = 1, "O", IIF([FromAddr_R] = 0 and ToAddr_R] = 0, "Z", "B")))
    • IIF(([FromAddr_R] MOD 2 = 0 and [ToAddr_R] MOD 2 = 0), "E", IIF(([FromAddr_R] MOD 2 = 1 and [ToAddr_R] MOD 2 = 1), "O", IIF(([FromAddr_R] = 0 and ToAddr_R] = 0), "Z", "B")))

Any help is welcome.

Thank you.

0 Kudos
1 Solution

Accepted Solutions
JasonBalmut
Frequent Contributor

The solution was to put the Zero part of the expression before the Odd/Even.  Here are the final expressions:

Left Parity

  • TableName: MasterStreetName
  • FieldName: Parity_L
  • ValueMethod: EXPRESSION
  • ValueInfo:
    • IIF([FromAddr_L] = 0 AND [ToAddr_L] = 0, "Z", IIF([FromAddr_L] MOD 2 = 0 AND [ToAddr_L] MOD 2 = 0, "E", IIF([FromAddr_L] MOD 2 = 1 AND [ToAddr_L] MOD 2 = 1, "O", "B")))

Right Parity

  • TableName: MasterStreetName
  • FieldName: Parity_R
  • ValueMethod: EXPRESSION
  • ValueInfo (expressions tried):
    • IIF([FromAddr_R] = 0 AND [ToAddr_R] = 0, "Z", IIF([FromAddr_R] MOD 2 = 0 AND [ToAddr_R] MOD 2 = 0, "E", IIF([FromAddr_R] MOD 2 = 1 AND [ToAddr_R] MOD 2 = 1, "O", "B")))

View solution in original post

0 Kudos
6 Replies
JoshSaad1
Frequent Contributor

I do something similar, but using Arcade.  Here's my code:

Left Parity

var leftfrom = Boolean($feature.fromleft % 2)
var leftto = Boolean($feature.toleft % 2)

if($feature.fromleft == null || $feature.toleft == null) {
return null
}
else {
if($feature.fromleft == 0 && $feature.toleft == 0) {
return "Z"
}
else {
if(leftfrom == false && leftto == false) {
return "E"
}
if(leftfrom == true && leftto == true) {
return "O"
}
if(leftfrom == false && leftto == true) {
return "B"
}
if(leftfrom == true && leftto == false) {
return "B"
}
}
}

 

Right Parity

var rightfrom = Boolean($feature.fromright % 2)
var rightto = Boolean($feature.toright % 2)

if($feature.fromright == null || $feature.toright == null) {
return null
}
else {
if($feature.fromright == 0 && $feature.toright == 0) {
return "Z"
}
else {
if(rightfrom == false && rightto == false) {
return "E"
}
if(rightfrom == true && rightto == true) {
return "O"
}
if(rightfrom == false && rightto == true) {
return "B"
}
if(rightfrom == true && rightto == false) {
return "B"
}
}
}

It automatically applies the expressions as soon as you tab out from the address number fields.

JasonBalmut
Frequent Contributor

@JoshSaad1 , we have to use ArcGIS Desktop's Attribute Assistant add-in for now and it does not use Arcade, it only uses VBScript.  I will keep your solution in mind for when we switch to Pro.

0 Kudos
NormWray
Occasional Contributor

Would you be willing to explain the "% 2" used in your function? I have run across this in several code blocks, but can't find it documented.

 

Thanks

0 Kudos
JoshSaad1
Frequent Contributor

I'm not a programmer, but from what I understand this is called a Modulo.  It determines whether there is a remainder when dividing one number by another.  Even numbers don't have remainders and return 0.  Odd numbers return 1.  The Boolean function interprets 1 as True, and 0 as False.  

0 Kudos
JasonBalmut
Frequent Contributor

Update to the original post

The following expressions work for all cases except for zeros which results in (E)ven.  The ValueInfo lines are 168 characters each.

Left Parity

  • TableName: MasterStreetName
  • FieldName: Parity_L
  • ValueMethod: EXPRESSION
  • ValueInfo:
    • IIF([FromAddr_L] MOD 2 = 0 AND [ToAddr_L] MOD 2 = 0, "E", IIF([FromAddr_L] MOD 2 = 1 AND [ToAddr_L] MOD 2 = 1, "O", IIF([FromAddr_L] = 0 AND [ToAddr_L] = 0, "Z", "B")))

Right Parity

  • TableName: MasterStreetName
  • FieldName: Parity_R
  • ValueMethod: EXPRESSION
  • ValueInfo (expressions tried):
    • IIF([FromAddr_R] MOD 2 = 0 AND [ToAddr_R] MOD 2 = 0, "E", IIF([FromAddr_R] MOD 2 = 1 AND [ToAddr_R] MOD 2 = 1, "O", IIF([FromAddr_R] = 0 AND [ToAddr_R] = 0, "Z", "B")))

I have tried a few variations to get the zeros to work but haven't found one yet that is less than 255 characters.  The following two were tested but failed and each is 253 characters in length:

  • IIF(([FromAddr_L] > 0 AND [FromAddr_L] MOD 2 = 0) AND ([ToAddr_L] > 0 AND [ToAddr_L] MOD 2 = 0), "E", IIF([FromAddr_L] > 0 AND [FromAddr_L] MOD 2 = 1) AND ([ToAddr_L] > 0 AND [ToAddr_L] MOD 2 = 1), "O", IIF([FromAddr_L] = 0 AND [ToAddr_L] = 0, "Z", "B")
  • IIF(([FromAddr_R] > 0 AND [FromAddr_R] MOD 2 = 0) AND ([ToAddr_R] > 0 AND [ToAddr_R] MOD 2 = 0), "E", IIF([FromAddr_R] > 0 AND [FromAddr_R] MOD 2 = 1) AND ([ToAddr_R] > 0 AND [ToAddr_R] MOD 2 = 1), "O", IIF([FromAddr_R] = 0 AND [ToAddr_R] = 0, "Z", "B")

Suggestions?

0 Kudos
JasonBalmut
Frequent Contributor

The solution was to put the Zero part of the expression before the Odd/Even.  Here are the final expressions:

Left Parity

  • TableName: MasterStreetName
  • FieldName: Parity_L
  • ValueMethod: EXPRESSION
  • ValueInfo:
    • IIF([FromAddr_L] = 0 AND [ToAddr_L] = 0, "Z", IIF([FromAddr_L] MOD 2 = 0 AND [ToAddr_L] MOD 2 = 0, "E", IIF([FromAddr_L] MOD 2 = 1 AND [ToAddr_L] MOD 2 = 1, "O", "B")))

Right Parity

  • TableName: MasterStreetName
  • FieldName: Parity_R
  • ValueMethod: EXPRESSION
  • ValueInfo (expressions tried):
    • IIF([FromAddr_R] = 0 AND [ToAddr_R] = 0, "Z", IIF([FromAddr_R] MOD 2 = 0 AND [ToAddr_R] MOD 2 = 0, "E", IIF([FromAddr_R] MOD 2 = 1 AND [ToAddr_R] MOD 2 = 1, "O", "B")))
0 Kudos