Skip to content

Commit

Permalink
Don't use a destructed value in GDALReader::inspect. (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Oct 25, 2018
1 parent 1b80f8b commit f65a5c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
30 changes: 17 additions & 13 deletions io/GDALReader.cpp
Expand Up @@ -84,20 +84,10 @@ void GDALReader::initialize()
m_width = m_raster->width();
m_height = m_raster->height();
m_bandTypes = m_raster->getPDALDimensionTypes();
m_raster.reset();
}


QuickInfo GDALReader::inspect()
{
QuickInfo qi;
std::unique_ptr<PointLayout> layout(new PointLayout());

initialize();
addDimensions(layout.get());

qi.m_pointCount = m_width * m_height;

auto p = std::find(m_bandIds.begin(), m_bandIds.end(), Dimension::Id::Z);

int nBand(1);
Expand All @@ -107,13 +97,27 @@ QuickInfo GDALReader::inspect()
nBand = (int) std::distance(m_bandIds.begin(), p) + 1;
}

m_dimNames.clear();
Dimension::IdList dims = layout->dims();
for (auto di = dims.begin(); di != dims.end(); ++di)
qi.m_dimNames.push_back(layout->dimName(*di));
m_dimNames.push_back(layout->dimName(*di));
m_bounds = m_raster->bounds(nBand);

qi.m_bounds = m_raster->bounds(nBand);
qi.m_srs = m_raster->getSpatialRef();
m_raster.reset();
}


QuickInfo GDALReader::inspect()
{
QuickInfo qi;

initialize();

qi.m_pointCount = m_width * m_height;
qi.m_srs = getSpatialReference();
qi.m_bounds = m_bounds;
qi.m_valid = true;
qi.m_dimNames = m_dimNames;

return qi;
}
Expand Down
5 changes: 4 additions & 1 deletion io/GDALReader.hpp
Expand Up @@ -35,7 +35,7 @@
#pragma once

#include <string>

#include <vector>

#include <pdal/Dimension.hpp>
#include <pdal/Reader.hpp>
Expand Down Expand Up @@ -77,6 +77,9 @@ class PDAL_DLL GDALReader : public Reader , public Streamable
point_count_t m_index;
int m_row;
int m_col;

BOX3D m_bounds;
StringList m_dimNames;
};

} // namespace pdal
Expand Down
2 changes: 1 addition & 1 deletion pdal/QuickInfo.hpp
Expand Up @@ -48,7 +48,7 @@ struct QuickInfo
BOX3D m_bounds;
SpatialReference m_srs;
point_count_t m_pointCount;
std::vector<std::string> m_dimNames;
StringList m_dimNames;
bool m_valid;

QuickInfo() : m_pointCount(0), m_valid(false)
Expand Down

0 comments on commit f65a5c3

Please sign in to comment.