Merge pull request #1654 from mapnik/no-bind

Remove bind option for datasources closes #962, reverts #622, refs #1655 and #1656
This commit is contained in:
Dane Springmeyer 2012-12-17 13:11:33 -08:00
commit 83215ba726
37 changed files with 380 additions and 722 deletions

View file

@ -50,24 +50,15 @@ namespace
using namespace boost::python; using namespace boost::python;
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d) boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{ {
bool bind=true;
mapnik::parameters params; mapnik::parameters params;
boost::python::list keys=d.keys(); boost::python::list keys=d.keys();
for (int i=0; i<len(keys); ++i) for (int i=0; i<len(keys); ++i)
{ {
std::string key = extract<std::string>(keys[i]); std::string key = extract<std::string>(keys[i]);
object obj = d[key]; object obj = d[key];
if (key == "bind")
{
bind = extract<bool>(obj)();
continue;
}
extract<std::string> ex0(obj); extract<std::string> ex0(obj);
extract<int> ex1(obj); extract<int> ex1(obj);
extract<double> ex2(obj); extract<double> ex2(obj);
if (ex0.check()) if (ex0.check())
{ {
params[key] = ex0(); params[key] = ex0();
@ -82,7 +73,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
} }
} }
return mapnik::datasource_cache::instance().create(params, bind); return mapnik::datasource_cache::instance().create(params);
} }
boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds) boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
@ -170,7 +161,6 @@ void export_datasource()
.def("describe",&describe) .def("describe",&describe)
.def("envelope",&datasource::envelope) .def("envelope",&datasource::envelope)
.def("features",&datasource::features) .def("features",&datasource::features)
.def("bind",&datasource::bind)
.def("fields",&fields) .def("fields",&fields)
.def("field_types",&field_types) .def("field_types",&field_types)
.def("features_at_point",&datasource::features_at_point, (arg("coord"),arg("tolerance")=0)) .def("features_at_point",&datasource::features_at_point, (arg("coord"),arg("tolerance")=0))

View file

@ -31,20 +31,12 @@ using namespace boost::python;
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d) boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{ {
bool bind=true;
mapnik::parameters params; mapnik::parameters params;
boost::python::list keys=d.keys(); boost::python::list keys=d.keys();
for (int i=0; i<len(keys); ++i) for (int i=0; i<len(keys); ++i)
{ {
std::string key = extract<std::string>(keys[i]); std::string key = extract<std::string>(keys[i]);
object obj = d[key]; object obj = d[key];
if (key == "bind")
{
bind = extract<bool>(obj)();
continue;
}
extract<std::string> ex0(obj); extract<std::string> ex0(obj);
extract<int> ex1(obj); extract<int> ex1(obj);
extract<double> ex2(obj); extract<double> ex2(obj);
@ -63,7 +55,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
} }
} }
return mapnik::datasource_cache::instance().create(params, bind); return mapnik::datasource_cache::instance().create(params);
} }
void register_datasources(std::string const& path) void register_datasources(std::string const& path)

View file

@ -86,10 +86,7 @@ public:
}; };
datasource (parameters const& params) datasource (parameters const& params)
: params_(params), : params__(params) {}
is_bound_(false)
{
}
/*! /*!
* @brief Get the configuration parameters of the data source. * @brief Get the configuration parameters of the data source.
@ -100,7 +97,7 @@ public:
*/ */
parameters const& params() const parameters const& params() const
{ {
return params_; return params__;
} }
/*! /*!
@ -108,12 +105,6 @@ public:
* @return The type of the datasource (Vector or Raster) * @return The type of the datasource (Vector or Raster)
*/ */
virtual datasource_t type() const = 0; virtual datasource_t type() const = 0;
/*!
* @brief Connect to the datasource
*/
virtual void bind() const {}
virtual featureset_ptr features(query const& q) const = 0; virtual featureset_ptr features(query const& q) const = 0;
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0; virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
virtual box2d<double> envelope() const = 0; virtual box2d<double> envelope() const = 0;
@ -121,12 +112,11 @@ public:
virtual layer_descriptor get_descriptor() const = 0; virtual layer_descriptor get_descriptor() const = 0;
virtual ~datasource() {} virtual ~datasource() {}
protected: protected:
parameters params_; parameters params__;
mutable bool is_bound_;
}; };
typedef const char * datasource_name(); typedef const char * datasource_name();
typedef datasource* create_ds(parameters const& params, bool bind); typedef datasource* create_ds(parameters const& params);
typedef void destroy_ds(datasource *ds); typedef void destroy_ds(datasource *ds);
class datasource_deleter class datasource_deleter
@ -145,9 +135,9 @@ typedef boost::shared_ptr<datasource> datasource_ptr;
{ \ { \
return classname::name(); \ return classname::name(); \
} \ } \
extern "C" MAPNIK_EXP datasource* create(parameters const& params, bool bind) \ extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
{ \ { \
return new classname(params, bind); \ return new classname(params); \
} \ } \
extern "C" MAPNIK_EXP void destroy(datasource *ds) \ extern "C" MAPNIK_EXP void destroy(datasource *ds) \
{ \ { \

View file

@ -48,7 +48,7 @@ public:
std::string plugin_directories(); std::string plugin_directories();
void register_datasources(std::string const& path); void register_datasources(std::string const& path);
bool register_datasource(std::string const& path); bool register_datasource(std::string const& path);
boost::shared_ptr<datasource> create(parameters const& params, bool bind=true); boost::shared_ptr<datasource> create(parameters const& params);
private: private:
datasource_cache(); datasource_cache();
~datasource_cache(); ~datasource_cache();

View file

@ -56,23 +56,23 @@ using namespace boost::spirit;
DATASOURCE_PLUGIN(csv_datasource) DATASOURCE_PLUGIN(csv_datasource)
csv_datasource::csv_datasource(parameters const& params, bool bind) csv_datasource::csv_datasource(parameters const& params)
: datasource(params), : datasource(params),
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")),
extent_(), extent_(),
filename_(), filename_(),
inline_string_(), inline_string_(),
file_length_(0), file_length_(0),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params.get<int>("row_limit", 0)),
features_(), features_(),
escape_(*params_.get<std::string>("escape", "")), escape_(*params.get<std::string>("escape", "")),
separator_(*params_.get<std::string>("separator", "")), separator_(*params.get<std::string>("separator", "")),
quote_(*params_.get<std::string>("quote", "")), quote_(*params.get<std::string>("quote", "")),
headers_(), headers_(),
manual_headers_(mapnik::util::trim_copy(*params_.get<std::string>("headers", ""))), manual_headers_(mapnik::util::trim_copy(*params.get<std::string>("headers", ""))),
strict_(*params_.get<mapnik::boolean>("strict", false)), strict_(*params.get<mapnik::boolean>("strict", false)),
quiet_(*params_.get<mapnik::boolean>("quiet", false)), quiet_(*params.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params_.get<float>("filesize_max", 20.0)), // MB filesize_max_(*params.get<float>("filesize_max", 20.0)), // MB
ctx_(boost::make_shared<mapnik::context_type>()) ctx_(boost::make_shared<mapnik::context_type>())
{ {
/* TODO: /* TODO:
@ -97,36 +97,22 @@ csv_datasource::csv_datasource(parameters const& params, bool bind)
http://boost-spirit.com/home/articles/qi-example/tracking-the-input-position-while-parsing/ http://boost-spirit.com/home/articles/qi-example/tracking-the-input-position-while-parsing/
*/ */
boost::optional<std::string> inline_string = params_.get<std::string>("inline"); boost::optional<std::string> inline_string = params.get<std::string>("inline");
if (inline_string) if (inline_string)
{ {
inline_string_ = *inline_string; inline_string_ = *inline_string;
} }
else else
{ {
boost::optional<std::string> file = params_.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw mapnik::datasource_exception("CSV Plugin: missing <file> parameter"); if (!file) throw mapnik::datasource_exception("CSV Plugin: missing <file> parameter");
boost::optional<std::string> base = params_.get<std::string>("base"); boost::optional<std::string> base = params.get<std::string>("base");
if (base) if (base)
filename_ = *base + "/" + *file; filename_ = *base + "/" + *file;
else else
filename_ = *file; filename_ = *file;
} }
if (bind)
{
this->bind();
}
}
csv_datasource::~csv_datasource() { }
void csv_datasource::bind() const
{
if (is_bound_) return;
if (!inline_string_.empty()) if (!inline_string_.empty())
{ {
std::istringstream in(inline_string_); std::istringstream in(inline_string_);
@ -140,14 +126,16 @@ void csv_datasource::bind() const
parse_csv(in,escape_, separator_, quote_); parse_csv(in,escape_, separator_, quote_);
in.close(); in.close();
} }
is_bound_ = true;
} }
csv_datasource::~csv_datasource() { }
template <typename T> template <typename T>
void csv_datasource::parse_csv(T & stream, void csv_datasource::parse_csv(T & stream,
std::string const& escape, std::string const& escape,
std::string const& separator, std::string const& separator,
std::string const& quote) const std::string const& quote)
{ {
stream.seekg(0, std::ios::end); stream.seekg(0, std::ios::end);
file_length_ = stream.tellg(); file_length_ = stream.tellg();
@ -890,14 +878,11 @@ datasource::datasource_t csv_datasource::type() const
mapnik::box2d<double> csv_datasource::envelope() const mapnik::box2d<double> csv_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }
boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const
{ {
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result; boost::optional<mapnik::datasource::geometry_t> result;
int multi_type = 0; int multi_type = 0;
unsigned num_features = features_.size(); unsigned num_features = features_.size();
@ -920,15 +905,11 @@ boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_typ
mapnik::layer_descriptor csv_datasource::get_descriptor() const mapnik::layer_descriptor csv_datasource::get_descriptor() const
{ {
if (!is_bound_) bind();
return desc_; return desc_;
} }
mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
{ {
if (!is_bound_) bind();
const std::set<std::string>& attribute_names = q.property_names(); const std::set<std::string>& attribute_names = q.property_names();
std::set<std::string>::const_iterator pos = attribute_names.begin(); std::set<std::string>::const_iterator pos = attribute_names.begin();
while (pos != attribute_names.end()) while (pos != attribute_names.end())
@ -958,7 +939,5 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
throw mapnik::datasource_exception("CSV Plugin: features_at_point is not supported yet"); throw mapnik::datasource_exception("CSV Plugin: features_at_point is not supported yet");
} }

View file

@ -42,7 +42,7 @@
class csv_datasource : public mapnik::datasource class csv_datasource : public mapnik::datasource
{ {
public: public:
csv_datasource(mapnik::parameters const& params, bool bind=true); csv_datasource(mapnik::parameters const& params);
virtual ~csv_datasource (); virtual ~csv_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -51,31 +51,30 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
template <typename T> template <typename T>
void parse_csv(T & stream, void parse_csv(T & stream,
std::string const& escape, std::string const& escape,
std::string const& separator, std::string const& separator,
std::string const& quote) const; std::string const& quote);
private: private:
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
mutable std::string filename_; std::string filename_;
mutable std::string inline_string_; std::string inline_string_;
mutable unsigned file_length_; unsigned file_length_;
mutable int row_limit_; int row_limit_;
mutable std::vector<mapnik::feature_ptr> features_; std::vector<mapnik::feature_ptr> features_;
mutable std::string escape_; std::string escape_;
mutable std::string separator_; std::string separator_;
mutable std::string quote_; std::string quote_;
mutable std::vector<std::string> headers_; std::vector<std::string> headers_;
mutable std::string manual_headers_; std::string manual_headers_;
mutable bool strict_; bool strict_;
mutable bool quiet_; bool quiet_;
mutable double filesize_max_; double filesize_max_;
mutable mapnik::context_ptr ctx_; mapnik::context_ptr ctx_;
}; };
#endif // MAPNIK_CSV_DATASOURCE_HPP #endif // MAPNIK_CSV_DATASOURCE_HPP

View file

@ -73,20 +73,24 @@ inline GDALDataset* gdal_datasource::open_dataset() const
} }
gdal_datasource::gdal_datasource(parameters const& params, bool bind) gdal_datasource::gdal_datasource(parameters const& params)
: datasource(params), : datasource(params),
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"))
{ {
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing..."; MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing...";
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::init");
#endif
GDALAllRegister(); GDALAllRegister();
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"); if (! file) throw datasource_exception("missing <file> parameter");
boost::optional<std::string> base = params_.get<std::string>("base"); boost::optional<std::string> base = params.get<std::string>("base");
if (base) if (base)
{ {
dataset_name_ = *base + "/" + *file; dataset_name_ = *base + "/" + *file;
@ -96,22 +100,8 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
dataset_name_ = *file; dataset_name_ = *file;
} }
if (bind) shared_dataset_ = *params.get<mapnik::boolean>("shared", false);
{ band_ = *params.get<int>("band", -1);
this->bind();
}
}
void gdal_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::bind");
#endif
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
band_ = *params_.get<int>("band", -1);
GDALDataset *dataset = open_dataset(); GDALDataset *dataset = open_dataset();
@ -121,7 +111,7 @@ void gdal_datasource::bind() const
double tr[6]; double tr[6];
bool bbox_override = false; bool bbox_override = false;
boost::optional<std::string> bbox_s = params_.get<std::string>("extent"); boost::optional<std::string> bbox_s = params.get<std::string>("extent");
if (bbox_s) if (bbox_s)
{ {
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: BBox Parameter=" << *bbox_s; MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: BBox Parameter=" << *bbox_s;
@ -188,7 +178,6 @@ void gdal_datasource::bind() const
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_;
is_bound_ = true;
} }
gdal_datasource::~gdal_datasource() gdal_datasource::~gdal_datasource()
@ -207,8 +196,6 @@ const char * gdal_datasource::name()
box2d<double> gdal_datasource::envelope() const box2d<double> gdal_datasource::envelope() const
{ {
if (! is_bound_) bind();
return extent_; return extent_;
} }
@ -224,8 +211,6 @@ layer_descriptor gdal_datasource::get_descriptor() const
featureset_ptr gdal_datasource::features(query const& q) const featureset_ptr gdal_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features"); mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features");
#endif #endif
@ -248,8 +233,6 @@ featureset_ptr gdal_datasource::features(query const& q) const
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr gdal_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point");
#endif #endif

View file

@ -45,7 +45,7 @@
class gdal_datasource : public mapnik::datasource class gdal_datasource : public mapnik::datasource
{ {
public: public:
gdal_datasource(mapnik::parameters const& params, bool bind = true); gdal_datasource(mapnik::parameters const& params);
virtual ~gdal_datasource(); virtual ~gdal_datasource();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -54,19 +54,18 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
GDALDataset* open_dataset() const; GDALDataset* open_dataset() const;
mutable mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string dataset_name_; std::string dataset_name_;
mutable int band_; int band_;
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable unsigned width_; unsigned width_;
mutable unsigned height_; unsigned height_;
mutable double dx_; double dx_;
mutable double dy_; double dy_;
mutable int nbands_; int nbands_;
mutable bool shared_dataset_; bool shared_dataset_;
double filter_factor_; double filter_factor_;
boost::optional<double> nodata_value_; boost::optional<double> nodata_value_;
}; };

View file

@ -49,24 +49,6 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(geojson_datasource) DATASOURCE_PLUGIN(geojson_datasource)
geojson_datasource::geojson_datasource(parameters const& params, bool bind)
: datasource(params),
type_(datasource::Vector),
desc_(*params_.get<std::string>("type"),
*params_.get<std::string>("encoding","utf-8")),
file_(*params_.get<std::string>("file","")),
extent_(),
tr_(new mapnik::transcoder(*params_.get<std::string>("encoding","utf-8"))),
features_(),
tree_(16,1)
{
if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing <file> parameter");
if (bind)
{
this->bind();
}
}
struct attr_value_converter : public boost::static_visitor<mapnik::eAttributeType> struct attr_value_converter : public boost::static_visitor<mapnik::eAttributeType>
{ {
mapnik::eAttributeType operator() (int /*val*/) const mapnik::eAttributeType operator() (int /*val*/) const
@ -105,9 +87,18 @@ struct attr_value_converter : public boost::static_visitor<mapnik::eAttributeTyp
} }
}; };
void geojson_datasource::bind() const geojson_datasource::geojson_datasource(parameters const& params)
: datasource(params),
type_(datasource::Vector),
desc_(*params.get<std::string>("type"),
*params.get<std::string>("encoding","utf-8")),
file_(*params.get<std::string>("file","")),
extent_(),
tr_(new mapnik::transcoder(*params.get<std::string>("encoding","utf-8"))),
features_(),
tree_(16,1)
{ {
if (is_bound_) return; if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing <file> parameter");
typedef std::istreambuf_iterator<char> base_iterator_type; typedef std::istreambuf_iterator<char> base_iterator_type;
@ -149,7 +140,6 @@ void geojson_datasource::bind() const
} }
tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())), count++); tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())), count++);
} }
is_bound_ = true;
} }
geojson_datasource::~geojson_datasource() { } geojson_datasource::~geojson_datasource() { }
@ -188,21 +178,16 @@ mapnik::datasource::datasource_t geojson_datasource::type() const
mapnik::box2d<double> geojson_datasource::envelope() const mapnik::box2d<double> geojson_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }
mapnik::layer_descriptor geojson_datasource::get_descriptor() const mapnik::layer_descriptor geojson_datasource::get_descriptor() const
{ {
if (!is_bound_) bind();
return desc_; return desc_;
} }
mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const
{ {
if (!is_bound_) bind();
// if the query box intersects our world extent then query for features // if the query box intersects our world extent then query for features
mapnik::box2d<double> const& b = q.get_bbox(); mapnik::box2d<double> const& b = q.get_bbox();
if (extent_.intersects(b)) if (extent_.intersects(b))
@ -218,7 +203,6 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
// FIXME // FIXME
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
throw mapnik::datasource_exception("GeoJSON Plugin: features_at_point is not supported yet"); throw mapnik::datasource_exception("GeoJSON Plugin: features_at_point is not supported yet");
return mapnik::featureset_ptr(); return mapnik::featureset_ptr();
} }

View file

@ -55,7 +55,7 @@ public:
typedef boost::geometry::index::rtree<box_type,std::size_t> spatial_index_type; typedef boost::geometry::index::rtree<box_type,std::size_t> spatial_index_type;
// constructor // constructor
geojson_datasource(mapnik::parameters const& params, bool bind=true); geojson_datasource(mapnik::parameters const& params);
virtual ~geojson_datasource (); virtual ~geojson_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -64,16 +64,15 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
void bind() const;
private: private:
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable std::map<std::string, mapnik::parameters> statistics_; std::map<std::string, mapnik::parameters> statistics_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable std::string file_; std::string file_;
mutable mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
boost::shared_ptr<mapnik::transcoder> tr_; boost::shared_ptr<mapnik::transcoder> tr_;
mutable std::vector<mapnik::feature_ptr> features_; std::vector<mapnik::feature_ptr> features_;
mutable spatial_index_type tree_; spatial_index_type tree_;
mutable std::deque<std::size_t> index_array_; mutable std::deque<std::size_t> index_array_;
}; };

View file

@ -85,7 +85,7 @@ void geos_error(const char* format, ...)
} }
geos_datasource::geos_datasource(parameters const& params, bool bind) geos_datasource::geos_datasource(parameters const& params)
: datasource(params), : datasource(params),
extent_(), extent_(),
extent_initialized_(false), extent_initialized_(false),
@ -99,42 +99,22 @@ geos_datasource::geos_datasource(parameters const& params, bool bind)
if (! geometry) throw datasource_exception("missing <wkt> parameter"); if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry; geometry_string_ = *geometry;
boost::optional<std::string> ext = params_.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext); if (ext) extent_initialized_ = extent_.from_string(*ext);
boost::optional<int> id = params_.get<int>("gid"); boost::optional<int> id = params.get<int>("gid");
if (id) geometry_id_ = *id; if (id) geometry_id_ = *id;
boost::optional<std::string> gdata = params_.get<std::string>("field_data"); boost::optional<std::string> gdata = params.get<std::string>("field_data");
if (gdata) geometry_data_ = *gdata; if (gdata) geometry_data_ = *gdata;
boost::optional<std::string> gdata_name = params_.get<std::string>("field_name"); boost::optional<std::string> gdata_name = params.get<std::string>("field_name");
if (gdata_name) geometry_data_name_ = *gdata_name; if (gdata_name) geometry_data_name_ = *gdata_name;
desc_.add_descriptor(attribute_descriptor(geometry_data_name_, mapnik::String)); desc_.add_descriptor(attribute_descriptor(geometry_data_name_, mapnik::String));
if (bind)
{
this->bind();
}
}
geos_datasource::~geos_datasource()
{
if (is_bound_)
{
geometry_.set_feature(0);
finishGEOS();
}
}
void geos_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::bind"); mapnik::progress_timer __stats__(std::clog, "geos_datasource::init");
#endif #endif
// open geos driver // open geos driver
@ -151,7 +131,7 @@ void geos_datasource::bind() const
if (! extent_initialized_) if (! extent_initialized_)
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "geos_datasource::bind(initialize_extent)"); mapnik::progress_timer __stats2__(std::clog, "geos_datasource::init(initialize_extent)");
#endif #endif
MAPNIK_LOG_DEBUG(geos) << "geos_datasource: Initializing extent from geometry"; MAPNIK_LOG_DEBUG(geos) << "geos_datasource: Initializing extent from geometry";
@ -222,9 +202,18 @@ void geos_datasource::bind() const
throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry"); throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry");
} }
is_bound_ = true;
} }
geos_datasource::~geos_datasource()
{
{
geometry_.set_feature(0);
finishGEOS();
}
}
const char * geos_datasource::name() const char * geos_datasource::name()
{ {
return "geos"; return "geos";
@ -237,14 +226,11 @@ mapnik::datasource::datasource_t geos_datasource::type() const
box2d<double> geos_datasource::envelope() const box2d<double> geos_datasource::envelope() const
{ {
if (! is_bound_) bind();
return extent_; return extent_;
} }
boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_type() const
{ {
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result; boost::optional<mapnik::datasource::geometry_t> result;
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
@ -280,15 +266,11 @@ boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_ty
layer_descriptor geos_datasource::get_descriptor() const layer_descriptor geos_datasource::get_descriptor() const
{ {
if (! is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr geos_datasource::features(query const& q) const featureset_ptr geos_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::features"); mapnik::progress_timer __stats__(std::clog, "geos_datasource::features");
#endif #endif
@ -316,8 +298,6 @@ featureset_ptr geos_datasource::features(query const& q) const
featureset_ptr geos_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr geos_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "geos_datasource::features_at_point");
#endif #endif

View file

@ -45,7 +45,7 @@
class geos_datasource : public mapnik::datasource class geos_datasource : public mapnik::datasource
{ {
public: public:
geos_datasource(mapnik::parameters const& params, bool bind = true); geos_datasource(mapnik::parameters const& params);
virtual ~geos_datasource (); virtual ~geos_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -54,17 +54,17 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
mutable mapnik::box2d<double> extent_; void init(mapnik::parameters const& params);
mutable bool extent_initialized_; mapnik::box2d<double> extent_;
bool extent_initialized_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable geos_feature_ptr geometry_; mutable geos_feature_ptr geometry_;
mutable std::string geometry_data_; std::string geometry_data_;
mutable std::string geometry_data_name_; std::string geometry_data_name_;
mutable int geometry_id_; int geometry_id_;
std::string geometry_string_; std::string geometry_string_;
}; };

View file

@ -67,7 +67,7 @@ boost::mutex knd_list_mutex;
std::list<kismet_network_data> knd_list; std::list<kismet_network_data> knd_list;
const unsigned int queue_size = 20; const unsigned int queue_size = 20;
kismet_datasource::kismet_datasource(parameters const& params, bool bind) kismet_datasource::kismet_datasource(parameters const& params)
: datasource(params), : datasource(params),
extent_(), extent_(),
extent_initialized_(false), extent_initialized_(false),
@ -75,7 +75,7 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"), srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
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"))
{ {
boost::optional<std::string> host = params_.get<std::string>("host"); boost::optional<std::string> host = params.get<std::string>("host");
if (host) if (host)
{ {
host_ = *host; host_ = *host;
@ -85,37 +85,25 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
throw datasource_exception("Kismet Plugin: missing <host> parameter"); throw datasource_exception("Kismet Plugin: missing <host> parameter");
} }
boost::optional<unsigned int> port = params_.get<unsigned int>("port", 2501); boost::optional<unsigned int> port = params.get<unsigned int>("port", 2501);
if (port) if (port)
{ {
port_ = *port; port_ = *port;
} }
boost::optional<std::string> srs = params_.get<std::string>("srs"); boost::optional<std::string> srs = params.get<std::string>("srs");
if (srs) if (srs)
{ {
srs_ = *srs; srs_ = *srs;
} }
boost::optional<std::string> ext = params_.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext) if (ext)
{ {
extent_initialized_ = extent_.from_string(*ext); extent_initialized_ = extent_.from_string(*ext);
} }
kismet_thread.reset(new boost::thread(boost::bind(&kismet_datasource::run, this, host_, port_))); kismet_thread.reset(new boost::thread(boost::bind(&kismet_datasource::run, this, host_, port_)));
if (bind)
{
this->bind();
}
}
void kismet_datasource::bind() const
{
if (is_bound_) return;
is_bound_ = true;
} }
kismet_datasource::~kismet_datasource() kismet_datasource::~kismet_datasource()
@ -134,7 +122,6 @@ mapnik::datasource::datasource_t kismet_datasource::type() const
box2d<double> kismet_datasource::envelope() const box2d<double> kismet_datasource::envelope() const
{ {
if (! is_bound_) bind();
return extent_; return extent_;
} }
@ -150,8 +137,6 @@ layer_descriptor kismet_datasource::get_descriptor() const
featureset_ptr kismet_datasource::features(query const& q) const featureset_ptr kismet_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features()"; MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features()";
// TODO: use box2d to filter bbox before adding to featureset_ptr // TODO: use box2d to filter bbox before adding to featureset_ptr
@ -168,8 +153,6 @@ featureset_ptr kismet_datasource::features(query const& q) const
featureset_ptr kismet_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr kismet_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_) bind();
MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features_at_point()"; MAPNIK_LOG_DEBUG(kismet) << "kismet_datasource::features_at_point()";
return featureset_ptr(); return featureset_ptr();

View file

@ -47,7 +47,7 @@
class kismet_datasource : public mapnik::datasource class kismet_datasource : public mapnik::datasource
{ {
public: public:
kismet_datasource(mapnik::parameters const& params, bool bind = true); kismet_datasource(mapnik::parameters const& params);
virtual ~kismet_datasource (); virtual ~kismet_datasource ();
datasource::datasource_t type() const; datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -56,7 +56,6 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
void run (std::string const& host, const unsigned int port); void run (std::string const& host, const unsigned int port);
@ -67,7 +66,7 @@ private:
unsigned int port_; unsigned int port_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
std::string srs_; std::string srs_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
boost::shared_ptr<boost::thread> kismet_thread; boost::shared_ptr<boost::thread> kismet_thread;
}; };

View file

@ -68,25 +68,29 @@ const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA";
DATASOURCE_PLUGIN(occi_datasource) DATASOURCE_PLUGIN(occi_datasource)
occi_datasource::occi_datasource(parameters const& params, bool bind) occi_datasource::occi_datasource(parameters const& params)
: datasource (params), : datasource (params),
type_(datasource::Vector), type_(datasource::Vector),
fields_(*params_.get<std::string>("fields", "*")), fields_(*params.get<std::string>("fields", "*")),
geometry_field_(*params_.get<std::string>("geometry_field", "")), geometry_field_(*params.get<std::string>("geometry_field", "")),
srid_initialized_(false), srid_initialized_(false),
extent_initialized_(false), extent_initialized_(false),
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")),
use_wkb_(*params_.get<mapnik::boolean>("use_wkb", false)), use_wkb_(*params.get<mapnik::boolean>("use_wkb", false)),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params.get<int>("row_limit", 0)),
row_prefetch_(*params_.get<int>("row_prefetch", 100)), row_prefetch_(*params.get<int>("row_prefetch", 100)),
pool_(0), pool_(0),
conn_(0) conn_(0)
{ {
if (! params_.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified"); #ifdef MAPNIK_STATS
if (! params_.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified"); mapnik::progress_timer __stats__(std::clog, "occi_datasource::init");
if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified"); #endif
boost::optional<std::string> table = params_.get<std::string>("table"); if (! params.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified");
if (! params.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified");
if (! params.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified");
boost::optional<std::string> table = params.get<std::string>("table");
if (! table) if (! table)
{ {
throw datasource_exception("OCCI Plugin: no <table> parameter specified"); throw datasource_exception("OCCI Plugin: no <table> parameter specified");
@ -95,57 +99,20 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
{ {
table_ = *table; table_ = *table;
} }
estimate_extent_ = *params.get<mapnik::boolean>("estimate_extent",false);
use_spatial_index_ = *params.get<mapnik::boolean>("use_spatial_index",true);
use_connection_pool_ = *params.get<mapnik::boolean>("use_connection_pool",true);
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true); boost::optional<std::string> ext = params.get<std::string>("extent");
use_connection_pool_ = *params_.get<mapnik::boolean>("use_connection_pool",true);
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext); if (ext) extent_initialized_ = extent_.from_string(*ext);
boost::optional<int> srid = params_.get<int>("srid"); boost::optional<int> srid = params.get<int>("srid");
if (srid) if (srid)
{ {
srid_ = *srid; srid_ = *srid;
srid_initialized_ = true; srid_initialized_ = true;
} }
if (bind)
{
this->bind();
}
}
occi_datasource::~occi_datasource()
{
if (is_bound_)
{
Environment* env = occi_environment::get_environment();
if (use_connection_pool_)
{
if (pool_ != 0)
{
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
}
}
else
{
if (conn_ != 0)
{
env->terminateConnection(conn_);
}
}
}
}
void occi_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::bind");
#endif
// connect to environment // connect to environment
if (use_connection_pool_) if (use_connection_pool_)
{ {
@ -154,11 +121,11 @@ void occi_datasource::bind() const
Environment* env = occi_environment::get_environment(); Environment* env = occi_environment::get_environment();
pool_ = env->createStatelessConnectionPool( pool_ = env->createStatelessConnectionPool(
*params_.get<std::string>("user"), *params.get<std::string>("user"),
*params_.get<std::string>("password"), *params.get<std::string>("password"),
*params_.get<std::string>("host"), *params.get<std::string>("host"),
*params_.get<int>("max_size", 5), *params.get<int>("max_size", 5),
*params_.get<int>("initial_size", 1), *params.get<int>("initial_size", 1),
1, 1,
StatelessConnectionPool::HOMOGENEOUS); StatelessConnectionPool::HOMOGENEOUS);
} }
@ -174,9 +141,9 @@ void occi_datasource::bind() const
Environment* env = occi_environment::get_environment(); Environment* env = occi_environment::get_environment();
conn_ = env->createConnection( conn_ = env->createConnection(
*params_.get<std::string>("user"), *params.get<std::string>("user"),
*params_.get<std::string>("password"), *params.get<std::string>("password"),
*params_.get<std::string>("host")); *params.get<std::string>("host"));
} }
catch (SQLException& ex) catch (SQLException& ex)
{ {
@ -348,8 +315,28 @@ void occi_datasource::bind() const
throw datasource_exception(ex.getMessage()); throw datasource_exception(ex.getMessage());
} }
} }
}
is_bound_ = true; occi_datasource::~occi_datasource()
{
{
Environment* env = occi_environment::get_environment();
if (use_connection_pool_)
{
if (pool_ != 0)
{
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
}
}
else
{
if (conn_ != 0)
{
env->terminateConnection(conn_);
}
}
}
} }
const char * occi_datasource::name() const char * occi_datasource::name()
@ -365,14 +352,11 @@ mapnik::datasource::datasource_t occi_datasource::type() const
box2d<double> occi_datasource::envelope() const box2d<double> occi_datasource::envelope() const
{ {
if (extent_initialized_) return extent_; if (extent_initialized_) return extent_;
if (! is_bound_) bind();
double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0; double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0;
boost::optional<mapnik::boolean> estimate_extent =
params_.get<mapnik::boolean>("estimate_extent",false);
if (estimate_extent && *estimate_extent) if (estimate_extent_)
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::envelope(estimate_extent)"); mapnik::progress_timer __stats__(std::clog, "occi_datasource::envelope(estimate_extent)");
@ -487,22 +471,16 @@ box2d<double> occi_datasource::envelope() const
boost::optional<mapnik::datasource::geometry_t> occi_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> occi_datasource::get_geometry_type() const
{ {
// FIXME
//if (! is_bound_) bind();
return boost::optional<mapnik::datasource::geometry_t>(); return boost::optional<mapnik::datasource::geometry_t>();
} }
layer_descriptor occi_datasource::get_descriptor() const layer_descriptor occi_datasource::get_descriptor() const
{ {
if (! is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr occi_datasource::features(query const& q) const featureset_ptr occi_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::features"); mapnik::progress_timer __stats__(std::clog, "occi_datasource::features");
#endif #endif
@ -592,8 +570,6 @@ featureset_ptr occi_datasource::features(query const& q) const
featureset_ptr occi_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr occi_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "occi_datasource::features_at_point");
#endif #endif

View file

@ -46,7 +46,7 @@
class occi_datasource : public mapnik::datasource class occi_datasource : public mapnik::datasource
{ {
public: public:
occi_datasource(mapnik::parameters const& params, bool bind = true); occi_datasource(mapnik::parameters const& params);
virtual ~occi_datasource (); virtual ~occi_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -55,28 +55,28 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
static const std::string METADATA_TABLE; static const std::string METADATA_TABLE;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable std::string table_; std::string table_;
mutable std::string table_name_; std::string table_name_;
mutable std::string fields_; std::string fields_;
mutable std::string geometry_field_; std::string geometry_field_;
mutable int srid_; int srid_;
mutable bool srid_initialized_; bool srid_initialized_;
mutable bool extent_initialized_; mutable bool extent_initialized_;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable bool use_wkb_; bool use_wkb_;
int row_limit_; int row_limit_;
int row_prefetch_; int row_prefetch_;
mutable oracle::occi::StatelessConnectionPool* pool_; oracle::occi::StatelessConnectionPool* pool_;
mutable oracle::occi::Connection* conn_; oracle::occi::Connection* conn_;
bool use_connection_pool_; bool use_connection_pool_;
bool use_spatial_index_; bool use_spatial_index_;
bool estimate_extent_;
}; };
#endif // OCCI_DATASOURCE_HPP #endif // OCCI_DATASOURCE_HPP

View file

@ -57,13 +57,32 @@ using mapnik::filter_in_box;
using mapnik::filter_at_point; using mapnik::filter_at_point;
ogr_datasource::ogr_datasource(parameters const& params, bool bind) ogr_datasource::ogr_datasource(parameters const& params)
: datasource(params), : datasource(params),
extent_(), extent_(),
type_(datasource::Vector), type_(datasource::Vector),
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)
{ {
init(params);
}
ogr_datasource::~ogr_datasource()
{
// free layer before destroying the datasource
layer_.free_layer();
OGRDataSource::DestroyDataSource (dataset_);
}
void ogr_datasource::init(mapnik::parameters const& params)
{
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::init");
#endif
// initialize ogr formats
OGRRegisterAll();
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
boost::optional<std::string> string = params.get<std::string>("string"); boost::optional<std::string> string = params.get<std::string>("string");
if (! file && ! string) if (! file && ! string)
@ -88,35 +107,7 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
} }
} }
if (bind) std::string driver = *params.get<std::string>("driver","");
{
this->bind();
}
}
ogr_datasource::~ogr_datasource()
{
if (is_bound_)
{
// free layer before destroying the datasource
layer_.free_layer();
OGRDataSource::DestroyDataSource (dataset_);
}
}
void ogr_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::bind");
#endif
// initialize ogr formats
OGRRegisterAll();
std::string driver = *params_.get<std::string>("driver","");
if (! driver.empty()) if (! driver.empty())
{ {
@ -147,9 +138,9 @@ void ogr_datasource::bind() const
} }
// initialize layer // initialize layer
boost::optional<std::string> layer_by_name = params_.get<std::string>("layer"); boost::optional<std::string> layer_by_name = params.get<std::string>("layer");
boost::optional<unsigned> layer_by_index = params_.get<unsigned>("layer_by_index"); boost::optional<unsigned> layer_by_index = params.get<unsigned>("layer_by_index");
boost::optional<std::string> layer_by_sql = params_.get<std::string>("layer_by_sql"); boost::optional<std::string> layer_by_sql = params.get<std::string>("layer_by_sql");
int passed_parameters = 0; int passed_parameters = 0;
passed_parameters += layer_by_name ? 1 : 0; passed_parameters += layer_by_name ? 1 : 0;
@ -185,7 +176,7 @@ void ogr_datasource::bind() const
else if (layer_by_sql) else if (layer_by_sql)
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats_sql__(std::clog, "ogr_datasource::bind(layer_by_sql)"); mapnik::progress_timer __stats_sql__(std::clog, "ogr_datasource::init(layer_by_sql)");
#endif #endif
layer_.layer_by_sql(dataset_, *layer_by_sql); layer_.layer_by_sql(dataset_, *layer_by_sql);
@ -278,7 +269,7 @@ void ogr_datasource::bind() const
#endif #endif
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::bind(get_column_description)"); mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::init(get_column_description)");
#endif #endif
// deal with attributes descriptions // deal with attributes descriptions
@ -328,8 +319,6 @@ void ogr_datasource::bind() const
} }
} }
} }
is_bound_ = true;
} }
const char * ogr_datasource::name() const char * ogr_datasource::name()
@ -344,7 +333,6 @@ mapnik::datasource::datasource_t ogr_datasource::type() const
box2d<double> ogr_datasource::envelope() const box2d<double> ogr_datasource::envelope() const
{ {
if (! is_bound_) bind();
return extent_; return extent_;
} }
@ -432,7 +420,6 @@ boost::optional<mapnik::datasource::geometry_t> ogr_datasource::get_geometry_typ
layer_descriptor ogr_datasource::get_descriptor() const layer_descriptor ogr_datasource::get_descriptor() const
{ {
if (! is_bound_) bind();
return desc_; return desc_;
} }
@ -475,8 +462,6 @@ void validate_attribute_names(query const& q, std::vector<attribute_descriptor>
featureset_ptr ogr_datasource::features(query const& q) const featureset_ptr ogr_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features"); mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features");
#endif #endif
@ -522,8 +507,6 @@ featureset_ptr ogr_datasource::features(query const& q) const
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features_at_point");
#endif #endif

View file

@ -47,7 +47,7 @@
class ogr_datasource : public mapnik::datasource class ogr_datasource : public mapnik::datasource
{ {
public: public:
ogr_datasource(mapnik::parameters const& params, bool bind=true); ogr_datasource(mapnik::parameters const& params);
virtual ~ogr_datasource (); virtual ~ogr_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -56,18 +56,18 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
mutable mapnik::box2d<double> extent_; void init(mapnik::parameters const& params);
mapnik::box2d<double> extent_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
std::string dataset_name_; std::string dataset_name_;
mutable std::string index_name_; std::string index_name_;
mutable OGRDataSource* dataset_; OGRDataSource* dataset_;
mutable ogr_layer_ptr layer_; ogr_layer_ptr layer_;
mutable std::string layer_name_; std::string layer_name_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable bool indexed_; bool indexed_;
}; };
#endif // OGR_DATASOURCE_HPP #endif // OGR_DATASOURCE_HPP

View file

@ -49,28 +49,17 @@ using mapnik::attribute_descriptor;
DATASOURCE_PLUGIN(osm_datasource) DATASOURCE_PLUGIN(osm_datasource)
osm_datasource::osm_datasource(const parameters& params, bool bind) osm_datasource::osm_datasource(const parameters& params)
: datasource (params), : datasource (params),
extent_(), extent_(),
type_(datasource::Vector), type_(datasource::Vector),
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"))
{ {
if (bind)
{
this->bind();
}
}
void osm_datasource::bind() const
{
if (is_bound_) return;
osm_data_ = NULL; osm_data_ = NULL;
std::string osm_filename = *params_.get<std::string>("file", ""); std::string osm_filename = *params.get<std::string>("file", "");
std::string parser = *params_.get<std::string>("parser", "libxml2"); std::string parser = *params.get<std::string>("parser", "libxml2");
std::string url = *params_.get<std::string>("url", ""); std::string url = *params.get<std::string>("url", "");
std::string bbox = *params_.get<std::string>("bbox", ""); std::string bbox = *params.get<std::string>("bbox", "");
// load the data // load the data
if (url != "" && bbox != "") if (url != "" && bbox != "")
@ -118,7 +107,6 @@ void osm_datasource::bind() const
// Get the bounds of the data and set extent_ accordingly // Get the bounds of the data and set extent_ accordingly
bounds b = osm_data_->get_bounds(); bounds b = osm_data_->get_bounds();
extent_ = box2d<double>(b.w, b.s, b.e, b.n); extent_ = box2d<double>(b.w, b.s, b.e, b.n);
is_bound_ = true;
} }
osm_datasource::~osm_datasource() osm_datasource::~osm_datasource()
@ -144,8 +132,6 @@ layer_descriptor osm_datasource::get_descriptor() const
featureset_ptr osm_datasource::features(const query& q) const featureset_ptr osm_datasource::features(const query& q) const
{ {
if (!is_bound_) bind();
filter_in_box filter(q.get_bbox()); filter_in_box filter(q.get_bbox());
// so we need to filter osm features by bbox here... // so we need to filter osm features by bbox here...
@ -157,8 +143,6 @@ featureset_ptr osm_datasource::features(const query& q) const
featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
filter_at_point filter(pt); filter_at_point filter(pt);
// collect all attribute names // collect all attribute names
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors(); std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
@ -180,12 +164,10 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt, double tol)
box2d<double> osm_datasource::envelope() const box2d<double> osm_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }
boost::optional<mapnik::datasource::geometry_t> osm_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> osm_datasource::get_geometry_type() const
{ {
if (! is_bound_) bind();
return boost::optional<mapnik::datasource::geometry_t>(mapnik::datasource::Collection); return boost::optional<mapnik::datasource::geometry_t>(mapnik::datasource::Collection);
} }

View file

@ -53,7 +53,7 @@ using mapnik::box2d;
class osm_datasource : public datasource class osm_datasource : public datasource
{ {
public: public:
osm_datasource(const parameters& params, bool bind = true); osm_datasource(const parameters& params);
virtual ~osm_datasource(); virtual ~osm_datasource();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -62,13 +62,12 @@ public:
box2d<double> envelope() const; box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
void bind() const;
private: private:
mutable box2d<double> extent_; box2d<double> extent_;
mutable osm_dataset* osm_data_; osm_dataset* osm_data_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable layer_descriptor desc_; layer_descriptor desc_;
}; };
#endif // OSM_DATASOURCE_HPP #endif // OSM_DATASOURCE_HPP

View file

@ -55,20 +55,20 @@ using boost::shared_ptr;
using mapnik::PoolGuard; using mapnik::PoolGuard;
using mapnik::attribute_descriptor; using mapnik::attribute_descriptor;
postgis_datasource::postgis_datasource(parameters const& params, bool bind) postgis_datasource::postgis_datasource(parameters const& params)
: datasource(params), : datasource(params),
table_(*params_.get<std::string>("table", "")), table_(*params.get<std::string>("table", "")),
schema_(""), schema_(""),
geometry_table_(*params_.get<std::string>("geometry_table", "")), geometry_table_(*params.get<std::string>("geometry_table", "")),
geometry_field_(*params_.get<std::string>("geometry_field", "")), geometry_field_(*params.get<std::string>("geometry_field", "")),
key_field_(*params_.get<std::string>("key_field", "")), key_field_(*params.get<std::string>("key_field", "")),
cursor_fetch_size_(*params_.get<int>("cursor_size", 0)), cursor_fetch_size_(*params.get<int>("cursor_size", 0)),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params.get<int>("row_limit", 0)),
type_(datasource::Vector), type_(datasource::Vector),
srid_(*params_.get<int>("srid", 0)), srid_(*params.get<int>("srid", 0)),
extent_initialized_(false), extent_initialized_(false),
simplify_geometries_(false), simplify_geometries_(false),
desc_(*params_.get<std::string>("type"), "utf-8"), desc_(*params.get<std::string>("type"), "utf-8"),
creator_(params.get<std::string>("host"), creator_(params.get<std::string>("host"),
params.get<std::string>("port"), params.get<std::string>("port"),
params.get<std::string>("dbname"), params.get<std::string>("dbname"),
@ -79,45 +79,32 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
scale_denom_token_("!scale_denominator!"), scale_denom_token_("!scale_denominator!"),
pixel_width_token_("!pixel_width!"), pixel_width_token_("!pixel_width!"),
pixel_height_token_("!pixel_height!"), pixel_height_token_("!pixel_height!"),
persist_connection_(*params_.get<mapnik::boolean>("persist_connection", true)), persist_connection_(*params.get<mapnik::boolean>("persist_connection", true)),
extent_from_subquery_(*params_.get<mapnik::boolean>("extent_from_subquery", false)), extent_from_subquery_(*params.get<mapnik::boolean>("extent_from_subquery", false)),
// params below are for testing purposes only (will likely be removed at any time) // params below are for testing purposes only (will likely be removed at any time)
intersect_min_scale_(*params_.get<int>("intersect_min_scale", 0)), intersect_min_scale_(*params.get<int>("intersect_min_scale", 0)),
intersect_max_scale_(*params_.get<int>("intersect_max_scale", 0)) intersect_max_scale_(*params.get<int>("intersect_max_scale", 0))
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::init");
#endif
if (table_.empty()) if (table_.empty())
{ {
throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter"); throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
} }
boost::optional<std::string> ext = params_.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext && !ext->empty()) if (ext && !ext->empty())
{ {
extent_initialized_ = extent_.from_string(*ext); extent_initialized_ = extent_.from_string(*ext);
} }
if (bind) boost::optional<int> initial_size = params.get<int>("initial_size", 1);
{ boost::optional<int> max_size = params.get<int>("max_size", 10);
this->bind(); boost::optional<mapnik::boolean> autodetect_key_field = params.get<mapnik::boolean>("autodetect_key_field", false);
} boost::optional<mapnik::boolean> estimate_extent = params.get<mapnik::boolean>("estimate_extent", false);
} estimate_extent_ = estimate_extent && *estimate_extent;
boost::optional<mapnik::boolean> simplify_opt = params.get<mapnik::boolean>("simplify_geometries", false);
void postgis_datasource::bind() const
{
if (is_bound_)
{
return;
}
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::bind");
#endif
boost::optional<int> initial_size = params_.get<int>("initial_size", 1);
boost::optional<int> max_size = params_.get<int>("max_size", 10);
boost::optional<mapnik::boolean> autodetect_key_field = params_.get<mapnik::boolean>("autodetect_key_field", false);
boost::optional<mapnik::boolean> simplify_opt = params_.get<mapnik::boolean>("simplify_geometries", false);
simplify_geometries_ = simplify_opt && *simplify_opt; simplify_geometries_ = simplify_opt && *simplify_opt;
ConnectionManager::instance().registerPool(creator_, *initial_size, *max_size); ConnectionManager::instance().registerPool(creator_, *initial_size, *max_size);
@ -158,7 +145,7 @@ void postgis_datasource::bind() const
if (geometryColumn_.empty() || srid_ == 0) if (geometryColumn_.empty() || srid_ == 0)
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "postgis_datasource::bind(get_srid_and_geometry_column)"); mapnik::progress_timer __stats2__(std::clog, "postgis_datasource::init(get_srid_and_geometry_column)");
#endif #endif
std::ostringstream s; std::ostringstream s;
@ -424,14 +411,13 @@ void postgis_datasource::bind() const
rs->close(); rs->close();
is_bound_ = true; }
}
} }
} }
postgis_datasource::~postgis_datasource() postgis_datasource::~postgis_datasource()
{ {
if (is_bound_ && ! persist_connection_) if (! persist_connection_)
{ {
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id()); shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool) if (pool)
@ -457,11 +443,6 @@ mapnik::datasource::datasource_t postgis_datasource::type() const
layer_descriptor postgis_datasource::get_descriptor() const layer_descriptor postgis_datasource::get_descriptor() const
{ {
if (! is_bound_)
{
bind();
}
return desc_; return desc_;
} }
@ -603,11 +584,6 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
featureset_ptr postgis_datasource::features(const query& q) const featureset_ptr postgis_datasource::features(const query& q) const
{ {
if (! is_bound_)
{
bind();
}
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features"); mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features");
#endif #endif
@ -725,11 +701,6 @@ featureset_ptr postgis_datasource::features(const query& q) const
featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr postgis_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_)
{
bind();
}
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features_at_point");
#endif #endif
@ -817,11 +788,6 @@ box2d<double> postgis_datasource::envelope() const
return extent_; return extent_;
} }
if (! is_bound_)
{
bind();
}
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id()); shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool) if (pool)
{ {
@ -832,9 +798,6 @@ box2d<double> postgis_datasource::envelope() const
std::ostringstream s; std::ostringstream s;
boost::optional<mapnik::boolean> estimate_extent =
params_.get<mapnik::boolean>("estimate_extent", false);
if (geometryColumn_.empty()) if (geometryColumn_.empty())
{ {
std::ostringstream s_error; std::ostringstream s_error;
@ -852,7 +815,7 @@ box2d<double> postgis_datasource::envelope() const
throw mapnik::datasource_exception("Postgis Plugin: " + s_error.str()); throw mapnik::datasource_exception("Postgis Plugin: " + s_error.str());
} }
if (estimate_extent && *estimate_extent) if (estimate_extent_)
{ {
s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)" s << "SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext)"
<< " FROM (SELECT ST_Estimated_Extent('"; << " FROM (SELECT ST_Estimated_Extent('";
@ -915,11 +878,6 @@ box2d<double> postgis_datasource::envelope() const
boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const
{ {
if (! is_bound_)
{
bind();
}
boost::optional<mapnik::datasource::geometry_t> result; boost::optional<mapnik::datasource::geometry_t> result;
shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id()); shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());

View file

@ -58,7 +58,7 @@ using mapnik::coord2d;
class postgis_datasource : public datasource class postgis_datasource : public datasource
{ {
public: public:
postgis_datasource(const parameters &params, bool bind=true); postgis_datasource(const parameters &params);
~postgis_datasource(); ~postgis_datasource();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -67,7 +67,6 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
void bind() const;
private: private:
std::string sql_bbox(box2d<double> const& env) const; std::string sql_bbox(box2d<double> const& env) const;
@ -84,19 +83,19 @@ private:
const std::string username_; const std::string username_;
const std::string password_; const std::string password_;
const std::string table_; const std::string table_;
mutable std::string schema_; std::string schema_;
mutable std::string geometry_table_; std::string geometry_table_;
const std::string geometry_field_; const std::string geometry_field_;
mutable std::string key_field_; std::string key_field_;
const int cursor_fetch_size_; const int cursor_fetch_size_;
const int row_limit_; const int row_limit_;
mutable std::string geometryColumn_; std::string geometryColumn_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable int srid_; int srid_;
mutable bool extent_initialized_; mutable bool extent_initialized_;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
mutable bool simplify_geometries_; bool simplify_geometries_;
mutable layer_descriptor desc_; layer_descriptor desc_;
ConnectionCreator<Connection> creator_; ConnectionCreator<Connection> creator_;
const std::string bbox_token_; const std::string bbox_token_;
const std::string scale_denom_token_; const std::string scale_denom_token_;
@ -104,6 +103,7 @@ private:
const std::string pixel_height_token_; const std::string pixel_height_token_;
bool persist_connection_; bool persist_connection_;
bool extent_from_subquery_; bool extent_from_subquery_;
bool estimate_extent_;
// params below are for testing purposes only (will likely be removed at any time) // params below are for testing purposes only (will likely be removed at any time)
int intersect_min_scale_; int intersect_min_scale_;
int intersect_max_scale_; int intersect_max_scale_;

View file

@ -75,7 +75,7 @@ feature_ptr postgis_featureset::next()
const char* buf = rs_->getValue(pos); const char* buf = rs_->getValue(pos);
std::string name = rs_->getFieldName(pos); std::string name = rs_->getFieldName(pos);
// validation happens of this type at bind() // validation happens of this type at initialization
int val; int val;
if (oid == 20) if (oid == 20)
{ {

View file

@ -20,53 +20,27 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(python_datasource) DATASOURCE_PLUGIN(python_datasource)
python_datasource::python_datasource(parameters const& params, bool bind) python_datasource::python_datasource(parameters const& params)
: datasource(params), : datasource(params),
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")),
factory_(*params_.get<std::string>("factory", "")) factory_(*params.get<std::string>("factory", ""))
{ {
// extract any remaining parameters as keyword args for the factory // extract any remaining parameters as keyword args for the factory
BOOST_FOREACH(const mapnik::parameters::value_type& kv, params_) BOOST_FOREACH(const mapnik::parameters::value_type& kv, params)
{ {
if((kv.first != "type") && (kv.first != "factory")) if((kv.first != "type") && (kv.first != "factory"))
{ {
kwargs_.insert(std::make_pair(kv.first, *params_.get<std::string>(kv.first))); kwargs_.insert(std::make_pair(kv.first, *params.get<std::string>(kv.first)));
} }
} }
if (bind) // The following methods call into the Python interpreter and hence require, unfortunately, that the GIL be held.
{
this->bind();
}
}
python_datasource::~python_datasource() { }
// This name must match the plugin filename, eg 'python.input'
const char* python_datasource::name_="python";
const char* python_datasource::name()
{
return name_;
}
mapnik::layer_descriptor python_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
// The following methods call into the Python interpreter and hence require, unfortunately, that the GIL be held.
void python_datasource::bind() const
{
using namespace boost; using namespace boost;
if (is_bound_) return; if (factory_.empty())
{
// if no factory callable is defined, bind is a nop throw mapnik::datasource_exception("Python: 'factory' option must be defined");
if (factory_.empty()) return; }
try try
{ {
@ -111,16 +85,27 @@ void python_datasource::bind() const
{ {
throw mapnik::datasource_exception(extractException()); throw mapnik::datasource_exception(extractException());
} }
}
is_bound_ = true; python_datasource::~python_datasource() { }
// This name must match the plugin filename, eg 'python.input'
const char* python_datasource::name_="python";
const char* python_datasource::name()
{
return name_;
}
mapnik::layer_descriptor python_datasource::get_descriptor() const
{
return desc_;
} }
mapnik::datasource::datasource_t python_datasource::type() const mapnik::datasource::datasource_t python_datasource::type() const
{ {
typedef boost::optional<mapnik::datasource::geometry_t> return_type; typedef boost::optional<mapnik::datasource::geometry_t> return_type;
if (!is_bound_) bind();
try try
{ {
ensure_gil lock; ensure_gil lock;
@ -137,8 +122,6 @@ mapnik::datasource::datasource_t python_datasource::type() const
mapnik::box2d<double> python_datasource::envelope() const mapnik::box2d<double> python_datasource::envelope() const
{ {
if (!is_bound_) bind();
try try
{ {
ensure_gil lock; ensure_gil lock;
@ -154,8 +137,6 @@ boost::optional<mapnik::datasource::geometry_t> python_datasource::get_geometry_
{ {
typedef boost::optional<mapnik::datasource::geometry_t> return_type; typedef boost::optional<mapnik::datasource::geometry_t> return_type;
if (!is_bound_) bind();
try try
{ {
ensure_gil lock; ensure_gil lock;
@ -181,8 +162,6 @@ boost::optional<mapnik::datasource::geometry_t> python_datasource::get_geometry_
mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const
{ {
if (!is_bound_) bind();
try try
{ {
// if the query box intersects our world extent then query for features // if the query box intersects our world extent then query for features
@ -209,8 +188,6 @@ mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const
mapnik::featureset_ptr python_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const mapnik::featureset_ptr python_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
try try
{ {
ensure_gil lock; ensure_gil lock;

View file

@ -12,7 +12,7 @@ class python_datasource : public mapnik::datasource
public: public:
// constructor // constructor
// arguments must not change // arguments must not change
python_datasource(mapnik::parameters const& params, bool bind=true); python_datasource(mapnik::parameters const& params);
// destructor // destructor
virtual ~python_datasource (); virtual ~python_datasource ();
@ -41,15 +41,12 @@ public:
// mandatory: return the layer descriptor // mandatory: return the layer descriptor
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
// mandatory: will bind the datasource given params
void bind() const;
private: private:
static const char* name_; static const char* name_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
const std::string factory_; const std::string factory_;
std::map<std::string, std::string> kwargs_; std::map<std::string, std::string> kwargs_;
mutable boost::python::object datasource_; boost::python::object datasource_;
}; };

View file

@ -45,7 +45,7 @@ using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource) DATASOURCE_PLUGIN(raster_datasource)
raster_datasource::raster_datasource(parameters const& params, bool bind) raster_datasource::raster_datasource(parameters const& params)
: datasource(params), : datasource(params),
desc_(*params.get<std::string>("type"), "utf-8"), desc_(*params.get<std::string>("type"), "utf-8"),
extent_initialized_(false) extent_initialized_(false)
@ -61,18 +61,19 @@ raster_datasource::raster_datasource(parameters const& params, bool bind)
else else
filename_ = *file; filename_ = *file;
multi_tiles_ = *params_.get<bool>("multi", false); multi_tiles_ = *params.get<bool>("multi", false);
tile_size_ = *params_.get<unsigned>("tile_size", 256); tile_size_ = *params.get<unsigned>("tile_size", 256);
tile_stride_ = *params_.get<unsigned>("tile_stride", 1); tile_stride_ = *params.get<unsigned>("tile_stride", 1);
format_ = *params_.get<std::string>("format","tiff"); format_ = *params.get<std::string>("format","tiff");
boost::optional<double> lox = params_.get<double>("lox");
boost::optional<double> loy = params_.get<double>("loy");
boost::optional<double> hix = params_.get<double>("hix");
boost::optional<double> hiy = params_.get<double>("hiy");
boost::optional<std::string> ext = params_.get<std::string>("extent");
boost::optional<double> lox = params.get<double>("lox");
boost::optional<double> loy = params.get<double>("loy");
boost::optional<double> hix = params.get<double>("hix");
boost::optional<double> hiy = params.get<double>("hiy");
boost::optional<std::string> ext = params.get<std::string>("extent");
if (lox && loy && hix && hiy) if (lox && loy && hix && hiy)
{ {
extent_.init(*lox, *loy, *hix, *hiy); extent_.init(*lox, *loy, *hix, *hiy);
@ -87,21 +88,11 @@ raster_datasource::raster_datasource(parameters const& params, bool bind)
{ {
throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required"); throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required");
} }
if (bind)
{
this->bind();
}
}
void raster_datasource::bind() const
{
if (is_bound_) return;
if (multi_tiles_) if (multi_tiles_)
{ {
boost::optional<unsigned> x_width = params_.get<unsigned>("x_width"); boost::optional<unsigned> x_width = params.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params_.get<unsigned>("y_width"); boost::optional<unsigned> y_width = params.get<unsigned>("y_width");
if (! x_width) if (! x_width)
{ {
@ -148,7 +139,6 @@ void raster_datasource::bind() const
MAPNIK_LOG_DEBUG(raster) << "raster_datasource: Raster size=" << width_ << "," << height_; MAPNIK_LOG_DEBUG(raster) << "raster_datasource: Raster size=" << width_ << "," << height_;
is_bound_ = true;
} }
raster_datasource::~raster_datasource() raster_datasource::~raster_datasource()
@ -182,8 +172,6 @@ layer_descriptor raster_datasource::get_descriptor() const
featureset_ptr raster_datasource::features(query const& q) const featureset_ptr raster_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
mapnik::CoordTransform t(width_, height_, extent_, 0, 0); mapnik::CoordTransform t(width_, height_, extent_, 0, 0);
mapnik::box2d<double> intersect = extent_.intersect(q.get_bbox()); mapnik::box2d<double> intersect = extent_.intersect(q.get_bbox());
mapnik::box2d<double> ext = t.forward(intersect); mapnik::box2d<double> ext = t.forward(intersect);

View file

@ -44,7 +44,7 @@
class raster_datasource : public mapnik::datasource class raster_datasource : public mapnik::datasource
{ {
public: public:
raster_datasource(const mapnik::parameters& params, bool bind=true); raster_datasource(const mapnik::parameters& params);
virtual ~raster_datasource(); virtual ~raster_datasource();
datasource::datasource_t type() const; datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -54,7 +54,6 @@ public:
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
bool log_enabled() const; bool log_enabled() const;
void bind() const;
private: private:
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
@ -65,8 +64,8 @@ private:
bool multi_tiles_; bool multi_tiles_;
unsigned tile_size_; unsigned tile_size_;
unsigned tile_stride_; unsigned tile_stride_;
mutable unsigned width_; unsigned width_;
mutable unsigned height_; unsigned height_;
}; };
#endif // RASTER_DATASOURCE_HPP #endif // RASTER_DATASOURCE_HPP

View file

@ -71,7 +71,7 @@ inline void* rasterlite_datasource::open_dataset() const
} }
rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind) rasterlite_datasource::rasterlite_datasource(parameters const& params)
: datasource(params), : datasource(params),
desc_(*params.get<std::string>("type"),"utf-8") desc_(*params.get<std::string>("type"),"utf-8")
{ {
@ -91,16 +91,11 @@ rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind
else else
dataset_name_ = *file; dataset_name_ = *file;
if (bind) this->init(params);
{
this->bind();
}
} }
void rasterlite_datasource::bind() const void rasterlite_datasource::init(mapnik::parameters const& params)
{ {
if (is_bound_) return;
if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist"); if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist");
void *dataset = open_dataset(); void *dataset = open_dataset();
@ -158,8 +153,6 @@ void rasterlite_datasource::bind() const
#endif #endif
rasterliteClose(dataset); rasterliteClose(dataset);
is_bound_ = true;
} }
rasterlite_datasource::~rasterlite_datasource() rasterlite_datasource::~rasterlite_datasource()
@ -178,8 +171,6 @@ mapnik::datasource::datasource_t rasterlite_datasource::type() const
box2d<double> rasterlite_datasource::envelope() const box2d<double> rasterlite_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }
@ -195,16 +186,12 @@ layer_descriptor rasterlite_datasource::get_descriptor() const
featureset_ptr rasterlite_datasource::features(query const& q) const featureset_ptr rasterlite_datasource::features(query const& q) const
{ {
if (!is_bound_) bind();
rasterlite_query gq = q; rasterlite_query gq = q;
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq); return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
} }
featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
rasterlite_query gq = pt; rasterlite_query gq = pt;
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq); return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
} }

View file

@ -45,7 +45,7 @@
class rasterlite_datasource : public mapnik::datasource class rasterlite_datasource : public mapnik::datasource
{ {
public: public:
rasterlite_datasource(mapnik::parameters const& params, bool bind = true); rasterlite_datasource(mapnik::parameters const& params);
virtual ~rasterlite_datasource (); virtual ~rasterlite_datasource ();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -54,11 +54,10 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
void* open_dataset() const; void* open_dataset() const;
mutable mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string dataset_name_; std::string dataset_name_;
std::string table_name_; std::string table_name_;
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;

View file

@ -55,14 +55,17 @@ using mapnik::filter_in_box;
using mapnik::filter_at_point; using mapnik::filter_at_point;
using mapnik::attribute_descriptor; using mapnik::attribute_descriptor;
shape_datasource::shape_datasource(const parameters &params, bool bind) shape_datasource::shape_datasource(const parameters &params)
: datasource (params), : datasource (params),
type_(datasource::Vector), type_(datasource::Vector),
file_length_(0), file_length_(0),
indexed_(false), indexed_(false),
row_limit_(*params_.get<int>("row_limit",0)), row_limit_(*params.get<int>("row_limit",0)),
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"))
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::init");
#endif
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("Shape Plugin: missing <file> parameter"); if (!file) throw datasource_exception("Shape Plugin: missing <file> parameter");
@ -74,20 +77,6 @@ shape_datasource::shape_datasource(const parameters &params, bool bind)
boost::algorithm::ireplace_last(shape_name_,".shp",""); boost::algorithm::ireplace_last(shape_name_,".shp","");
if (bind)
{
this->bind();
}
}
void shape_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::bind");
#endif
if (!boost::filesystem::exists(shape_name_ + ".shp")) if (!boost::filesystem::exists(shape_name_ + ".shp"))
{ {
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist"); throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist");
@ -107,7 +96,7 @@ void shape_datasource::bind() const
try try
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "shape_datasource::bind(get_column_description)"); mapnik::progress_timer __stats2__(std::clog, "shape_datasource::init(get_column_description)");
#endif #endif
boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_); boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_);
@ -171,12 +160,9 @@ void shape_datasource::bind() const
throw; throw;
} }
is_bound_ = true;
} }
shape_datasource::~shape_datasource() {} void shape_datasource::init(shape_io& shape)
void shape_datasource::init(shape_io& shape) const
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::init"); mapnik::progress_timer __stats__(std::clog, "shape_datasource::init");
@ -240,6 +226,8 @@ void shape_datasource::init(shape_io& shape) const
MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Shape type=" << shape_type_; MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Shape type=" << shape_type_;
} }
shape_datasource::~shape_datasource() {}
const char * shape_datasource::name() const char * shape_datasource::name()
{ {
return "shape"; return "shape";
@ -252,14 +240,11 @@ datasource::datasource_t shape_datasource::type() const
layer_descriptor shape_datasource::get_descriptor() const layer_descriptor shape_datasource::get_descriptor() const
{ {
if (!is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr shape_datasource::features(const query& q) const featureset_ptr shape_datasource::features(const query& q) const
{ {
if (!is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features"); mapnik::progress_timer __stats__(std::clog, "shape_datasource::features");
#endif #endif
@ -290,8 +275,6 @@ featureset_ptr shape_datasource::features(const query& q) const
featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point");
#endif #endif
@ -334,8 +317,6 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol
box2d<double> shape_datasource::envelope() const box2d<double> shape_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }

View file

@ -52,7 +52,7 @@ using mapnik::coord2d;
class shape_datasource : public datasource class shape_datasource : public datasource
{ {
public: public:
shape_datasource(const parameters &params, bool bind=true); shape_datasource(const parameters &params);
virtual ~shape_datasource(); virtual ~shape_datasource();
datasource::datasource_t type() const; datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -61,20 +61,19 @@ public:
box2d<double> envelope() const; box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
void bind() const;
private: private:
void init(shape_io& shape) const; void init(shape_io& shape);
datasource::datasource_t type_; datasource::datasource_t type_;
std::string shape_name_; std::string shape_name_;
mutable boost::shared_ptr<shape_io> shape_; boost::shared_ptr<shape_io> shape_;
mutable shape_io::shapeType shape_type_; shape_io::shapeType shape_type_;
mutable long file_length_; long file_length_;
mutable box2d<double> extent_; box2d<double> extent_;
mutable bool indexed_; bool indexed_;
const int row_limit_; const int row_limit_;
mutable layer_descriptor desc_; layer_descriptor desc_;
}; };
#endif //SHAPE_HPP #endif //SHAPE_HPP

View file

@ -52,22 +52,22 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(sqlite_datasource) DATASOURCE_PLUGIN(sqlite_datasource)
sqlite_datasource::sqlite_datasource(parameters const& params, bool bind) sqlite_datasource::sqlite_datasource(parameters const& params)
: datasource(params), : datasource(params),
extent_(), extent_(),
extent_initialized_(false), extent_initialized_(false),
type_(datasource::Vector), type_(datasource::Vector),
table_(*params_.get<std::string>("table", "")), table_(*params.get<std::string>("table", "")),
fields_(*params_.get<std::string>("fields", "*")), fields_(*params.get<std::string>("fields", "*")),
metadata_(*params_.get<std::string>("metadata", "")), metadata_(*params.get<std::string>("metadata", "")),
geometry_table_(*params_.get<std::string>("geometry_table", "")), geometry_table_(*params.get<std::string>("geometry_table", "")),
geometry_field_(*params_.get<std::string>("geometry_field", "")), geometry_field_(*params.get<std::string>("geometry_field", "")),
index_table_(*params_.get<std::string>("index_table", "")), index_table_(*params.get<std::string>("index_table", "")),
key_field_(*params_.get<std::string>("key_field", "")), key_field_(*params.get<std::string>("key_field", "")),
row_offset_(*params_.get<int>("row_offset", 0)), row_offset_(*params.get<int>("row_offset", 0)),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params.get<int>("row_limit", 0)),
intersects_token_("!intersects!"), intersects_token_("!intersects!"),
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")),
format_(mapnik::wkbAuto) format_(mapnik::wkbAuto)
{ {
/* TODO /* TODO
@ -76,27 +76,14 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
- if spatialite - leverage more of the metadata for geometry type detection - if spatialite - leverage more of the metadata for geometry type detection
*/ */
boost::optional<std::string> file = params_.get<std::string>("file");
if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
if (bind)
{
this->bind();
}
}
void sqlite_datasource::bind() const
{
if (is_bound_) return;
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::bind"); mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::init");
#endif #endif
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("Sqlite Plugin: missing <file> parameter"); if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
boost::optional<std::string> base = params_.get<std::string>("base"); boost::optional<std::string> base = params.get<std::string>("base");
if (base) if (base)
dataset_name_ = *base + "/" + *file; dataset_name_ = *base + "/" + *file;
else else
@ -107,15 +94,15 @@ void sqlite_datasource::bind() const
throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist"); throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist");
} }
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index", true); use_spatial_index_ = *params.get<mapnik::boolean>("use_spatial_index", true);
// TODO - remove this option once all datasources have an indexing api // TODO - remove this option once all datasources have an indexing api
bool auto_index = *params_.get<mapnik::boolean>("auto_index", true); bool auto_index = *params.get<mapnik::boolean>("auto_index", true);
boost::optional<std::string> ext = params_.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext); if (ext) extent_initialized_ = extent_.from_string(*ext);
boost::optional<std::string> wkb = params_.get<std::string>("wkb_format"); boost::optional<std::string> wkb = params.get<std::string>("wkb_format");
if (wkb) if (wkb)
{ {
if (*wkb == "spatialite") if (*wkb == "spatialite")
@ -139,13 +126,13 @@ void sqlite_datasource::bind() const
// databases are relative to directory containing dataset_name_. Sqlite // databases are relative to directory containing dataset_name_. Sqlite
// will default to attaching from cwd. Typicaly usage means that the // will default to attaching from cwd. Typicaly usage means that the
// map loader will produce full paths here. // map loader will produce full paths here.
boost::optional<std::string> attachdb = params_.get<std::string>("attachdb"); boost::optional<std::string> attachdb = params.get<std::string>("attachdb");
if (attachdb) if (attachdb)
{ {
parse_attachdb(*attachdb); parse_attachdb(*attachdb);
} }
boost::optional<std::string> initdb = params_.get<std::string>("initdb"); boost::optional<std::string> initdb = params.get<std::string>("initdb");
if (initdb) if (initdb)
{ {
init_statements_.push_back(*initdb); init_statements_.push_back(*initdb);
@ -154,10 +141,10 @@ void sqlite_datasource::bind() const
// now actually create the connection and start executing setup sql // now actually create the connection and start executing setup sql
dataset_ = boost::make_shared<sqlite_connection>(dataset_name_); dataset_ = boost::make_shared<sqlite_connection>(dataset_name_);
boost::optional<unsigned> table_by_index = params_.get<unsigned>("table_by_index"); boost::optional<unsigned> table_by_index = params.get<unsigned>("table_by_index");
int passed_parameters = 0; int passed_parameters = 0;
passed_parameters += params_.get<std::string>("table") ? 1 : 0; passed_parameters += params.get<std::string>("table") ? 1 : 0;
passed_parameters += table_by_index ? 1 : 0; passed_parameters += table_by_index ? 1 : 0;
if (passed_parameters > 1) if (passed_parameters > 1)
@ -289,7 +276,7 @@ void sqlite_datasource::bind() const
if (use_spatial_index_) if (use_spatial_index_)
{ {
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::bind(use_spatial_index)"); mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::init(use_spatial_index)");
#endif #endif
if (boost::filesystem::exists(index_db)) if (boost::filesystem::exists(index_db))
@ -374,7 +361,6 @@ void sqlite_datasource::bind() const
} }
} }
is_bound_ = true;
} }
std::string sqlite_datasource::populate_tokens(std::string const& sql) const std::string sqlite_datasource::populate_tokens(std::string const& sql) const
@ -487,15 +473,11 @@ mapnik::datasource::datasource_t sqlite_datasource::type() const
box2d<double> sqlite_datasource::envelope() const box2d<double> sqlite_datasource::envelope() const
{ {
if (! is_bound_) bind();
return extent_; return extent_;
} }
boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::get_geometry_type"); mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::get_geometry_type");
#endif #endif
@ -547,15 +529,11 @@ boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_
layer_descriptor sqlite_datasource::get_descriptor() const layer_descriptor sqlite_datasource::get_descriptor() const
{ {
if (! is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr sqlite_datasource::features(query const& q) const featureset_ptr sqlite_datasource::features(query const& q) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features"); mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features");
#endif #endif
@ -634,8 +612,6 @@ featureset_ptr sqlite_datasource::features(query const& q) const
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double tol) const featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double tol) const
{ {
if (! is_bound_) bind();
#ifdef MAPNIK_STATS #ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features_at_point"); mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features_at_point");
#endif #endif

View file

@ -48,7 +48,7 @@
class sqlite_datasource : public mapnik::datasource class sqlite_datasource : public mapnik::datasource
{ {
public: public:
sqlite_datasource(mapnik::parameters const& params, bool bind = true); sqlite_datasource(mapnik::parameters const& params);
virtual ~sqlite_datasource (); virtual ~sqlite_datasource ();
datasource::datasource_t type() const; datasource::datasource_t type() const;
static const char * name(); static const char * name();
@ -57,7 +57,6 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private: private:
// Fill init_statements with any statements // Fill init_statements with any statements
@ -65,30 +64,27 @@ private:
void parse_attachdb(std::string const& attachdb) const; void parse_attachdb(std::string const& attachdb) const;
std::string populate_tokens(std::string const& sql) const; std::string populate_tokens(std::string const& sql) const;
// FIXME: remove mutable qualifier from data members mapnik::box2d<double> extent_;
// by factoring out bind() logic out from bool extent_initialized_;
// datasource impl !!!
mutable mapnik::box2d<double> extent_;
mutable bool extent_initialized_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable std::string dataset_name_; std::string dataset_name_;
mutable boost::shared_ptr<sqlite_connection> dataset_; boost::shared_ptr<sqlite_connection> dataset_;
mutable std::string table_; std::string table_;
std::string fields_; std::string fields_;
std::string metadata_; std::string metadata_;
mutable std::string geometry_table_; std::string geometry_table_;
mutable std::string geometry_field_; std::string geometry_field_;
mutable std::string index_table_; std::string index_table_;
mutable std::string key_field_; std::string key_field_;
mutable int row_offset_; int row_offset_;
mutable int row_limit_; int row_limit_;
// TODO - also add to postgis.input // TODO - also add to postgis.input
const std::string intersects_token_; const std::string intersects_token_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable mapnik::wkbFormat format_; mapnik::wkbFormat format_;
mutable bool use_spatial_index_; bool use_spatial_index_;
mutable bool has_spatial_index_; bool has_spatial_index_;
mutable bool using_subquery_; bool using_subquery_;
mutable std::vector<std::string> init_statements_; mutable std::vector<std::string> init_statements_;
}; };

View file

@ -11,29 +11,22 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(hello_datasource) DATASOURCE_PLUGIN(hello_datasource)
hello_datasource::hello_datasource(parameters const& params, bool bind) hello_datasource::hello_datasource(parameters const& params)
: datasource(params), : datasource(params),
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")),
extent_() extent_()
{ {
if (bind) this->init(params);
{
this->bind();
}
} }
void hello_datasource::bind() const void hello_datasource::init(mapnik::parameters const& params)
{ {
if (is_bound_) return;
// every datasource must have some way of reporting its extent // every datasource must have some way of reporting its extent
// in this case we are not actually reading from any data so for fun // in this case we are not actually reading from any data so for fun
// let's just create a world extent in Mapnik's default srs: // let's just create a world extent in Mapnik's default srs:
// '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326) // '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326)
// see http://spatialreference.org/ref/epsg/4326/ for more details // see http://spatialreference.org/ref/epsg/4326/ for more details
extent_.init(-180,-90,180,90); extent_.init(-180,-90,180,90);
is_bound_ = true;
} }
hello_datasource::~hello_datasource() { } hello_datasource::~hello_datasource() { }
@ -51,8 +44,6 @@ mapnik::datasource::datasource_t hello_datasource::type() const
mapnik::box2d<double> hello_datasource::envelope() const mapnik::box2d<double> hello_datasource::envelope() const
{ {
if (!is_bound_) bind();
return extent_; return extent_;
} }
@ -63,15 +54,11 @@ boost::optional<mapnik::datasource::geometry_t> hello_datasource::get_geometry_t
mapnik::layer_descriptor hello_datasource::get_descriptor() const mapnik::layer_descriptor hello_datasource::get_descriptor() const
{ {
if (!is_bound_) bind();
return desc_; return desc_;
} }
mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
{ {
if (!is_bound_) bind();
// if the query box intersects our world extent then query for features // if the query box intersects our world extent then query for features
if (extent_.intersects(q.get_bbox())) if (extent_.intersects(q.get_bbox()))
{ {
@ -84,8 +71,6 @@ mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
{ {
if (!is_bound_) bind();
// features_at_point is rarely used - only by custom applications, // features_at_point is rarely used - only by custom applications,
// so for this sample plugin let's do nothing... // so for this sample plugin let's do nothing...
return mapnik::featureset_ptr(); return mapnik::featureset_ptr();

View file

@ -22,7 +22,7 @@ class hello_datasource : public mapnik::datasource
public: public:
// constructor // constructor
// arguments must not change // arguments must not change
hello_datasource(mapnik::parameters const& params, bool bind=true); hello_datasource(mapnik::parameters const& params);
// destructor // destructor
virtual ~hello_datasource (); virtual ~hello_datasource ();
@ -51,15 +51,15 @@ public:
// mandatory: return the layer descriptor // mandatory: return the layer descriptor
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
// mandatory: will bind the datasource given params
void bind() const;
private: private:
// recommended - do intialization in a so-named init function
// to reduce code in constructor
void init(mapnik::parameters const& params);
// recommended naming convention of datasource members: // recommended naming convention of datasource members:
// name_, type_, extent_, and desc_ // name_, type_, extent_, and desc_
static const std::string name_; static const std::string name_;
mutable mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
mutable mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
}; };

View file

@ -55,7 +55,7 @@ datasource_cache::~datasource_cache()
lt_dlexit(); lt_dlexit();
} }
datasource_ptr datasource_cache::create(const parameters& params, bool bind) datasource_ptr datasource_cache::create(const parameters& params)
{ {
boost::optional<std::string> type = params.get<std::string>("type"); boost::optional<std::string> type = params.get<std::string>("type");
if ( ! type) if ( ! type)
@ -114,7 +114,7 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind)
} }
#endif #endif
ds = datasource_ptr(create_datasource(params, bind), datasource_deleter()); ds = datasource_ptr(create_datasource(params), datasource_deleter());
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type; MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type;

View file

@ -119,7 +119,6 @@ namespace mapnik { namespace util {
feature_type_style style_out(style_in,true); // deep copy feature_type_style style_out(style_in,true); // deep copy
map_out.insert_style(kv.first, style_out); map_out.insert_style(kv.first, style_out);
} }
} }
}} }}