Static Public Attributes | |
static string | name |
static array | data |
A Keys object has a list of key - value pairs and a name. The value() function can be used to get a stored value for a specific key. A global javascript function cls()
is used to define the usage of a Keys element within a Binding. Using Keys is fast, because it allows the core engine to evaluate reclassifications without issuing calls to Javascript routines. The name / value pairs must be provided as an array / simple JSON expression (see examples below).
Basic usage example:
// create Key object var key = new Keys; key.name = 'specieskey'; key.data = { 'picea abies': 'pa', 'pinus sylvestris': 'ps'}; // use the key in a data binding: classify the source column 'SPECIES' using the 'specieskey' defined above // (e.g. translate 'picea abies' to 'pa') and store the result to the bound column 'Species'. var bind = { Species: cls('SPECIES', 'specieskey') };
Creating many Keys objects per hand might be cumbersome. In that case Keys can be loaded automatically using a Javascript function:
// Helper function that loads // classification schemes (and their translation to motive-format) // from a simple text-based table with columns 'name', 'key', 'value' function loadClasses(file_name) { var ds = new DataSource; ds.open('csv', file_name); var last_name = "???"; var keys, data; while (ds.next()) { if (ds.value("name")!=last_name) { if (ds.at()>0) { keys.data = data; print("loaded key-transformation for", keys.name); } keys = new Keys; last_name = ds.value("name"); keys.name = last_name; data = []; } data[ds.value("key")] = ds.value("value"); } if (ds.at()>0) { keys.data = data; print("loaded key-transformation for", keys.name); } } // example file: // name;key;value // species;picea abies;pa // species;pinus sylvestris;ps // dbh_1;1;2 // dbh_1;2;4
array Keys::data [static] |
the classification array as a list of key / value pairs in JSON Notation.
string Keys::name [static] |
the name of the classifcation. This name is used to refer to a classification when using the GlobalScope::cls() function.