add 'base' path option to sql,gdal, and ogr plugins and touchup handling of missing files with boost filesystem - closes #263

This commit is contained in:
Dane Springmeyer 2009-03-30 20:19:57 +00:00
parent 6166da7c22
commit e7c9d02fd3
7 changed files with 38 additions and 10 deletions

View file

@ -43,9 +43,15 @@ gdal_datasource::gdal_datasource( parameters const& params)
{
GDALAllRegister();
boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw datasource_exception("missing <file> paramater");
if (!file) throw datasource_exception("missing <file> parameter");
dataset_ = boost::shared_ptr<GDALDataset>(reinterpret_cast<GDALDataset*>(GDALOpen((*file).c_str(),GA_ReadOnly)));
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
dataset_name_ = *base + "/" + *file;
else
dataset_name_ = *file;
dataset_ = boost::shared_ptr<GDALDataset>(reinterpret_cast<GDALDataset*>(GDALOpen((dataset_name_).c_str(),GA_ReadOnly)));
if (!dataset_) throw datasource_exception("failed to create GDALDataset");
double tr[6];
dataset_->GetGeoTransform(tr);

View file

@ -41,6 +41,7 @@ class gdal_datasource : public mapnik::datasource
mapnik::layer_descriptor get_descriptor() const;
private:
mapnik::Envelope<double> extent_;
std::string dataset_name_;
boost::shared_ptr<GDALDataset> dataset_;
mapnik::layer_descriptor desc_;
};

View file

@ -36,6 +36,8 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik')
libraries.append('icuuc')
libraries.append('icudata')
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
ogr_inputdriver = env.SharedLibrary('ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)

View file

@ -25,6 +25,9 @@
#include "ogr_featureset.hpp"
#include <mapnik/ptree_helpers.hpp>
// boost
#include <boost/filesystem/operations.hpp>
using std::clog;
using std::endl;
@ -51,15 +54,23 @@ ogr_datasource::ogr_datasource(parameters const& params)
OGRRegisterAll();
boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw datasource_exception("missing <file> paramater");
if (!file) throw datasource_exception("missing <file> parameter");
boost::optional<std::string> layer = params.get<std::string>("layer");
if (!layer) throw datasource_exception("missing <layer> paramater");
if (!layer) throw datasource_exception("missing <layer> parameter");
layerName_ = *layer;
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
dataset_ = OGRSFDriverRegistrar::Open ((*file).c_str(), FALSE);
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
dataset_name_ = *base + "/" + *file;
else
dataset_name_ = *file;
if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist");
dataset_ = OGRSFDriverRegistrar::Open ((dataset_name_).c_str(), FALSE);
if (!dataset_) throw datasource_exception(CPLGetLastErrorMsg());
layer_ = dataset_->GetLayerByName (layerName_.c_str());

View file

@ -50,6 +50,7 @@ class ogr_datasource : public mapnik::datasource
static const std::string name_;
mapnik::Envelope<double> extent_;
int type_;
std::string dataset_name_;
OGRDataSource* dataset_;
OGRLayer* layer_;
std::string layerName_;

View file

@ -91,7 +91,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params)
format_(mapnik::wkbGeneric)
{
boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw datasource_exception("missing <file> paramater");
if (!file) throw datasource_exception("missing <file> parameter");
boost::optional<std::string> wkb = params.get<std::string>("wkb_format");
if (wkb)
@ -103,9 +103,15 @@ sqlite_datasource::sqlite_datasource(parameters const& params)
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true);
if (!boost::filesystem::exists(*file)) throw datasource_exception(*file + " don't exists");
dataset_ = new sqlite_connection (*file);
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
dataset_name_ = *base + "/" + *file;
else
dataset_name_ = *file;
if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist");
dataset_ = new sqlite_connection (dataset_name_);
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext)
@ -181,7 +187,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params)
{
/*
XXX - This is problematic, if we don't have at least a row,
XXX - This is problematic, if we do not have at least a row,
we cannot determine the right columns types and names
as all column_type are SQLITE_NULL
*/

View file

@ -53,6 +53,7 @@ class sqlite_datasource : public mapnik::datasource
mapnik::Envelope<double> extent_;
mutable bool extent_initialized_;
int type_;
std::string dataset_name_;
sqlite_connection* dataset_;
std::string table_;
std::string metadata_;