''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Tam.WizAdjPolygons Script ' Function: Adjusts Land_value to reflect partial cells near polygons representing ' a different conservation cost. It adds up new value on top of the existing ' land values and treats the partial PU polygons. It then calculates new ' Easement values and new EBIs using the adjusted land values (based onTam.WizAdjProtAreas) ' Input: - PU polygon theme ' - land cover grid theme ' - conservation cost polygon theme ' Output: - modified PU theme ' Author: Miroslav Honzak ' Conservation International ' Last update: April 17, 2003 - Created and tested. ' December 12, 2003 - Excluded the Brazilian data dependency ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' theView = av.GetActiveDoc theThemeList = theView.GetThemes if (theThemeList.count = 0) then Return Nil end 'theView = av.FindDoc("Analysis View") 'theThemeList = theView.GetThemes 'if (theThemeList.count = 0) then ' Return Nil 'end 'Check if Spatial Analyst Extention is loaded anExtention = Extension.Find("Spatial Analyst") if (anExtention = nil) then MsgBox.Info("Please load Spatial Analyst Extension first", "") Return Nil end 'Extract polygon theme list and grid theme list thePUThemeList = {} theGridThemeList = {} theArgumentList = {} for each t in theThemeList if ( t.Is(FTHEME) ) then theVTab = t.GetFTab theShapeField = theVTab.findField("shape") if ( theShapeField = nil ) then continue end theTotalRecs = theVTab.GetNumRecords if( theTotalRecs < 1 ) then continue end theShape = theVtab.ReturnValue(theShapeField, 0) if ( theShape = Nil ) then continue end theClassName = theShape.GetClass.GetClassName if ( theClassName = "Polygon" ) then thePUThemeList.Add(t) end elseif ( t.Is(GTHEME) ) then theGridThemeList.Add(t) end 'if end 'Check whether the Polygon theme list or Grid theme list is empty if ( thePUThemeList.count = 0 ) then MsgBox.Info("There is no polygon theme in the active view", "Error") Return Nil end if ( theGridThemeList.count = 0 ) then MsgBox.Info("There is no grid theme in the active view", "Error") Return Nil end '************************************************************** 'Request user to select input PU and other useful themes '************************************************************** thePUTheme = Msgbox.List(thePUThemeList, "Select PLANING UNIT theme", "Input Dialog") if ( thePUTheme = Nil ) then Return Nil end thePATheme = Msgbox.List(thePUThemeList, "Select adjusted CONSERVATION COST boundaries", "Input Dialog") if ( thePATheme = Nil ) then Return Nil end theValField = NIL theValFieldList = {} ConsCostFieldList ={} for each f in thePATheme.GetFTab.GetFields if ((f.AsString = "Shape").Not) then ConsCostFieldList.Add(f.AsString) end end if (ConsCostFieldList.FindbyValue("Value_ha") < 0) then theValFieldList = MsgBox.List(ConsCostFieldList,"Pick VALUE PER HA field","Input Dialog") if (theValFieldList = NIL) then addValueha= MsgBox.Input("Enter CONSERVATION COST to be added on top of the existing land values within conservation cost boundaries (US$ per ha)", "Input Dialog", "10.00") if ( addValueha = NIL ) then exit end thePAFTab = thePATheme.GetFTab thePAFTab.seteditable(TRUE) theValField = Field.Make( "Value_ha", #FIELD_DECIMAL, 8, 2 ) thePAFTab.AddFields( {theValField} ) thePAFTab.Calculate ( addValueha, thePAFTab.FindField("Value_ha") ) thePAFTab.seteditable(FALSE) end end thePUTheme.GetFTab.GetSelection.ClearAll thePUTheme.GetFTab.UpdateSelection '************************************************************** ' Request user to enter Land_Value regression coefficients '************************************************************** labels = { "Primary Forest", "Secondary Forest", "Other Forested Media" } defaults = { "-1.20619", "-0.7967599", "-0.309976" } theCoefList = MsgBox.MultiInput( "Enter Regression Coefficients used for calculating Land Values", "Input Dialog", labels, defaults ) if (theCoefList.Count = 0) then Return NIL end '************************************************************** ' SELECT PUs INTERSECTING WITH CONSERVATION COST POLYGONS '************************************************************** anFTab = thePUTheme.GetFTab theNumRecs = anFTab.GetNumRecords thePUTheme.SelectByTheme( thePATheme, #FTAB_RELTYPE_INTERSECTS, 0, #VTAB_SELTYPE_NEW ) ' We must intersect here in order to get area InsideFTab = av.Run( "Tam.IntersectThemes", {thePUTheme, thePATheme, True, False} ) theDeleteFieldList = {} for each f in InsideFTab.GetFields if (Not(f.AsString = "Shape") AND Not(f.AsString = "Value_ha")) then theDeleteFieldList.Add(f) end end InsideFTab.SetEditable(TRUE) InsideFTab.RemoveFields( theDeleteFieldList ) InsideFTab.SetEditable(FALSE) InsideFTheme = FTheme.Make( InsideFTab ) 'theView.AddTheme( InsideFTheme ) anFTab.SetEditable(TRUE) theSet = anFTab.GetSelection ' FOR ALL SELECTED RECORDS add newLandValue on top of the existing Land_Value ' Recalculate Easements and new EBIs using new Land Values n=0 for each theRec in theSet av.ShowMsg( "Calculating values inside...") av.ShowStopButton progress = ( (theRec+1) / theNumRecs ) * 100 doMore = av.SetStatus(progress) if (not doMore) then break end '-------Get Area and Value from Intersecitng PUs--------- addValueha = InsideFTab.ReturnValue(InsideFTab.FindField("Value_ha"), n) theInsidePoly = InsideFTab.ReturnValue(InsideFTab.FindField("Shape"), n) inside_ha = theInsidePoly.ReturnArea/10000 n=n+1 '-----------New Land Value--------------- oldLandValue = anFTab.ReturnValue(anFTab.FindField("Land_Value"), theRec) newLandValue = oldLandValue + (addValueha * inside_ha) anFTab.SetValue(anFTab.FindField("Land_Value"), theRec, newLandValue) '--------------New EBIs------------------ if ( (newLandValue <> NIL) and (newLandValue <> 0) ) then EBI_Pref = anFTab.ReturnValue(anFTab.FindField("EBI_Pref"), theRec) EBI_Core = anFTab.ReturnValue(anFTab.FindField("EBI_Core"), theRec) nourbwat = anFTab.ReturnValue(anFTab.FindField("Nourbwa_ha"), theRec) EBI_Pref_per_LV = 1000 * nourbwat * EBI_Pref / newLandValue EBI_Core_per_LV = 1000 * nourbwat * EBI_Core / newLandValue else EBI_Pref_per_LV = NIL EBI_Core_per_LV = NIL end anFTab.SetValue(anFTab.FindField("EBI_PperLV"), theRec, EBI_Pref_per_LV) anFTab.SetValue(anFTab.FindField("EBI_CperLV"), theRec, EBI_Core_per_LV) '-----------New Easements---------------- landval = newLandValue '''FOR BRAZIL'''landval = (newLandValue - (addValueha * inside_ha)) / 1.137 if ( ((landval <> Nil) and (landval <> 0)) and (nourbwat <> 0) ) then primfoha = anFTab.ReturnValue(anFTab.FindField("Pfor_ha"), theRec) secforha = anFTab.ReturnValue(anFTab.FindField("Sfor_ha"), theRec) cabrucha = anFTab.ReturnValue(anFTab.FindField("Cab_ha"), theRec) noncabha = nourbwat - cabrucha lnpricha = (landval/nourbwat).ln theEuler = Number.GetEuler ' EV1 lnpricprimfo = lnpricha - ((theCoefList.Get(0).AsNumber) * ((primfoha/nourbwat) - 1.0)) - ((theCoefList.Get(1).AsNumber) * ((secforha/nourbwat) - 0.0)) - ((theCoefList.Get(2).AsNumber) * ((cabrucha/nourbwat) - 0.0)) predp_hf = ((theEuler^(lnpricprimfo)) * nourbwat) + (addValueha * inside_ha) '''FOR BRAZIL'''predp_hf = ((theEuler^(lnpricprimfo)) * nourbwat * 1.137) + (addValueha * inside_ha) easement1 = newLandValue - ( predp_hf/2 ) ' EV2 easement2 = newLandValue - predp_hf ' EV3 lnpricprimfoexcab = lnpricha - ((theCoefList.Get(0).AsNumber) * ((primfoha/nourbwat) - (noncabha/nourbwat))) - ((theCoefList.Get(1).AsNumber) * (secforha/nourbwat)) predp_hc = ((theEuler^(lnpricprimfoexcab)) * nourbwat) + (addValueha * inside_ha) '''FOR BRAZIL'''predp_hc = ((theEuler^(lnpricprimfoexcab)) * nourbwat * 1.137) + (addValueha * inside_ha) easement3 = newLandValue - predp_hc ' EV4 easement4 = 0.5 * ( easement2 + easement3 ) else landvalue = NIL easement1 = NIL easement2 = NIL easement3 = NIL easement4 = NIL end anFTab.SetValue(anFTab.FindField("EaseVal1"), theRec, easement1) anFTab.SetValue(anFTab.FindField("EaseVal2"), theRec, easement2) anFTab.SetValue(anFTab.FindField("EaseVal3"), theRec, easement3) anFTab.SetValue(anFTab.FindField("EaseVal4"), theRec, easement4) end '********************************************************************************* anFTab.SetEditable(FALSE) thePUTheme.GetFTab.GetSelection.ClearAll thePUTheme.GetFTab.UpdateSelection av.ClearMsg av.ClearStatus av.PurgeObjects