support for GDAL >= 2.0 in ogr plugin - refs #2259
This commit is contained in:
parent
bedd275e95
commit
dcbedc007a
3 changed files with 25 additions and 8 deletions
|
@ -71,7 +71,11 @@ ogr_datasource::~ogr_datasource()
|
|||
{
|
||||
// free layer before destroying the datasource
|
||||
layer_.free_layer();
|
||||
#if GDAL_VERSION_NUM >= 2000
|
||||
GDALClose(( GDALDatasetH) dataset_);
|
||||
#else
|
||||
OGRDataSource::DestroyDataSource (dataset_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ogr_datasource::init(mapnik::parameters const& params)
|
||||
|
@ -81,6 +85,7 @@ void ogr_datasource::init(mapnik::parameters const& params)
|
|||
#endif
|
||||
|
||||
// initialize ogr formats
|
||||
// NOTE: in GDAL >= 2.0 this is the same as GDALAllRegister()
|
||||
OGRRegisterAll();
|
||||
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
|
@ -111,17 +116,22 @@ void ogr_datasource::init(mapnik::parameters const& params)
|
|||
|
||||
if (! driver.empty())
|
||||
{
|
||||
#if GDAL_VERSION_NUM >= 2000
|
||||
unsigned int nOpenFlags = GDAL_OF_READONLY | GDAL_OF_VECTOR;
|
||||
const char* papszAllowedDrivers[] = { driver.c_str(), NULL };
|
||||
dataset_ = static_cast<gdal_dataset_type>(GDALOpenEx(dataset_name_.c_str(),nOpenFlags,papszAllowedDrivers,NULL,NULL));
|
||||
#else
|
||||
OGRSFDriver * ogr_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver.c_str());
|
||||
if (ogr_driver && ogr_driver != nullptr)
|
||||
{
|
||||
dataset_ = ogr_driver->Open((dataset_name_).c_str(), FALSE);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// open ogr driver
|
||||
dataset_ = OGRSFDriverRegistrar::Open((dataset_name_).c_str(), FALSE);
|
||||
dataset_ = static_cast<gdal_dataset_type>(OGROpen(dataset_name_.c_str(), FALSE, NULL));
|
||||
}
|
||||
|
||||
if (! dataset_)
|
||||
|
|
|
@ -63,7 +63,7 @@ private:
|
|||
mapnik::datasource::datasource_t type_;
|
||||
std::string dataset_name_;
|
||||
std::string index_name_;
|
||||
OGRDataSource* dataset_;
|
||||
gdal_dataset_type dataset_;
|
||||
ogr_layer_ptr layer_;
|
||||
std::string layer_name_;
|
||||
mapnik::layer_descriptor desc_;
|
||||
|
|
|
@ -29,9 +29,16 @@
|
|||
// stl
|
||||
#include <stdexcept>
|
||||
|
||||
// ogr
|
||||
// gdal
|
||||
#include <gdal_version.h>
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
#if GDAL_VERSION_NUM >= 2000
|
||||
typedef GDALDataset* gdal_dataset_type;
|
||||
#else
|
||||
typedef OGRDataSource* gdal_dataset_type;
|
||||
#endif
|
||||
|
||||
class ogr_layer_ptr
|
||||
{
|
||||
public:
|
||||
|
@ -62,7 +69,7 @@ public:
|
|||
is_valid_ = false;
|
||||
}
|
||||
|
||||
void layer_by_name(OGRDataSource* const datasource,
|
||||
void layer_by_name(gdal_dataset_type const datasource,
|
||||
std::string const& layer_name)
|
||||
{
|
||||
free_layer();
|
||||
|
@ -84,7 +91,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
void layer_by_index(OGRDataSource* const datasource,
|
||||
void layer_by_index(gdal_dataset_type const datasource,
|
||||
int layer_index)
|
||||
{
|
||||
free_layer();
|
||||
|
@ -110,7 +117,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
void layer_by_sql(OGRDataSource* const datasource,
|
||||
void layer_by_sql(gdal_dataset_type const datasource,
|
||||
std::string const& layer_sql)
|
||||
{
|
||||
free_layer();
|
||||
|
@ -179,7 +186,7 @@ private:
|
|||
}
|
||||
#endif
|
||||
|
||||
OGRDataSource* datasource_;
|
||||
gdal_dataset_type datasource_;
|
||||
OGRLayer* layer_;
|
||||
std::string layer_name_;
|
||||
bool owns_layer_;
|
||||
|
|
Loading…
Reference in a new issue