Commit 42950427 authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch 'dem-big-folder' into 'develop'

Avoid reloading the same DEM directory

See merge request !917
parents 762e6f14 66f7861a
Pipeline #11054 passed with stage
in 22 minutes and 1 second
......@@ -20,4 +20,4 @@ Several DEM tiles can be provided at the same time, using the ``OpenDEMDirectory
A geoid file can be opened using the ``OpenGeoidFile`` method, and the default height above ellipsoid can be set using ``OpenGeoidFile`` method.
The ``ClearElevationParameters`` method can be used to clear the DEMs, the geoid and the default height above ellipsoid. All associated GDAL datasets will be closed.
\ No newline at end of file
The ``ClearElevationParameters`` method can be used to clear the DEMs, the geoid and the default height above ellipsoid. All associated GDAL datasets will be closed. The ``OpenDEMDirectory`` method won't reopen a directory already loaded, even if the content of the directory changed. To force loading the new tiles, one needs to call ``ClearElevationParameters``.
......@@ -57,14 +57,21 @@ std::vector<std::string> GetFilesInDirectory(const std::string & directoryPath)
// End iterator : default construction yields past-the-end
for ( const auto & item : boost::make_iterator_range(boost::filesystem::directory_iterator(directoryPath), {}) )
{
if ( boost::filesystem::is_directory(item.status()) )
try
{
auto subDirList = GetFilesInDirectory(item.path().string());
fileList.insert(fileList.end(), subDirList.begin(), subDirList.end());
if ( boost::filesystem::is_directory(item.status()) )
{
auto subDirList = GetFilesInDirectory(item.path().string());
fileList.insert(fileList.end(), subDirList.begin(), subDirList.end());
}
else
{
fileList.push_back(item.path().string());
}
}
else
catch (boost::filesystem::filesystem_error& e)
{
fileList.push_back(item.path().string());
otbLogMacro(Warning, << e.what())
}
}
......@@ -204,6 +211,16 @@ void DEMHandler::OpenDEMFile(const std::string& path)
void DEMHandler::OpenDEMDirectory(const std::string& DEMDirectory)
{
auto isSameDirectory = [&DEMDirectory](std::string const& s)
{
return s == DEMDirectory;
};
if(std::any_of(std::begin(m_DEMDirectories), std::end(m_DEMDirectories), isSameDirectory))
{
otbLogMacro(Info, << "Directory '"<< DEMDirectory << "' already opened.")
return;
}
// Free the previous in-memory dataset (if any)
if (!m_DatasetList.empty())
VSIUnlink(DEM_DATASET_PATH.c_str());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment