Skip to content

Commit

Permalink
rasterize_to_disk return the dataset for correct ds flush behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Feb 7, 2024
1 parent c1b85a9 commit 044f29f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gdalalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,17 @@ std::pair<GeoMetadata, std::vector<T>> rasterize(const VectorDataSet& ds, const
return std::make_pair(memDataSet.geometadata(), std::move(data));
}

void rasterize_to_disk(const VectorDataSet& ds, const fs::path& path, const std::vector<std::string>& options)
RasterDataSet rasterize_to_disk(const VectorDataSet& ds, const fs::path& path, const std::vector<std::string>& options)
{
RasterizeOptionsWrapper gdalOptions(options);

int errorCode = CE_None;
GDALRasterize(path.generic_u8string().c_str(), nullptr, ds.get(), gdalOptions.get(), &errorCode);
RasterDataSet rasterDs(GDALRasterize(path.generic_u8string().c_str(), nullptr, ds.get(), gdalOptions.get(), &errorCode));
if (errorCode != CE_None) {
throw RuntimeError("Failed to rasterize dataset {}", errorCode);
}

return rasterDs;
}

class VectorTranslateOptionsWrapper
Expand Down Expand Up @@ -516,6 +518,7 @@ gdal::RasterDataSet translate(const gdal::RasterDataSet& ds, const fs::path& out
template std::pair<GeoMetadata, std::vector<float>> rasterize<float>(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);
template std::pair<GeoMetadata, std::vector<double>> rasterize<double>(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);
template std::pair<GeoMetadata, std::vector<int32_t>> rasterize<int32_t>(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);
template std::pair<GeoMetadata, std::vector<int16_t>> rasterize<int16_t>(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);
template std::pair<GeoMetadata, std::vector<uint8_t>> rasterize<uint8_t>(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);

template std::pair<GeoMetadata, std::vector<float>> translate<float>(const RasterDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options);
Expand Down
2 changes: 1 addition & 1 deletion include/infra/gdalalgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ VectorDataSet polygonize(std::span<const T> rasterData, const GeoMetadata& meta)
template <typename T>
std::pair<GeoMetadata, std::vector<T>> rasterize(const VectorDataSet& ds, const GeoMetadata& meta, const std::vector<std::string>& options = {});

void rasterize_to_disk(const VectorDataSet& ds, const fs::path& path, const std::vector<std::string>& options = {});
RasterDataSet rasterize_to_disk(const VectorDataSet& ds, const fs::path& path, const std::vector<std::string>& options = {});

// convert a vector dataset
VectorDataSet translate_vector(const VectorDataSet& ds, const std::vector<std::string>& options = {});
Expand Down

0 comments on commit 044f29f

Please sign in to comment.