Rev 137 | Rev 140 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 137 | Rev 138 | ||
---|---|---|---|
Line 98... | Line 98... | ||
98 | return; |
98 | return; |
99 | char sep='\t'; |
99 | char sep='\t'; |
100 | if (!lines[0].contains(sep)) |
100 | if (!lines[0].contains(sep)) |
101 | sep=';'; |
101 | sep=';'; |
102 | QStringList headers = lines[0].split(sep); |
102 | QStringList headers = lines[0].split(sep); |
103 | //int iSpecies = headers.indexOf("species");
|
- | |
104 | //int iCount = headers.indexOf("count");
|
- | |
- | 103 | ||
105 | int iX = headers.indexOf("x"); |
104 | int iX = headers.indexOf("x"); |
106 | int iY = headers.indexOf("y"); |
105 | int iY = headers.indexOf("y"); |
107 | int iBhd = headers.indexOf("bhdfrom"); |
106 | int iBhd = headers.indexOf("bhdfrom"); |
108 | int iHeight = headers.indexOf("treeheight"); |
107 | int iHeight = headers.indexOf("treeheight"); |
109 | int iSpecies = headers.indexOf("species"); |
108 | int iSpecies = headers.indexOf("species"); |
- | 109 | if (iX==-1 || iY==-1 || iBhd==-1 || iSpecies==-1 || iHeight==-1) |
|
- | 110 | throw IException(QString("Initfile %1 is not valid!").arg(fileName)); |
|
110 | 111 | ||
- | 112 | double dbh; |
|
111 | for (int i=1;i<lines.count();i++) { |
113 | for (int i=1;i<lines.count();i++) { |
112 | QString &line = lines[i]; |
114 | QString &line = lines[i]; |
113 | //qDebug() << "line" << i << ":" << line;
|
- | |
- | 115 | dbh = line.section(sep, iBhd, iBhd).toDouble(); |
|
- | 116 | if (dbh<5.) |
|
- | 117 | continue; |
|
114 | Tree &tree = ru->newTree(); |
118 | Tree &tree = ru->newTree(); |
115 | QPointF f;
|
119 | QPointF f;
|
116 | if (iX>=0 && iY>=0) { |
120 | if (iX>=0 && iY>=0) { |
117 | f.setX( line.section(sep, iX, iX).toDouble() ); |
121 | f.setX( line.section(sep, iX, iX).toDouble() ); |
118 | f.setY( line.section(sep, iY, iY).toDouble() ); |
122 | f.setY( line.section(sep, iY, iY).toDouble() ); |
119 | f+=offset; |
123 | f+=offset; |
120 | tree.setPosition(f); |
124 | tree.setPosition(f); |
121 | }
|
125 | }
|
122 | if (iBhd>=0) |
- | |
123 | tree.setDbh(line.section(sep, iBhd, iBhd).toDouble()); |
- | |
124 | if (tree.dbh() < 5) |
- | |
125 | continue; // 5cm: lower threshold for the moment |
- | |
126 | if (iHeight>=0) |
- | |
127 | tree.setHeight(line.section(sep, iHeight, iHeight).toDouble()/100.); // convert from Picus-cm to m. |
- | |
128 | 126 | ||
129 | if (iSpecies>=0) { |
- | |
130 | int idx = picusSpeciesIds.indexOf(line.section(sep, iSpecies, iSpecies)); |
- | |
131 | QString speciesid="piab"; |
- | |
132 | if (idx>0) |
- | |
133 | speciesid = iLandSpeciesIds[idx]; |
- | |
134 | Species *s = speciesSet->species(speciesid); |
- | |
135 | - | ||
136 | tree.setRU(ru); |
- | |
137 | tree.setSpecies(s); |
- | |
138 | }
|
- | |
- | 127 | tree.setDbh(dbh); |
|
- | 128 | tree.setHeight(line.section(sep, iHeight, iHeight).toDouble()/100.); // convert from Picus-cm to m. |
|
- | 129 | int idx = picusSpeciesIds.indexOf(line.section(sep, iSpecies, iSpecies)); |
|
- | 130 | QString speciesid="piab"; |
|
- | 131 | if (idx>0) |
|
- | 132 | speciesid = iLandSpeciesIds[idx]; |
|
- | 133 | Species *s = speciesSet->species(speciesid); |
|
- | 134 | if (!ru || !s) |
|
- | 135 | throw IException("Loading init-file: either ressource unit or species invalid."); |
|
139 | 136 | ||
- | 137 | tree.setRU(ru); |
|
- | 138 | tree.setSpecies(s); |
|
140 | tree.setup(); |
139 | tree.setup(); |
141 | }
|
140 | }
|
142 | //qDebug() << "loaded init-file contained" << lines.count() <<"lines.";
|
141 | //qDebug() << "loaded init-file contained" << lines.count() <<"lines.";
|
143 | //qDebug() << "lines: " << lines;
|
142 | //qDebug() << "lines: " << lines;
|
144 | 143 |