Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Grid::loadGrid(const char* filePathGrid)
- {
- // 2D vector to contain the matrix
- vector<vector<float>> data;
- unsigned nrows, ncols;
- double xllcorner, yllcorner;
- int cellsize, nodataValue;
- const int nRowHeader = 6;
- string line, strtmp;
- ifstream DEMFile;
- DEMFile.open(filePathGrid);
- if (DEMFile.is_open())
- {
- // read the header (6 lines)
- for (int index = 0; index < nRowHeader; index++)
- {
- getline(DEMFile, line);
- istringstream ss(line);
- switch (index)
- {
- case 0:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> ncols;
- }
- break;
- case 1:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> nrows;
- }
- break;
- case 2:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> xllcorner;
- }
- break;
- case 3:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> yllcorner;
- }
- break;
- case 4:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> cellsize;
- }
- break;
- case 5:
- while (ss >> strtmp)
- {
- istringstream(strtmp) >> nodataValue;
- }
- break;
- }
- }
- // Read in the elevation values
- if (ncols * nrows > 0)
- {
- // Set up sizes. (rows x cols)
- data.resize(nrows);
- for (unsigned row = 0; row < nrows; ++row)
- {
- data[row].resize(ncols);
- }
- // Load values in
- unsigned row = 0;
- while (row < nrows)
- {
- getline(DEMFile, line);
- istringstream ss(line);
- for (unsigned col =0; col < ncols; col++)
- {
- ss >> data[row][col];
- }
- row ++;
- }
- DEMFile.close();
- }
- }
- else cout << "Unable to open file";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement