+ cache GDALDataset object for re-use

This commit is contained in:
Artem Pavlenko 2012-06-27 17:44:51 +01:00
parent bfa7052e84
commit 72344c3918
3 changed files with 20 additions and 14 deletions

View file

@ -52,29 +52,35 @@ inline GDALDataset* gdal_datasource::open_dataset() const
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Opening " << dataset_name_;
GDALDataset *dataset;
if (dataset_)
{
return dataset_;
}
//GDALDataset *dataset;
#if GDAL_VERSION_NUM >= 1600
if (shared_dataset_)
{
dataset = reinterpret_cast<GDALDataset*>(GDALOpenShared((dataset_name_).c_str(), GA_ReadOnly));
dataset_ = reinterpret_cast<GDALDataset*>(GDALOpenShared((dataset_name_).c_str(), GA_ReadOnly));
}
else
#endif
{
dataset = reinterpret_cast<GDALDataset*>(GDALOpen((dataset_name_).c_str(), GA_ReadOnly));
dataset_ = reinterpret_cast<GDALDataset*>(GDALOpen((dataset_name_).c_str(), GA_ReadOnly));
}
if (! dataset)
if (! dataset_)
{
throw datasource_exception(CPLGetLastErrorMsg());
}
return dataset;
return dataset_;
}
gdal_datasource::gdal_datasource(parameters const& params, bool bind)
: datasource(params),
dataset_(0),
desc_(*params.get<std::string>("type"), "utf-8"),
filter_factor_(*params_.get<double>("filter_factor", 0.0)),
nodata_value_(params_.get<double>("nodata"))
@ -114,10 +120,9 @@ void gdal_datasource::bind() const
band_ = *params_.get<int>("band", -1);
GDALDataset *dataset = open_dataset();
nbands_ = dataset->GetRasterCount();
width_ = dataset->GetRasterXSize();
height_ = dataset->GetRasterYSize();
nbands_ = dataset_->GetRasterCount();
width_ = dataset_->GetRasterXSize();
height_ = dataset_->GetRasterYSize();
double tr[6];
bool bbox_override = false;
@ -144,7 +149,7 @@ void gdal_datasource::bind() const
}
else
{
dataset->GetGeoTransform(tr);
dataset_->GetGeoTransform(tr);
}
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource Geotransform="
@ -183,7 +188,7 @@ void gdal_datasource::bind() const
extent_.init(x0, y0, x1, y1);
}
GDALClose(dataset);
//GDALClose(dataset);
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Size=" << width_ << "," << height_;
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Extent=" << extent_;
@ -193,6 +198,8 @@ void gdal_datasource::bind() const
gdal_datasource::~gdal_datasource()
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << dataset_;
GDALClose(dataset_);
}
datasource::datasource_t gdal_datasource::type() const

View file

@ -47,6 +47,7 @@ public:
void bind() const;
private:
GDALDataset* open_dataset() const;
mutable GDALDataset* dataset_;
mutable mapnik::box2d<double> extent_;
std::string dataset_name_;
mutable int band_;

View file

@ -76,9 +76,7 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
gdal_featureset::~gdal_featureset()
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << &dataset_;
GDALClose(&dataset_);
//
}
feature_ptr gdal_featureset::next()