User Tools

Site Tools


howtos:toolcoding:using_maps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howtos:toolcoding:using_maps [2011/06/16 17:35]
chris.strashok
howtos:toolcoding:using_maps [2011/06/17 16:03] (current)
chris.strashok
Line 241: Line 241:
 A //​category//​ is a useful way of grouping elements into meaningfull collections. By categorizing related elements together you can create elements that are more descriptive while also reducing the number of elements you are carrying through your model. A //​category//​ is a useful way of grouping elements into meaningfull collections. By categorizing related elements together you can create elements that are more descriptive while also reducing the number of elements you are carrying through your model.
  
-The mapcat tool can also be used for aggregating elements into classes or groups. The example below uses the data found in the following table to use the categorization as a map to transform the data for each province to the number of regions ​while aggregating to get the total in each region.+The mapcat tool can also be used for aggregating elements into classes or groups. The example below uses the data found in the following table to use the categorization as a map to transform the population ​data for each province to a region class while aggregating ​over each province ​to get the total population ​in each region.
  
-for is used to map group and member element informants onto a category and conversely it is also used to "​break"​ a category apart into its compnent group and member informants using the mapcat tool.+{{:​howtos:​toolcoding:​mapdata5_rev1.gif|}}
  
-{{:howtos:​toolcoding:​mapdata5.gif|}}+The supporting tool script code for building the informants and importing data above can be found [[howtos:​toolcoding:​mapEx5|here]].
  
-The supporting tool script code for building ​the informants ​and importing data from the data source in the table above can be found [[howtos:​toolcoding:​mapEx5|here]].+The mapping template ​for a category is held in the category itself. As you can see in the code below the provinces is the group place holder ​and the locations are members of the province and they are related to each based on a relationship provided by the modeler.
  
-The mapping template for a category ​is held in the category itself. As you can see in the code below the provinces is the group place holder and the location are members of the province and they are related to each based on a relationship provided by the modeler.+<​code>​ 
 + 
 +localinformant locProv[l->​p] = create (; object=category, groups=location,​ members=province,​ \ 
 + "​west"​="​Alberta",​ \ 
 + "​west"​="​British Columbia",​\ 
 + "​east"​="​Newfoundland",​\ 
 + "​east"​="​Nova Scotia",​\ 
 + "​central"​="​Ontario",​\ 
 + "​east"​="​PEI"​) 
 + 
 +</​code>​ 
 + 
 +This categorization or map can then be applied using the mapcat tool below to bring the elements together in the category.
  
 <​code>​ <​code>​
  
-localinformant provLoc[p->l] = create ​(; object=category, groups=province,​ members=location, \ +local provLoc_Cat[l->p] = mapcat ​(provinceData[p]; category=locProv) 
- "​Alberta"​="​west",​ \ + 
- "​British Columbia"​="​west",​\ +table (provLoc_Cat[l->​p])
- "​Newfoundland"​="​east",​\ +
- "Nova Scotia"​="​east",​\ +
- "​Ontario"​="​central",​\ +
- "​PEI"​="​east"​)+
  
 </​code>​ </​code>​
  
-This categorization or map can then be applied using the mapcat tool below to either bring the elements together in the category ​or split the category apart+See how the province and location informants have been categorized into the provLoc category. 
 + 
 +{{:​howtos:​toolcoding:​mapresults5a_rev1.gif|}} 
 + 
 +Now we can use the mapcat tool again, but this time we will be splitting ​the category ​back up into the respective group and members.
  
 <​code>​ <​code>​
  
-local regionsCat[p->l] = mapcat (regionData[p,l]; category=provLoc)+local regions[l,p] = mapcat (provLoc_Cat[l->p])
  
-table (regionsCat[p->l])+table (regions[l,p])
  
 </​code>​ </​code>​
  
-The table below displays ​how the province and location informants ​have been categorized into the provLoc category.+See how we have now created a two dimensional array from a data set that only had one dimension.
  
-{{:​howtos:​toolcoding:​mapresults5a.gif|image}}+{{:​howtos:​toolcoding:​mapresults5c.gif|}} 
 + 
 +We can now sum up the provinces dimension to get the total population for each region as seen in the table below.
  
 <​code>​ <​code>​
  
-local regionsSplit[p,l] = mapcat ​(regionsCat[p->l])+local regions_sum[l] = sum (regions[l,p]; \ 
 + dim=province)
  
-table (regionsSplit[p,l])+table (regions_sum[l])
  
 </​code>​ </​code>​
  
-Inversely the table below displays how we can split the category onto its component group and member informants+{{:​howtos:​toolcoding:​mapresults5b_rev1.gif|}}
  
-{{:howtos:​toolcoding:​mapresults5b.gif|image}}+This process has been broken down inorder to see how the transformation occurs, however there is no need to take this many steps. This process can be done on one line by combining the two mapcat and sum tool commands as follows:
  
 +<​code>​
 +
 +local regions[l] = sum (mapcat (mapcat (provinceData[p];​ \
 + category=provLoc);​ \
 + dim=provLoc);​ \ 
 + dim=province)
 +
 +</​code>​
howtos/toolcoding/using_maps.1308245726.txt.gz · Last modified: 2011/06/16 17:35 by chris.strashok