--- MAIN PROGRAM -- -- GLOBAL VARIABLES cs85 = CellularSpace{ dbType = "ADO", host = "localhost", database = "D:\\Usuarios\\Tiago\\Rondonia.mdb", user = "", password = "", layer = "celulas_500_Anari_1985", theme = "celulas_500_Anari_1985", select = {"cover_" } } cs95 = CellularSpace{ dbType = "ADO", host = "localhost", database = "D:\\Usuarios\\Tiago\\Rondonia.mdb", user = "", password = "", layer = "celulas_500_Anari_1995", theme = "celulas_500_Anari_1995", select = {"cover_","soil_fert", "dist_urban", "protected", "dist_rodovia_BR", "dist_ramal_princ", "dist_ramal_sec", "dist_vicinal"} } -- UTILITY FUNCTIONS -- Creates a inter-celular spaces neighborhood: each cell in "cs85" has a -- Moore like neighborhood in the "cs95" cellular space function CreateNeighborhoodFrom85to95( cs85, cs95 ) ForEachCell( cs85, function( cell85 ) local neigh = Neighborhood(); for lin = -1,1,1 do for col = -1,1,1 do -- add neighbor local index = TeCoord{ x = (cell85.x + col), y = (cell85.y + lin)}; neigh:addCell( index, cs95, 1/9 ); -- wheight = 0.111111 (9 neighbors) end end cell85:addNeighborhood( neigh ); end ); end -- RULES -- Loads and synchronizes both celular spaces cs85:load(); cs95:load(); cs85:synchronize(); cs95:synchronize(); -- Creates inter-celular spaces neighbouhood CreateNeighborhoodFrom85to95( cs85, cs95 ); -- Traverses the "cs85" cellular space and prints average value from the "dist_urban" -- attribute from the neighbor of each cell in the "cs95" cellular space. Note that -- the "dist_urban" hasnīt been loaded for the "cs85" cellular space. -- Cells that have less than 9 neighbors are in the border of the cellular space! ForEachCell( cs85, function( cell85 ) local sum = 0; local count = 0; ForEachNeighbor( cell85, 0, -- 0 is the first neighborhood from a cell. function( cell, nestedCell , weight ) -- nested_cell belongs to "cs95" -- calculates the sum sum = sum + nestedCell.dist_urban; count = count + 1; end ); -- calculates the average local average = 0; if( count > 0)then average = sum / count; end -- print the result values print("Cell["..cell85.x..","..cell85.y.."]: neighbors ="..count..", average = "..average); end );