Hi folks,I am new to this python game and hopefully I can get pointed in the right direction. I am trying to run a field calculator python script using an IF THEN statment.My data exists like this:Species Code 1Species Code 1 PercentageSpecies Code 2Species Code 2 PercentageSpecies Code 3Species Code 3 PercentageAnd so on to 7.I am trying to fill in an area field using a logic like this:PL_volIf Species code 1 = PLThen Species Code 1 Percentage x AreaIf Species Code 1/= PL Then move to species code 2 to validate. Essentially what I am trying to do is search the species code fields for PL then multiply the corresponding value by an area. If somebody could point me in the right direction or has suggestions I would be very greatful.Thanks,BrettI am using ARCGIS 10.0INFO
Percent = 0 If Not IsNull([Species Code 1]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 1 Percentage] End If If Not IsNull([Species Code 2]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 2 Percentage] End If If Not IsNull([Species Code 3]) Then If [Species Code 3] = "PL" Then Percent = [Species Code 3 Percentage] End If If Not IsNull([Species Code 4]) Then If [Species Code 4] = "PL" Then Percent = [Species Code 4 Percentage] End If If Not IsNull([Species Code 5]) Then If [Species Code 5] = "PL" Then Percent = [Species Code 5 Percentage] End If If Not IsNull([Species Code 6]) Then If [Species Code 6] = "PL" Then Percent = [Species Code 6 Percentage] End If If Not IsNull([Species Code 7]) Then If [Species Code 7] = "PL" Then Percent = [Species Code 7 Percentage] End If Output = Percent * [Area]
One last question, say I wanted to change another value based on the if statment. Something like this: Percent = 0 Volume = 0 If Not IsNull([Species Code 1]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 1 Percentage] And [Species 1 Live Volume ] End If If Not IsNull([Species Code 2]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 2 Percentage] And [Species 2 Live Volume ] End If If Not IsNull([Species Code 3]) Then If [Species Code 3] = "PL" Then Percent = [Species Code 3 Percentage] And [Species 3 Live Volume ] End If If Not IsNull([Species Code 4]) Then If [Species Code 4] = "PL" Then Percent = [Species Code 4 Percentage] And [Species 4 Live Volume ] End If If Not IsNull([Species Code 5]) Then If [Species Code 5] = "PL" Then Percent = [Species Code 5 Percentage] And [Species 5 Live Volume ] End If If Not IsNull([Species Code 6]) Then If [Species Code 6] = "PL" Then Percent = [Species Code 6 Percentage] And [Species 6 Live Volume ] End If If Not IsNull([Species Code 7]) Then If [Species Code 7] = "PL" Then Percent = [Species Code 7 Percentage] And [Species 7 Live Volume ] End If Output = Percent * Volume Thanks again,Brett
Percent = 0 Volume = 0 If Not IsNull([Species Code 1]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 1 Percentage] And [Species 1 Live Volume ] End If If Not IsNull([Species Code 2]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 2 Percentage] And [Species 2 Live Volume ] End If If Not IsNull([Species Code 3]) Then If [Species Code 3] = "PL" Then Percent = [Species Code 3 Percentage] And [Species 3 Live Volume ] End If If Not IsNull([Species Code 4]) Then If [Species Code 4] = "PL" Then Percent = [Species Code 4 Percentage] And [Species 4 Live Volume ] End If If Not IsNull([Species Code 5]) Then If [Species Code 5] = "PL" Then Percent = [Species Code 5 Percentage] And [Species 5 Live Volume ] End If If Not IsNull([Species Code 6]) Then If [Species Code 6] = "PL" Then Percent = [Species Code 6 Percentage] And [Species 6 Live Volume ] End If If Not IsNull([Species Code 7]) Then If [Species Code 7] = "PL" Then Percent = [Species Code 7 Percentage] And [Species 7 Live Volume ] End If Output = Percent * Volume
Percent = 0 Volume = 0 If Not IsNull([Species Code 1]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 1 Percentage] And Volume = [Species 1 Live Volume ] End If If Not IsNull([Species Code 2]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 2 Percentage] And Volume= [Species 2 Live Volume ] End If If Not IsNull([Species Code 3]) Then If [Species Code 3] = "PL" Then Percent = [Species Code 3 Percentage] And Volume= [Species 3 Live Volume ] End If If Not IsNull([Species Code 4]) Then If [Species Code 4] = "PL" Then Percent = [Species Code 4 Percentage] And Volume= [Species 4 Live Volume ] End If If Not IsNull([Species Code 5]) Then If [Species Code 5] = "PL" Then Percent = [Species Code 5 Percentage] And Volume= [Species 5 Live Volume ] End If If Not IsNull([Species Code 6]) Then If [Species Code 6] = "PL" Then Percent = [Species Code 6 Percentage] And Volume= [Species 6 Live Volume ] End If If Not IsNull([Species Code 7]) Then If [Species Code 7] = "PL" Then Percent = [Species Code 7 Percentage] And Volume= [Species 7 Live Volume ] End If Output = Percent * Volume
I am a VB Script guy with the Field Calculator. This should work:Parser: VB ScriptUse Codeblock: CheckedPre-Logic Script Codeblock:Percent = 0 If Not IsNull([Species Code 1]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 1 Percentage] End If If Not IsNull([Species Code 2]) Then If [Species Code 2] = "PL" Then Percent = [Species Code 2 Percentage] End If If Not IsNull([Species Code 3]) Then If [Species Code 3] = "PL" Then Percent = [Species Code 3 Percentage] End If If Not IsNull([Species Code 4]) Then If [Species Code 4] = "PL" Then Percent = [Species Code 4 Percentage] End If If Not IsNull([Species Code 5]) Then If [Species Code 5] = "PL" Then Percent = [Species Code 5 Percentage] End If If Not IsNull([Species Code 6]) Then If [Species Code 6] = "PL" Then Percent = [Species Code 6 Percentage] End If If Not IsNull([Species Code 7]) Then If [Species Code 7] = "PL" Then Percent = [Species Code 7 Percentage] End If Output = Percent * [Area]Expression (your PL percent of area field): OutputIf no field contains "PL" then no percent of area is associated with the species and the output will be 0. It is assumed that only one Species Code field can contain "PL" for any given record. Edited to handle NULL Species codes.
Percent = 0 If Not IsNull([SPECIES_CD_1]) Then If [SPECIES_CD_1] = "PL" Then Percent = [SPECIES_PCT_1] End If If Not IsNull([SPECIES_CD_2]) Then If [SPECIES_CD_2] = "PL" Then Percent = [SPECIES_PCT_2] End If If Not IsNull([SPECIES_CD_3]) Then If [SPECIES_CD_3] = "PL" Then Percent = [SPECIES_PCT_3] End If If Not IsNull([SPECIES_CD_4]) Then If [SPECIES_CD_4] = "PL" Then Percent = [SPECIES_PCT_4] End If If Not IsNull([SPECIES_CD_5]) Then If [SPECIES_CD_5] = "PL" Then Percent = [SPECIES_PCT_5] End If If Not IsNull([SPECIES_CD_6]) Then If [SPECIES_CD_6] = "PL" Then Percent = [SPECIES_PCT_6] End If Output = Percent * [Area_ha_1]
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.