Show/Hide Toolbars

CatchmentSIM Help

Navigation: Program Reference > Analysis > Raster Calculator

Raster Calculator Code Examples

Scroll Prev Top Next More

 

Listed below are selected Raster Calculator Code scripts that can be used to perform a range of tasks. All Raster Calculator Code (*.rcc) scripts are included on the installation CD along with the required lookup tables. Be aware that it may be necessary to change the path of lookup tables that are referenced in the Raster Calculator Code scripts in order to use the scripts. Tutorial 4 is used as a basis for each of the examples outlined below and must be completed before the Raster Calculator Code can be used.

 

The Zonal Statistics form can be used to analyse any of the raster grids that are created from the following scripts.

 

 

Manning's 'n' Roughness

 

The following code will create a new raster grid and will assign Manning's 'n' roughness coefficients to each raster grid cell based on a land use GIS layer (Land_Use.shp\LAYER) and a lookup table (Mannings_Lookup.csv).  

 

Setup Code

 

CreateNewGrid("Mannings_n",Decimal)

 

Pixel Code

 

LookupTable1(&Manning,"C:\Mannings_Lookup.csv",#Land_Use.shp\LAYER#,1,2)    

WriteValue(#Mannings_n#,&Manning)

 

 

Probabilistic Rational Method

 

The following 3 scripts will ultimately produce a raster grid describing the variation in peak discharge across a catchment based on the Probabilistic Rational Method, which is outlined in detail in 'Australian Rainfall and Runoff: A Guide to Flood Estimation, Volume 1' (Institution of Engineers Australia, 1987).

 

Script 1 - Time of Concentration

The first script will create a .

 

Setup Code

 

CreateNewGrid("Tc_NSW",DECIMAL)

 

Pixel Code

 

{Get Contributing Area in square kilometres}

AssignVariable(&Area,#FlowAccumulation#*%Project.PixelArea/1000000)

{Determine Time of Concentration - Rational Method NSW}

WriteValue(#Tc_NSW#,0.76*(&Area^0.38))

 

 

Nutrient Export Rates

 

The following code will create three new raster grids and will assign a detailed land use description and total nitrogen and phosphorus export rates (in kg/hectare/year) to each raster grid cell based on a land use GIS layer (Land_Use.shp\LAYER) and a lookup table (Nutrient_Lookup.csv).  

 

Setup Code

 

CreateNewGrid("Land_Use",Text)

CreateNewGrid("Total_Nitrogen",Decimal)

CreateNewGrid("Total_Phosphorus",Decimal)

 

Pixel Code

 

LookupTable1(&LandUse,"C:\NutrientLookup.csv",#Land_Use.shp\LAYER#,1,2)

LookupTable1(&TN,"C:\NutrientLookup.csv",#Land_Use.shp\LAYER#,1,3)

LookupTable1(&TP,"C:\NutrientLookup.csv",#Land_Use.shp\LAYER#,1,4)  

WriteValue(#Land_Use#,&LandUse)

WriteValue(#Total_Nitrogen#,&TN)

WriteValue(#Total_Phosphorus#,&TP)

 

 

Green-Ampt Infiltration Parameters

 

The following code will generate seven new grid layers containing various Green-Ampt infiltration parameter values based on a soil GIS layer (SSURGO_Soils_Clip.shp\MUKEY) and land use GIS layer (Land_Use_Pre.shp\LAYER), soil and land use lookup tables (Soil_lookup.csv and LandUse_Lookup.csv) and some simple mathematical conversions. The first lookup table is used to assign Green-Ampt parameter values derived from the soil GIS layer and the second lookup table assigns Green-Ampt parameters derived from  the land use GIS layer (i.e., % impervious and % DCIA). In addition, this script will  generate a new grid containing basin (i.e., subcatchment) ID values based on an external GIS file (Existing_Basins.shp\USER_LABEL). Two additional grid layers  are also created, which contain soil and land use descriptions. This script has been used in South-West Florida to generate the Green-Ampt parameters necessary to integrate with the ICPR model.

 

Setup Code

 

CreateNewGrid("Basin_ID",TEXT)

CreateNewGrid("Land_Use_Description",TEXT)

CreateNewGrid("%_Imperv",DECIMAL)

CreateNewGrid("DCIA",DECIMAL)

CreateNewGrid("Soil_Names",TEXT)

CreateNewGrid("Effective_Porosity",DECIMAL)

CreateNewGrid("Hydraulic_Conductivity",DECIMAL)

CreateNewGrid("Soil_Storage",DECIMAL)

CreateNewGrid("Soil_Suction_Head",DECIMAL)

CreateNewGrid("Cutoff_Depth",DECIMAL)

AssignVariable(&LU_Lookup,"C:\LandUse_Lookup.csv")

AssignVariable(&Soil_Lookup,"C:\Soil_lookup.csv")

 

Pixel Code

 

LookupTable1(&LU,&LU_Lookup,#Land_Use_Pre.shp\LAYER#,1,2)

LookupTable1(&Imper,&LU_Lookup,#Land_Use_Pre.shp\LAYER#,1,5)

LookupTable1(&DCImperv,&LU_Lookup,#Land_Use_Pre.shp\LAYER#,1,6)

LookupTable1(&Names,&Soil_Lookup,#SSURGO_Soils_Clip.shp\MUKEY#,2,4)

LookupTable1(&Conduct,&Soil_Lookup,#SSURGO_Soils_Clip.shp\MUKEY#,2,6)

LookupTable1(&Por,&Soil_Lookup,#SSURGO_Soils_Clip.shp\MUKEY#,2,7)

LookupTable1(&S_St,&Soil_Lookup,#SSURGO_Soils_Clip.shp\MUKEY#,2,8)

LookupTable1(&S_Su,&Soil_Lookup,#SSURGO_Soils_Clip.shp\MUKEY#,2,9)

AssignVariable(&EffPor,0.9*&Por)

AssignVariable(&S_St_conv,0.083333333333*&S_St)

AssignVariable(&Cuttoff,&S_St_conv/&EffPor)

WriteValue(#Basin_ID#,#Existing_Basins.shp\USER_LABEL#)

WriteValue(#Land_Use_Description#,&LU)

WriteValue(#Soil_Names#,&Names)

WriteValue(#%_Imperv#,&Imper)

WriteValue(#DCIA#,&DCImperv)

WriteValue(#Hydraulic_Conductivity#,&Conduct)

WriteValue(#Effective_Porosity#,&EffPor)

WriteValue(#Soil_Storage#,&S_St_conv)

WriteValue(#Soil_Suction_Head#,&S_Su)

WriteValue(#Cutoff_Depth#,&Cuttoff)

 

 

Runoff Curve Numbers

 

The following code will generate runoff curve numbers for each raster grid cell using lookup tables and land use and soils GIS layers.  This code is a more advanced application of the Raster Calculator and will create six new raster grids.  It will assign hydrologic groups and soils names to two grid layers using a soil GIS layer attribute (soilmu_a_fl017.shp\MUSYM) and a lookup table (Soils ID, Names & Hyd Group.csv).  Raw land use values will be assigned directly to a new grid from a land use GIS layer (Land_Use.shp\LAYER) and a refined land use layer will be created using the raw land use raster grid and another lookup table (LandUseLookup.csv).  Refined hydrologic groups will be assigned based on an overlying land use type (Wood or Forest Land: Good cover).  Finally curve numbers will be assigned to each raster grid cell based on the hydrologic group and land use of the cell and by reference to another lookup table (FDOT Table T-7 - Selected Agricultural, Suburban, and Urban Land Use.csv). Please note that this raster calculator code is provided as an example only. If you wish to calculate runoff curve numbers, the Curve Number Calculator provides a much more simplified approach.

 

Setup Code

 

CreateNewGrid("Soil-Names",TEXT)

CreateNewGrid("Hyd_Group_Raw",TEXT)

CreateNewGrid("LandUse-Raw",TEXT)

CreateNewGrid("LandUse-Refined",TEXT)

CreateNewGrid("Hyd_Group",TEXT)

CreateNewGrid("Curve_Numbers",DECIMAL)

 

Pixel Code

 

LookupTable1(&SoilName,"C:\Soils ID, Names & Hyd Group.csv",#soilmu_a_fl017.shp\MUSYM#,1,2)

LookupTable1(&HydGroup,"C:\Soils ID, Names & Hyd Group.csv",#soilmu_a_fl017.shp\MUSYM#,1,3)

WriteValue(#Hyd_Group_Raw#,&HydGroup)

WriteValue(#Soil-Names#,&SoilName)

WriteValue(#LandUse-Raw#,#Land_Use.shp\LAYER#)

LookupTable1(&LandUseLU,"C:\LandUseLookup.csv",#LandUse-Raw#,1,2)

WriteValue(#LandUse-Refined#,&LandUseLU)

Length(&StrLength,#Hyd_Group_Raw#)

IF(&StrLength|=|1|WriteValue(#Hyd_Group#,#Hyd_Group_Raw#))

IF(&StrLength|>|1|

 Copy(&HydG1,#Hyd_Group_Raw#,1,1)

 Copy(&HydG2,#Hyd_Group_Raw#,3,1)

 IF(#LandUse-Refined#|=|"Wood or Forest Land: Good cover"|WriteValue(#Hyd_Group#,&HydG2))

 IF(#LandUse-Refined#|<>|"Wood or Forest Land: Good cover"|WriteValue(#Hyd_Group#,&HydG1))

)

 

AssignVariable(&Curve_No,NonDefined)

IF(#Hyd_Group#|=|"A"|LookupTable1(&Curve_No,"C:\FDOT Table T-7 - Selected Agricultural, Suburban, and Urban Land Use.csv",#LandUse-Refined#,1,2))

IF(#Hyd_Group#|=|"B"|LookupTable1(&Curve_No,"C:\FDOT Table T-7 - Selected Agricultural, Suburban, and Urban Land Use.csv",#LandUse-Refined#,1,3))

IF(#Hyd_Group#|=|"C"|LookupTable1(&Curve_No,"C:\FDOT Table T-7 - Selected Agricultural, Suburban, and Urban Land Use.csv",#LandUse-Refined#,1,4))

IF(#Hyd_Group#|=|"D"|LookupTable1(&Curve_No,"C:\FDOT Table T-7 - Selected Agricultural, Suburban, and Urban Land Use.csv",#LandUse-Refined#,1,5))

 

WriteValue(#Curve_Numbers#,&Curve_No)