Landscape
Iterating through the sites on the landscape
The landscape is represented as a 2-dimensional grid of equal-sized squares called sites. An individual site is identified by its location - row and column - in the gird.
However, there is no need to use nested loops with coordinates of each site on the landscape if all of them need to be accessed; a simple foreach loop is used instead. Thus, the basic loop to work with sites is:
foreach (Site site in Model.Core.Landscape.AllSites)
{
// do something with the current site (either active or inactive)
}
The basic loop to work with active sites on the landscape is:
foreach (ActiveSite site in Model.Core.Landscape)
{
// do something with the current active site
}
Example from Base Wind extension:
int eventCount = 0; // number of occured events
foreach (ActiveSite site in Model.Core.Landscape)
{
// Try to initiate a wind event at current active site;
// a new event won't initiate at the site if it is already
// part of another event.
Event windEvent = Event.Initiate(site, Timestep);
if (windEvent != null)
{
// A new wind event started at the current active site,
// and spread to neighboring sites. Log details about
// the event.
LogEvent(Model.Core.CurrentTime, windEvent);
eventCount++;
}
}
// Report # of events to the User Interface and log file
UI.WriteLine("Wind events: {0}", eventCount);
For more information refer to Landis.Landscape Namespace in the LANDIS-II Help File for Developers
Page 1 | Page 2
