diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index 748a59458..07cec478a 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -53,7 +53,7 @@ static bool GDALAllRegister_once_() gdal_datasource::gdal_datasource(parameters const& params) : datasource(params), - dataset_(nullptr), + dataset_(nullptr, &GDALClose), desc_(gdal_datasource::name(), "utf-8"), nodata_value_(params.get("nodata")), nodata_tolerance_(*params.get("nodata_tolerance",1e-12)) @@ -85,12 +85,14 @@ gdal_datasource::gdal_datasource(parameters const& params) #if GDAL_VERSION_NUM >= 1600 if (shared_dataset_) { - dataset_ = reinterpret_cast(GDALOpenShared((dataset_name_).c_str(), GA_ReadOnly)); + auto ds = GDALOpenShared(dataset_name_.c_str(), GA_ReadOnly); + dataset_.reset(static_cast(ds)); } else #endif { - dataset_ = reinterpret_cast(GDALOpen((dataset_name_).c_str(), GA_ReadOnly)); + auto ds = GDALOpen(dataset_name_.c_str(), GA_ReadOnly); + dataset_.reset(static_cast(ds)); } if (! dataset_) @@ -98,7 +100,7 @@ gdal_datasource::gdal_datasource(parameters const& params) throw datasource_exception(CPLGetLastErrorMsg()); } - MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: opened Dataset=" << dataset_; + MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: opened Dataset=" << dataset_.get(); nbands_ = dataset_->GetRasterCount(); width_ = dataset_->GetRasterXSize(); @@ -188,8 +190,7 @@ gdal_datasource::gdal_datasource(parameters const& params) gdal_datasource::~gdal_datasource() { - MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << dataset_; - GDALClose(dataset_); + MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << dataset_.get(); } datasource::datasource_t gdal_datasource::type() const @@ -223,12 +224,9 @@ featureset_ptr gdal_datasource::features(query const& q) const mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features"); #endif - gdal_query gq = q; - - // TODO - move to std::make_shared, but must reduce # of args to <= 9 - return featureset_ptr(new gdal_featureset(*dataset_, + return std::make_shared(*dataset_, band_, - gq, + gdal_query(q), extent_, width_, height_, @@ -236,7 +234,7 @@ featureset_ptr gdal_datasource::features(query const& q) const dx_, dy_, nodata_value_, - nodata_tolerance_)); + nodata_tolerance_); } featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const @@ -245,12 +243,9 @@ featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point"); #endif - gdal_query gq = pt; - - // TODO - move to std::make_shared, but must reduce # of args to <= 9 - return featureset_ptr(new gdal_featureset(*dataset_, + return std::make_shared(*dataset_, band_, - gq, + gdal_query(pt), extent_, width_, height_, @@ -258,5 +253,5 @@ featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) dx_, dy_, nodata_value_, - nodata_tolerance_)); + nodata_tolerance_); } diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index 7e7b22164..3fc3036c8 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -55,8 +55,7 @@ public: boost::optional get_geometry_type() const; mapnik::layer_descriptor get_descriptor() const; private: - GDALDataset* open_dataset() const; - GDALDataset* dataset_; + std::unique_ptr dataset_; mapnik::box2d extent_; std::string dataset_name_; int band_; diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index 968fc6df1..fe1fe64a4 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -21,7 +21,7 @@ *****************************************************************************/ // mapnik -#include +#include #include #include #include @@ -29,7 +29,6 @@ #include #include #include -#include // stl #include @@ -39,8 +38,6 @@ #include "gdal_featureset.hpp" #include -using mapnik::query; -using mapnik::coord2d; using mapnik::box2d; using mapnik::feature_ptr; using mapnik::view_transform; @@ -77,8 +74,6 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset, gdal_featureset::~gdal_featureset() { - MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << &dataset_; - } feature_ptr gdal_featureset::next() diff --git a/plugins/input/gdal/gdal_featureset.hpp b/plugins/input/gdal/gdal_featureset.hpp index b90921149..639028b65 100644 --- a/plugins/input/gdal/gdal_featureset.hpp +++ b/plugins/input/gdal/gdal_featureset.hpp @@ -24,13 +24,12 @@ #define GDAL_FEATURESET_HPP // mapnik -#include +#include +#include #include // boost #include -#include "gdal_datasource.hpp" - class GDALDataset; class GDALRasterBand;