+ make a proper bind (no ogr calls outside)

+ implement dane suggestion about using string for json datasource
+ small cosmetics
This commit is contained in:
Lucio Asnaghi 2010-11-16 17:14:22 +00:00
parent 31d170c8a6
commit 03ce43f805

View file

@ -62,18 +62,24 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")), desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")),
indexed_(false) indexed_(false)
{ {
OGRRegisterAll();
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw datasource_exception("missing <file> parameter"); boost::optional<std::string> string = params.get<std::string>("string");
if (!file && !string) throw datasource_exception("missing <file> or <string> parameter");
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false); multiple_geometries_ = *params.get<mapnik::boolean>("multiple_geometries",false);
boost::optional<std::string> base = params_.get<std::string>("base"); if (string)
if (base) {
dataset_name_ = *base + "/" + *file; dataset_name_ = *string;
}
else else
dataset_name_ = *file; {
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
dataset_name_ = *base + "/" + *file;
else
dataset_name_ = *file;
}
if (bind) if (bind)
{ {
@ -81,9 +87,20 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
} }
} }
ogr_datasource::~ogr_datasource()
{
if (is_bound_)
{
OGRDataSource::DestroyDataSource (dataset_);
}
}
void ogr_datasource::bind() const void ogr_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
// initialize ogr formats
OGRRegisterAll();
// open ogr driver // open ogr driver
dataset_ = OGRSFDriverRegistrar::Open ((dataset_name_).c_str(), FALSE); dataset_ = OGRSFDriverRegistrar::Open ((dataset_name_).c_str(), FALSE);
@ -247,14 +264,6 @@ void ogr_datasource::bind() const
is_bound_ = true; is_bound_ = true;
} }
ogr_datasource::~ogr_datasource()
{
if (is_bound_)
{
OGRDataSource::DestroyDataSource (dataset_);
}
}
std::string ogr_datasource::name() std::string ogr_datasource::name()
{ {
return "ogr"; return "ogr";