Compare commits
2 commits
master
...
gdaldatase
Author | SHA1 | Date | |
---|---|---|---|
|
55c0e3e0f2 | ||
|
72344c3918 |
3 changed files with 21 additions and 15 deletions
|
@ -52,29 +52,35 @@ inline GDALDataset* gdal_datasource::open_dataset() const
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Opening " << dataset_name_;
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Opening " << dataset_name_;
|
||||||
|
|
||||||
GDALDataset *dataset;
|
if (dataset_)
|
||||||
|
{
|
||||||
|
return dataset_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//GDALDataset *dataset;
|
||||||
#if GDAL_VERSION_NUM >= 1600
|
#if GDAL_VERSION_NUM >= 1600
|
||||||
if (shared_dataset_)
|
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
|
else
|
||||||
#endif
|
#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());
|
throw datasource_exception(CPLGetLastErrorMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataset;
|
return dataset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
||||||
: datasource(params),
|
: datasource(params),
|
||||||
|
dataset_(0),
|
||||||
desc_(*params.get<std::string>("type"), "utf-8"),
|
desc_(*params.get<std::string>("type"), "utf-8"),
|
||||||
filter_factor_(*params_.get<double>("filter_factor", 0.0)),
|
filter_factor_(*params_.get<double>("filter_factor", 0.0)),
|
||||||
nodata_value_(params_.get<double>("nodata"))
|
nodata_value_(params_.get<double>("nodata"))
|
||||||
|
@ -113,11 +119,10 @@ void gdal_datasource::bind() const
|
||||||
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
|
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
|
||||||
band_ = *params_.get<int>("band", -1);
|
band_ = *params_.get<int>("band", -1);
|
||||||
|
|
||||||
GDALDataset *dataset = open_dataset();
|
dataset_ = open_dataset();
|
||||||
|
nbands_ = dataset_->GetRasterCount();
|
||||||
nbands_ = dataset->GetRasterCount();
|
width_ = dataset_->GetRasterXSize();
|
||||||
width_ = dataset->GetRasterXSize();
|
height_ = dataset_->GetRasterYSize();
|
||||||
height_ = dataset->GetRasterYSize();
|
|
||||||
|
|
||||||
double tr[6];
|
double tr[6];
|
||||||
bool bbox_override = false;
|
bool bbox_override = false;
|
||||||
|
@ -144,7 +149,7 @@ void gdal_datasource::bind() const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dataset->GetGeoTransform(tr);
|
dataset_->GetGeoTransform(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource Geotransform="
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource Geotransform="
|
||||||
|
@ -183,7 +188,7 @@ void gdal_datasource::bind() const
|
||||||
extent_.init(x0, y0, x1, y1);
|
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 Size=" << width_ << "," << height_;
|
||||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Extent=" << extent_;
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Raster Extent=" << extent_;
|
||||||
|
@ -193,6 +198,8 @@ void gdal_datasource::bind() const
|
||||||
|
|
||||||
gdal_datasource::~gdal_datasource()
|
gdal_datasource::~gdal_datasource()
|
||||||
{
|
{
|
||||||
|
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << dataset_;
|
||||||
|
GDALClose(dataset_);
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource::datasource_t gdal_datasource::type() const
|
datasource::datasource_t gdal_datasource::type() const
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
void bind() const;
|
void bind() const;
|
||||||
private:
|
private:
|
||||||
GDALDataset* open_dataset() const;
|
GDALDataset* open_dataset() const;
|
||||||
|
mutable GDALDataset* dataset_;
|
||||||
mutable mapnik::box2d<double> extent_;
|
mutable mapnik::box2d<double> extent_;
|
||||||
std::string dataset_name_;
|
std::string dataset_name_;
|
||||||
mutable int band_;
|
mutable int band_;
|
||||||
|
|
|
@ -76,9 +76,7 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
||||||
|
|
||||||
gdal_featureset::~gdal_featureset()
|
gdal_featureset::~gdal_featureset()
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Closing Dataset=" << &dataset_;
|
//
|
||||||
|
|
||||||
GDALClose(&dataset_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
feature_ptr gdal_featureset::next()
|
feature_ptr gdal_featureset::next()
|
||||||
|
|
Loading…
Reference in a new issue