Sample Lua Freeform Scripts

<< Click to Display Table of Contents >>

Navigation:  Albion 6 GIS User Guide > Appendix > APPENDIX A: Scripting in Albion GIS >

Sample Lua Freeform Scripts

The following samples demonstrate how to write freeform scripts in Lua. Such scripts are typically used to manipulate data tables.

Format


All of the samples assume that the script is operating on a database record with the following fields and values:

distribution_zone

original_diameter

diameter

material

code

983

0.200

0.150

PVC

HC203

 

Examples


 

Copy distribution_zone to original_diameter:

record.original_diameter = record.distribution_zone


original_diameter: 0.200 -> 983


 

Make diameter 3x original_diameter:

record.diameter = 3 * record.original_diameter


diameter: 0.150 -> 0.600


 

Combine code and diameter into distribution_zone, formatting diameter to 4 decimal digits

record.distribution_zone = record.code .. string.format( " -- %.4f", record.diameter )


distribution_zone: 983 -> HC203 -- 0.1500


 

If original_diameter is null, then make diameter -99, otherwise make it original_diameter

if record.original_diameter == nil then record.diameter = -99

else record.diameter = record.original_diameter

end


diameter: 0.150 -> 0.200


 

Lookup record in foreign database

-- Retrieve a handle to the table named 'othertable', which resides in the database named 'otherdb'

local tab = adb.table( 'otherdb.othertable' )

 

-- Find the first record in 'othertable' that has its 'material' field value equal to our record's 'material field value.

local mat_record = tab:find_first( 'material', record.material )

 

-- If such a record exists, then lookup the value of its 'diameter_factor' field.

if mat_record ~= nil then record.diameter = record.original_diameter * mat_record.diameter_factor

else record.diameter = record.original_diameter

end


diameter: 0.150 -> 0.200 (assuming the foreign database existed)