Skip to content

Commit

Permalink
Accept GDAL options and pass to driver on dataset creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Sep 22, 2016
1 parent 571c72e commit 5e8875e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/pdal/GDALUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ enum class GDALError
InvalidDriver,
DriverNotFound,
CantCreate,
InvalidOption,
CantWriteBlock
};

Expand Down Expand Up @@ -296,9 +297,10 @@ class PDAL_DLL Raster
\param numBands Number of bands in the raster.
\param type Datatype (int, float, etc.) of the raster data.
\param noData Value that indiciates no data in a raster cell.
\param options GDAL driver options.
*/
GDALError open(int width, int height, int numBands, Dimension::Type type,
double noData);
double noData, StringList options = StringList());

/**
Close the raster and deallocate the underlying dataset.
Expand Down
4 changes: 3 additions & 1 deletion io/gdal/GDALWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void GDALWriter::addArgs(ProgramArgs& args)
args.add("radius", "Radius from cell center to use to locate influencing "
"points", m_radius).setPositional();
args.add("gdaldriver", "GDAL writer driver name", m_drivername, "GTiff");
args.add("gdalopts", "GDAL driver options (name=value,name=value...)",
m_options);
}


Expand Down Expand Up @@ -130,7 +132,7 @@ void GDALWriter::done(PointTableRef table)
raster.writeBand(m_grid->data("mean"), 3, "mean");
raster.writeBand(m_grid->data("idw"), 4, "idw");
raster.writeBand(m_grid->data("count"), 5, "count");
raster.writeBand(m_grid->data("den"), 6, "den");
raster.writeBand(m_grid->data("stdev"), 6, "stdev");
}

} // namespace pdal
Expand Down
10 changes: 9 additions & 1 deletion io/gdal/GDALWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Grid
return (uint8_t *)m_mean.data();
if (name == "idw")
return (uint8_t *)m_idw.data();
if (name == "den")
if (name == "stdev")
return (uint8_t *)m_stdDev.data();
throw pdal_error("Requested invalid grid data '" + name + "'.");
}
Expand Down Expand Up @@ -189,6 +189,10 @@ class Grid

void update(int x, int y, double val, double dist)
{
// See
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// https://en.wikipedia.org/wiki/Inverse_distance_weighting

size_t offset = (y * m_width) + x;

double& count = m_count[offset];
Expand Down Expand Up @@ -217,6 +221,9 @@ class Grid

void finalize()
{
// See
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// https://en.wikipedia.org/wiki/Inverse_distance_weighting
for (size_t i = 0; i < m_count.size(); ++i)
{
if (m_count[i])
Expand Down Expand Up @@ -273,6 +280,7 @@ class PDAL_DLL GDALWriter : public Writer
BOX2D m_bounds;
double m_edgeLength;
double m_radius;
StringList m_options;
GridPtr m_grid;
};

Expand Down
19 changes: 16 additions & 3 deletions src/GDALUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Raster::Raster(const std::string& filename, const std::string& drivername,


GDALError Raster::open(int width, int height, int numBands,
Dimension::Type type, double noData)
Dimension::Type type, double noData, StringList options)
{
if (m_drivername.empty())
m_drivername = "GTiff";
Expand Down Expand Up @@ -527,9 +527,22 @@ GDALError Raster::open(int width, int height, int numBands,
return GDALError::InvalidDriver;
}

const char *options[2] = { "INTERLEAVE=BAND" };
std::vector<const char *> opts;

for (size_t i = 0; i < options.size(); ++i)
{
if (options[i].find("INTERLEAVE") == 0)
{
m_errorMsg = "INTERLEAVE GDAL driver option not supported.";
return GDALError::InvalidOption;
}
opts.push_back(options[i].data());
}
opts.push_back("INTERLEAVE=BAND");
opts.push_back(NULL);

m_ds = driver->Create(m_filename.data(), m_width, m_height, m_numBands,
toGdalType(type), (char **)options);
toGdalType(type), const_cast<char **>(opts.data()));
if (m_ds == NULL)
{
m_errorMsg = "Unable to open GDAL datasource '" + m_filename + "'.";
Expand Down

0 comments on commit 5e8875e

Please sign in to comment.