Skip to content

Commit

Permalink
GDALDEM: use a /vsimem file instead of a disk file
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Aug 8, 2024
1 parent 67c0382 commit 2dfb4e1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/osgEarth/GDALDEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,6 @@ GDALDEMLayer::createImageImplementation(const TileKey& key, ProgressCallback* pr
osg::ref_ptr< osg::Image > image = 0;
const osg::HeightField* hf = heightField.getHeightField();

std::string tmpPath = getTempName(getTempPath(), ".tif");

GDALDataset* srcDS = createDataSetFromHeightField(hf, key.getExtent().xMin(), key.getExtent().yMin(), key.getExtent().xMax(), key.getExtent().yMax(), key.getExtent().getSRS()->getWKT());
int error = 0;
std::string processing = options().processing().get();
Expand Down Expand Up @@ -467,13 +465,18 @@ GDALDEMLayer::createImageImplementation(const TileKey& key, ProgressCallback* pr
pszColorFilename = color_filename.c_str();
}

// temporary in-memory file:
static std::atomic_int s_tempNameGen = { 0 };
std::string tmpPath = Stringify() << "/vsimem/" << std::this_thread::get_id() << std::to_string(s_tempNameGen++) << ".tif";

GDALDatasetH outputDS = GDALDEMProcessing(tmpPath.c_str(), srcDS, processing.c_str(), pszColorFilename, psOptions, &error);
if (outputDS)
{
image = createImageFromDataset((GDALDataset*)outputDS);
GDALClose(outputDS);
}
remove(tmpPath.c_str());
//remove(tmpPath.c_str());
VSIUnlink(tmpPath.c_str());
delete srcDS;
GDALDEMProcessingOptionsFree(psOptions);
CSLDestroy(papsz);
Expand Down

0 comments on commit 2dfb4e1

Please sign in to comment.