The IDU coverage is contained in an object of class MapLayer. MapLayer is a class that
embodies a single layer of GIS data, and provides numerous GIS operations on that data.
It also contains a pointer to a Map object that is a container of multiple MapLayers
(depending on how many are loaded) and provides for the visual display of the maps.
There are several common tasks involving MapLayer that are described below.
Getting a pointer the IDU MapLayer
A pointer to the IDU MapLayer is passed in the EnvContext structure during each invocation of an interface. To access this pointer:
const MapLayer *pLayer = pContext->pMapLayer;
Iterate over the IDU coverage and access data
Use a MapLayer::Iterator, in conjunction with the IDU's MapLayer::GetData() function, to retrieved teh current IDU data for a given field (column) in the database, as follows
const MapLayer *pLayer = pContext->pMapLayer;
for ( MapLayer::Iterator idu=pLayer->Begin(); idu < pLayer->End(); idu++ )
{
float value; // int, CString, bool, etc.depending on col datatype
pLayer->GetData( idu, m_colOfInterest, value ); // do something with the idu’s value of the specified column
}
Iterate over the DeltaArray
DeltaArray’s provide a complete history of every change that has been made to the IDU coverage. Further, Envision tracks the last time each model/process has “seen” the DeltaArray. This means that if a model/process want to see anychanges that have been made either from a particular years, form the beginning of the run, or since it was last “seen” by the model/process, that is easily accessed as follows.
DeltaArray *deltaArray = pContext->deltaArray;// get a ptr to the delta array
INT_PTR daSize = deltaArray->GetSize(); // use static size so deltas added
// by this process this cycle don’t
// get looked at!!!
// iterate through deltas added since last “seen”
for ( int i=pContext->firstUnseenDelta; i < daSize; ++i )
{
DELTA &delta = deltaArray->GetAt(i);
// do something with the delta
}
Update data in the IDU layer
Models/Processes should not modify the map directly – instead, they should add a DELTA to the map indicating the change to be made. Envision then modifies the map with all DELTA’s added when the model/process returns control to Envision when exiting the call. The EnvContext contains a pointer to a function for adding DELTA’s. To simplify use, the EnvExtension class provides a member function makes it very easy to add DELTA’s.
const MapLayer *pLayer = pContext->pMapLayer;
for ( MapLayer::Iterator idu=pLayer->Begin(); idu < pLayer->End(); idu++ )
{
float fValue = 10.0f;
int iValue = 20;
UpdateIDU( pContext, idu, m_col0, fValue, ADD_DELTA ); // note: these are polymorphic
UpdateIDU( pContext, idu, m_col1, ivalue, ADD_DELTA );
}
Expose input/output variables
Models can optionally expose
input and output variables to Envision. Exposed input variables can be set differently
across different scenarios; exposed output variables are used by Envision to collect
data from the model/process during a run. The EnvExtension parent class manages these
variables. All that is needed is to call AddInputVar() and AddOutputVar() in either the model
constructor or in your model's Init() method.
MyModel.h
class MyModel : public EnvAutoProcess
{
protected:
int m_input1; // declare input, output variables
float m_input2;
int output;
public:
// constructor
MyModel();
}
MyModel.cpp
MyModel::MyModel()
: EnvEvalModel()
, m_input1(10)
, m_input2(2)
, m_output( 5 )
{
// Arguments are label, variable, description
AddInputVar ( _T(“Input 1”), m_input1, _T(“this is an input”) );
AddInputVar ( _T(“Input 2”), m_input2, _T(“this is another”) );
AddOutputVar( _T(“Output”), m_output, _T(“this is an output”) );
}