Subversion Repositories public iLand

Rev

Rev 389 | Rev 431 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 389 Rev 393
Line 22... Line 22...
22
{
22
{
23
    if (mRandom)
23
    if (mRandom)
24
        delete mRandom;
24
        delete mRandom;
25
}
25
}
26
26
27
void StandLoader::loadForUnit()
-
 
28
{
-
 
29
-
 
30
}
-
 
31
27
32
void StandLoader::copyTrees()
28
void StandLoader::copyTrees()
33
{
29
{
34
    // we assume that all stands are equal, so wie simply COPY the trees and modify them afterwards
30
    // we assume that all stands are equal, so wie simply COPY the trees and modify them afterwards
35
    const Grid<ResourceUnit*> &ruGrid=mModel->RUgrid();
31
    const Grid<ResourceUnit*> &ruGrid=mModel->RUgrid();
Line 119... Line 115...
119
        }
115
        }
120
    }
116
    }
121
    qDebug() << "evaluateDebugTrees: enabled debugging for" << counter << "trees.";
117
    qDebug() << "evaluateDebugTrees: enabled debugging for" << counter << "trees.";
122
}
118
}
123
119
124
void StandLoader::loadInitFile(const QString &fileName, const QString &type, ResourceUnit *ru)
-
 
-
 
120
int StandLoader::loadInitFile(const QString &fileName, const QString &type, ResourceUnit *ru)
125
{
121
{
126
    QString pathFileName = GlobalSettings::instance()->path(fileName, "init");
122
    QString pathFileName = GlobalSettings::instance()->path(fileName, "init");
127
    if (!QFile::exists(pathFileName))
123
    if (!QFile::exists(pathFileName))
128
        throw IException(QString("StandLoader::loadInitFile: File %1 does not exist!").arg(pathFileName));
124
        throw IException(QString("StandLoader::loadInitFile: File %1 does not exist!").arg(pathFileName));
129
125
Line 133... Line 129...
133
        return loadiLandFile(pathFileName, ru);
129
        return loadiLandFile(pathFileName, ru);
134
130
135
    throw IException(QLatin1String("StandLoader::loadInitFile: unknown initalization.type:")+type);
131
    throw IException(QLatin1String("StandLoader::loadInitFile: unknown initalization.type:")+type);
136
}
132
}
137
133
138
void StandLoader::loadPicusFile(const QString &fileName, ResourceUnit *ru)
-
 
-
 
134
int StandLoader::loadPicusFile(const QString &fileName, ResourceUnit *ru)
139
{
135
{
140
    QString content = Helper::loadTextFile(fileName);
136
    QString content = Helper::loadTextFile(fileName);
141
    if (content.isEmpty()) {
137
    if (content.isEmpty()) {
142
        qDebug() << "file not found: " + fileName;
138
        qDebug() << "file not found: " + fileName;
143
        return;
-
 
-
 
139
        return 0;
144
    }
140
    }
145
    loadSingleTreeList(content, ru, fileName);
-
 
-
 
141
    return loadSingleTreeList(content, ru, fileName);
146
}
142
}
147
143
148
/** load a list of trees (given by content) to a resource unit. Param fileName is just for error reporting.
144
/** load a list of trees (given by content) to a resource unit. Param fileName is just for error reporting.
149
  returns the number of loaded trees.
145
  returns the number of loaded trees.
150
  */
146
  */
Line 252... Line 248...
252
    return cnt;
248
    return cnt;
253
    //qDebug() << "loaded init-file contained" << lines.count() <<"lines.";
249
    //qDebug() << "loaded init-file contained" << lines.count() <<"lines.";
254
    //qDebug() << "lines: " << lines;
250
    //qDebug() << "lines: " << lines;
255
}
251
}
256
252
257
void StandLoader::loadDistributionList(const QString &content, ResourceUnit *ru, const QString &fileName)
-
 
-
 
253
/** initialize trees on a resource unit based on dbh distributions.
-
 
254
  use a fairly clever algorithm to determine tree positions.
-
 
255
  see http://iland.boku.ac.at/initialize+trees
-
 
256
  @param content tree init file (including headers) in a string
-
 
257
  @param ru resource unit
-
 
258
  @param fileName source file name (for error reporting)
-
 
259
  @return number of trees added
-
 
260
  */
-
 
261
int StandLoader::loadDistributionList(const QString &content, ResourceUnit *ru, const QString &fileName)
258
{
262
{
259
    if (!ru)
263
    if (!ru)
260
        ru = mModel->ru();
264
        ru = mModel->ru();
261
    Q_ASSERT(ru!=0);
265
    Q_ASSERT(ru!=0);
262
    SpeciesSet *speciesSet = ru->speciesSet(); // of default RU
266
    SpeciesSet *speciesSet = ru->speciesSet(); // of default RU
Line 277... Line 281...
277
        throw IException(QString("load-ini-file: file '%1' containts not all required fields (count, species, dbh_from, dbh_to, hd, age).").arg(fileName));
281
        throw IException(QString("load-ini-file: file '%1' containts not all required fields (count, species, dbh_from, dbh_to, hd, age).").arg(fileName));
278
282
279
    mInitItems.clear();
283
    mInitItems.clear();
280
    InitFileItem item;
284
    InitFileItem item;
281
    bool ok;
285
    bool ok;
-
 
286
    int total_count = 0;
282
    for (int row=0;row<infile.rowCount();row++) {
287
    for (int row=0;row<infile.rowCount();row++) {
283
         item.count = infile.value(row, icount).toInt();
288
         item.count = infile.value(row, icount).toInt();
-
 
289
         total_count += item.count;
284
         item.dbh_from = infile.value(row, idbh_from).toDouble();
290
         item.dbh_from = infile.value(row, idbh_from).toDouble();
285
         item.dbh_to = infile.value(row, idbh_to).toDouble();
291
         item.dbh_to = infile.value(row, idbh_to).toDouble();
286
         item.hd = infile.value(row, ihd).toDouble();
292
         item.hd = infile.value(row, ihd).toDouble();
287
         ok = true;
293
         ok = true;
288
         if (iage>=0)
294
         if (iage>=0)
Line 319... Line 325...
319
    }
325
    }
320
326
321
    // exeucte the
327
    // exeucte the
322
    executeiLandInit(ru);
328
    executeiLandInit(ru);
323
    ru->cleanTreeList();
329
    ru->cleanTreeList();
-
 
330
    return total_count;
324
331
325
}
332
}
326
333
327
void StandLoader::loadiLandFile(const QString &fileName, ResourceUnit *ru)
-
 
-
 
334
int StandLoader::loadiLandFile(const QString &fileName, ResourceUnit *ru)
328
{
335
{
329
    if (!QFile::exists(fileName))
336
    if (!QFile::exists(fileName))
330
        throw IException(QString("load-ini-file: file '%1' does not exist.").arg(fileName));
337
        throw IException(QString("load-ini-file: file '%1' does not exist.").arg(fileName));
331
    QString content = Helper::loadTextFile(fileName);
338
    QString content = Helper::loadTextFile(fileName);
332
    loadDistributionList(content, ru, fileName);
-
 
-
 
339
    return loadDistributionList(content, ru, fileName);
333
}
340
}
334
341
335
// evenlist: tentative order of pixel-indices (within a 5x5 grid) used as tree positions.
342
// evenlist: tentative order of pixel-indices (within a 5x5 grid) used as tree positions.
336
// e.g. 12 = centerpixel, 0: upper left corner, ...
343
// e.g. 12 = centerpixel, 0: upper left corner, ...
337
int evenlist[25] = { 12, 6, 18, 16, 8, 22, 2, 10, 14, 0, 24, 20, 4,
344
int evenlist[25] = { 12, 6, 18, 16, 8, 22, 2, 10, 14, 0, 24, 20, 4,