Compare commits

...

32 commits

Author SHA1 Message Date
Dane Springmeyer
982a2b940e merge with master 2012-03-14 12:26:43 -07:00
Artem Pavlenko
965181bd65 revert last change 2012-03-12 16:15:56 +00:00
Artem Pavlenko
f6f4f27b1f resolve merge conflict 2012-03-12 16:00:07 +00:00
Artem Pavlenko
d206657dd4 Merge branch 'master' into move_bind_logic_to_layer
Conflicts:
	bindings/python/mapnik_layer.cpp
	include/mapnik/symbolizer_helpers.hpp
	src/agg/process_line_symbolizer.cpp
	src/cairo_renderer.cpp
	src/feature_style_processor.cpp
2012-03-12 15:51:09 +00:00
Artem Pavlenko
a4c4c4b65c Merge remote-tracking branch 'origin/move_bind_logic_to_layer' into move_bind_logic_to_layer 2012-03-09 11:21:20 +00:00
Dane Springmeyer
4bf23dc0b9 update rasterlite, occi, csv, hello_world, and rundemo 2012-03-08 22:31:43 -08:00
Artem Pavlenko
90f453a19f Merge branch 'master' into move_bind_logic_to_layer 2012-03-08 16:44:24 +00:00
Artem Pavlenko
500f344b34 + add clipping to polygon/line_pattern_syms 2012-03-08 15:02:46 +00:00
Artem Pavlenko
48b6d9899e + update cairo_renderer to use clipped paths 2012-03-08 11:07:13 +00:00
Artem Pavlenko
71eb544d6a Merge branch 'master' into move_bind_logic_to_layer 2012-03-08 09:21:04 +00:00
Artem Pavlenko
51bfc0bd35 + inflate query extent to avoid line joining artifacts 2012-03-07 15:01:55 +00:00
Artem Pavlenko
23ac16cb04 + cleanup 2012-03-07 15:01:23 +00:00
Artem Pavlenko
b86378253c + add clipping to text/shield/markers 2012-03-07 12:48:51 +00:00
Artem Pavlenko
0ead59223c + remove debug printing 2012-03-07 12:04:55 +00:00
Artem Pavlenko
386cbe852f + clip geometries before applying any
transformations.
2012-03-07 09:33:43 +00:00
Artem Pavlenko
3a8c11cfa3 Merge branch 'master' into move_bind_logic_to_layer 2012-03-06 08:46:09 +00:00
Artem Pavlenko
ceeb115529 + fix : call init(params) 2012-03-05 15:38:19 +00:00
Artem Pavlenko
edd85f41bc + update geos.input - TODO: do we need this datasource ? 2012-03-05 15:29:58 +00:00
Artem Pavlenko
ad3072300f + remove mutable qualifiers 2012-03-05 15:29:21 +00:00
Artem Pavlenko
0cd93835f8 + update osm.input 2012-03-05 15:15:39 +00:00
Artem Pavlenko
a67e9dc967 + update sqlite.input 2012-03-05 15:05:09 +00:00
Artem Pavlenko
90323ffc74 + update raster.input 2012-03-05 14:43:59 +00:00
Artem Pavlenko
a22cc87df7 + update ogr.input 2012-03-05 14:38:04 +00:00
Artem Pavlenko
0b8a3323c2 + update gdal.input 2012-03-05 14:32:08 +00:00
Artem Pavlenko
9cbd4ad932 + make init(parameters const&) private 2012-03-05 14:21:57 +00:00
Artem Pavlenko
9ace240a67 + update rundemo.py 2012-03-05 14:10:30 +00:00
Artem Pavlenko
6de8a9066c + update viewer to work with new datasource/layer interface 2012-03-05 14:09:52 +00:00
Artem Pavlenko
accd81192b + remove bind() logic from shape and postgis plug-ins 2012-03-05 14:09:19 +00:00
Artem Pavlenko
9d24ed04f5 + update python bindings to use new datasource interface
+ datasource_parameters accept Python dictionary e.g

```
>>> import mapnik
>>> l = mapnik.Layer("test")
>>> l.datasource_parameters = {"type":"shape","file":"/tmp/world.shp"}
```
2012-03-05 14:06:36 +00:00
Artem Pavlenko
02b2a55ecc + update load/save map to work with mapnik::parameters 2012-03-05 14:04:36 +00:00
Artem Pavlenko
5e63e42673 + temp fix to compile : FIXME 2012-03-05 14:04:06 +00:00
Artem Pavlenko
9a0248559f + move 'bind' logic from datasource level to layer
+ store and copy mapnik::parameters only in mapnik::layer
+ make datasource_ptr mutable
2012-03-05 13:59:12 +00:00
41 changed files with 457 additions and 653 deletions

View file

@ -46,20 +46,13 @@ namespace
using namespace boost::python;
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{
bool bind=true;
mapnik::parameters params;
boost::python::list keys=d.keys();
for (int i=0; i<len(keys); ++i)
{
std::string key = extract<std::string>(keys[i]);
object obj = d[key];
if (key == "bind")
{
bind = extract<bool>(obj)();
continue;
}
extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<double> ex2(obj);
@ -78,7 +71,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
}
}
return mapnik::datasource_cache::create(params, bind);
return mapnik::datasource_cache::create(params);
}
boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
@ -166,13 +159,9 @@ void export_datasource()
.def("describe",&describe)
.def("envelope",&datasource::envelope)
.def("features",&datasource::features)
.def("bind",&datasource::bind)
.def("fields",&fields)
.def("field_types",&field_types)
.def("features_at_point",&datasource::features_at_point)
.def("params",&datasource::params,return_value_policy<copy_const_reference>(),
"The configuration parameters of the data source. "
"These vary depending on the type of data source.")
;
def("CreateDatasource",&create_datasource);

View file

@ -54,7 +54,7 @@ struct layer_pickle_suite : boost::python::pickle_suite
{
s.append(style_names[i]);
}
return boost::python::make_tuple(l.clear_label_cache(),l.min_zoom(),l.max_zoom(),l.queryable(),l.datasource()->params(),l.cache_features(),s);
return boost::python::make_tuple(l.clear_label_cache(),l.min_zoom(),l.max_zoom(),l.queryable(),l.datasource_parameters(),l.cache_features(),s);
}
static void
@ -79,8 +79,8 @@ struct layer_pickle_suite : boost::python::pickle_suite
l.set_queryable(extract<bool>(state[3]));
mapnik::parameters params = extract<parameters>(state[4]);
l.set_datasource(datasource_cache::instance()->create(params));
l.set_datasource_parameters(params);
boost::python::list s = extract<boost::python::list>(state[5]);
for (int i=0;i<len(s);++i)
{
@ -91,8 +91,43 @@ struct layer_pickle_suite : boost::python::pickle_suite
}
};
std::vector<std::string> & (mapnik::layer::*_styles_)() = &mapnik::layer::styles;
void set_datasource_parameters(layer & lyr, boost::python::dict const& d)
{
mapnik::parameters params;
boost::python::list keys = d.keys();
for (int i=0;i<len(keys);++i)
{
boost::python::extract<std::string> k(keys[i]);
if (k.check())
{
boost::python::object obj = d[keys[i]];
boost::python::extract<std::string> str_val(obj);
if (str_val.check())
{
params.insert(std::make_pair(k(),str_val()));
continue;
}
boost::python::extract<int> int_val(obj);
if (int_val.check())
{
params.insert(std::make_pair(k(),int_val()));
continue;
}
boost::python::extract<double> dbl_val(obj);
if (dbl_val.check())
{
params.insert(std::make_pair(k(),dbl_val()));
}
}
}
lyr.set_datasource_parameters(params);
}
void export_layer()
{
using namespace boost::python;
@ -185,15 +220,19 @@ void export_layer()
">>> lyr.cache_features = True # set to True to enable feature caching\n"
)
.add_property("datasource",
&layer::datasource,
&layer::set_datasource,
"The datasource attached to this layer.\n"
.def("datasource",&layer::datasource,
"The datasource attached to this layer.\n"
)
.add_property("datasource_parameters",
make_function(&layer::datasource_parameters,return_value_policy<copy_const_reference>()),
set_datasource_parameters,
"The datasource parameters attached to this layer.\n"
"\n"
"Usage:\n"
">>> from mapnik import Layer, Datasource\n"
">>> lyr = Layer('My Layer','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')\n"
">>> lyr.datasource = Datasource(type='shape',file='world_borders')\n"
">>> lyr.datasource_parameters = {'type':'shape','file':'world_borders'}\n"
">>> lyr.datasource\n"
"<mapnik.Datasource object at 0x65470>\n"
)
@ -290,6 +329,6 @@ void export_layer()
">>> lyr.styles[0]\n"
"'My Style'\n"
)
;
}

View file

@ -68,7 +68,7 @@ m.background = mapnik.Color('white')
provpoly_lyr = mapnik.Layer('Provinces')
provpoly_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
provpoly_lyr.datasource = mapnik.Shapefile(file='../data/boundaries', encoding='latin1')
provpoly_lyr.datasource_parameters = {"type":"shape","file":'../data/boundaries', "encoding":'latin1'}
# We then define a style for the layer. A layer can have one or many styles.
# Styles are named, so they can be shared across different layers.
@ -133,7 +133,7 @@ m.layers.append(provpoly_lyr)
qcdrain_lyr = mapnik.Layer('Quebec Hydrography')
qcdrain_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
qcdrain_lyr.datasource = mapnik.Shapefile(file='../data/qcdrainage')
qcdrain_lyr.datasource_parameters = {"type":"shape","file":'../data/qcdrainage'}
qcdrain_style = mapnik.Style()
qcdrain_rule = mapnik.Rule()
@ -153,7 +153,7 @@ m.layers.append(qcdrain_lyr)
ondrain_lyr = mapnik.Layer('Ontario Hydrography')
ondrain_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
ondrain_lyr.datasource = mapnik.Shapefile(file='../data/ontdrainage')
ondrain_lyr.datasource_parameters = {"type":"shape","file":'../data/ontdrainage'}
ondrain_lyr.styles.append('drainage')
m.layers.append(ondrain_lyr)
@ -162,7 +162,7 @@ m.layers.append(ondrain_lyr)
provlines_lyr = mapnik.Layer('Provincial borders')
provlines_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
provlines_lyr.datasource = mapnik.Shapefile(file='../data/boundaries_l')
provlines_lyr.datasource_parameters = {"type":"shape","file":'../data/boundaries_l'}
# Here we define a "dash dot dot dash" pattern for the provincial boundaries.
@ -188,7 +188,7 @@ roads34_lyr = mapnik.Layer('Roads')
roads34_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
# create roads datasource (we're going to re-use it later)
roads34_lyr.datasource = mapnik.Shapefile(file='../data/roads')
roads34_lyr.datasource_parameters = {"type":"shape","file":'../data/roads'}
roads34_style = mapnik.Style()
roads34_rule = mapnik.Rule()
@ -221,7 +221,7 @@ m.layers.append(roads34_lyr)
roads2_lyr = mapnik.Layer('Roads')
roads2_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
# Just get a copy from roads34_lyr
roads2_lyr.datasource = roads34_lyr.datasource
roads2_lyr.datasource_parameters = {"type":"shape","file":'../data/roads'}#roads34_lyr.datasource
roads2_style_1 = mapnik.Style()
roads2_rule_1 = mapnik.Rule()
@ -256,7 +256,7 @@ m.layers.append(roads2_lyr)
roads1_lyr = mapnik.Layer('Roads')
roads1_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
roads1_lyr.datasource = roads34_lyr.datasource
roads1_lyr.datasource_parameters = {"type":"shape","file":'../data/roads'}#roads34_lyr.datasource
roads1_style_1 = mapnik.Style()
roads1_rule_1 = mapnik.Rule()
@ -290,7 +290,7 @@ m.layers.append(roads1_lyr)
popplaces_lyr = mapnik.Layer('Populated Places')
popplaces_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
popplaces_lyr.datasource = mapnik.Shapefile(file='../data/popplaces',encoding='latin1')
popplaces_lyr.datasource_parameters = {"type":"shape","file":'../data/popplaces',"encoding":'latin1'}
popplaces_style = mapnik.Style()
popplaces_rule = mapnik.Rule()

View file

@ -39,28 +39,24 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
// Named Styles : TODO!!!
// Datasource
mapnik::datasource_ptr ds = lay.datasource();
if (ds)
mapnik::parameters const& ps = lay.datasource_parameters();
ui.tableWidget->setRowCount(ps.size());
ui.tableWidget->setColumnCount(2);
mapnik::parameters::const_iterator pos;
int index=0;
for (pos = ps.begin();pos != ps.end();++pos)
{
mapnik::parameters ps = ds->params();
ui.tableWidget->setRowCount(ps.size());
ui.tableWidget->setColumnCount(2);
mapnik::parameters::const_iterator pos;
int index=0;
for (pos = ps.begin();pos != ps.end();++pos)
boost::optional<std::string> result;
boost::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
if (result)
{
boost::optional<std::string> result;
boost::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
if (result)
{
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
ui.tableWidget->setItem(index,0,keyItem);
ui.tableWidget->setItem(index,1,valueItem);
++index;
}
QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
ui.tableWidget->setItem(index,0,keyItem);
ui.tableWidget->setItem(index,1,valueItem);
++index;
}
}
}

View file

@ -81,47 +81,25 @@ public:
Collection = 4
};
datasource (parameters const& params)
: params_(params),
is_bound_(false)
{}
/*!
* @brief Get the configuration parameters of the data source.
*
* These vary depending on the type of data source.
*
* @return The configuration parameters of the data source.
*/
parameters const& params() const
{
return params_;
}
datasource (parameters const& params) {}
/*!
* @brief Get the type of the datasource
* @return The type of the datasource (Vector or Raster)
*/
virtual datasource_t type() const=0;
/*!
* @brief Connect to the datasource
*/
virtual void bind() const {};
virtual featureset_ptr features(const query& q) const=0;
virtual featureset_ptr features(query const& q) const=0;
virtual featureset_ptr features_at_point(coord2d const& pt) const=0;
virtual box2d<double> envelope() const=0;
virtual boost::optional<geometry_t> get_geometry_type() const=0;
virtual layer_descriptor get_descriptor() const=0;
virtual ~datasource() {};
protected:
parameters params_;
mutable bool is_bound_;
};
typedef boost::shared_ptr<datasource> datasource_ptr;
typedef std::string datasource_name();
typedef datasource* create_ds(const parameters& params, bool bind);
typedef datasource* create_ds(parameters const& params);
typedef void destroy_ds(datasource *ds);
@ -134,17 +112,14 @@ public:
}
};
typedef boost::shared_ptr<datasource> datasource_ptr;
#define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_EXP std::string datasource_name() \
{ \
return classname::name(); \
} \
extern "C" MAPNIK_EXP datasource* create(const parameters &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) \
{ \

View file

@ -37,6 +37,9 @@
#include <map>
namespace mapnik {
class datasource;
class MAPNIK_DECL datasource_cache :
public singleton <datasource_cache,CreateStatic>,
private boost::noncopyable
@ -55,7 +58,8 @@ public:
static std::vector<std::string> plugin_names();
static std::string plugin_directories();
static void register_datasources(const std::string& path);
static boost::shared_ptr<datasource> create(parameters const& params, bool bind=true);
static boost::shared_ptr<datasource> create(parameters const& params);
};
}

View file

@ -176,13 +176,15 @@ public:
*
* @param ds The datasource to attach.
*/
void set_datasource(datasource_ptr const& ds);
void set_datasource_parameters(parameters const& p);
parameters const& datasource_parameters() const;
/*!
* @return the datasource attached to this layer.
*/
datasource_ptr datasource() const;
/*!
* @return the geographic envelope/bounding box of the data in the layer.
*/
@ -203,7 +205,8 @@ private:
bool cache_features_;
std::string group_by_;
std::vector<std::string> styles_;
datasource_ptr ds_;
parameters datasource_params_;
mutable datasource_ptr ds_;
};
}

View file

@ -30,23 +30,23 @@ using namespace boost::spirit;
DATASOURCE_PLUGIN(csv_datasource)
csv_datasource::csv_datasource(parameters const& params, bool bind)
csv_datasource::csv_datasource(parameters const& 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_(),
filename_(),
inline_string_(),
file_length_(0),
row_limit_(*params_.get<int>("row_limit", 0)),
row_limit_(*params.get<int>("row_limit", 0)),
features_(),
escape_(*params_.get<std::string>("escape", "")),
separator_(*params_.get<std::string>("separator", "")),
quote_(*params_.get<std::string>("quote", "")),
escape_(*params.get<std::string>("escape", "")),
separator_(*params.get<std::string>("separator", "")),
quote_(*params.get<std::string>("quote", "")),
headers_(),
manual_headers_(boost::trim_copy(*params_.get<std::string>("headers", ""))),
strict_(*params_.get<mapnik::boolean>("strict", false)),
quiet_(*params_.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params_.get<float>("filesize_max", 20.0)) // MB
manual_headers_(boost::trim_copy(*params.get<std::string>("headers", ""))),
strict_(*params.get<mapnik::boolean>("strict", false)),
quiet_(*params.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params.get<float>("filesize_max", 20.0)) // MB
{
/* TODO:
general:
@ -71,36 +71,31 @@ csv_datasource::csv_datasource(parameters const& params, bool bind)
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)
{
inline_string_ = *inline_string;
}
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");
boost::optional<std::string> base = params_.get<std::string>("base");
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
filename_ = *base + "/" + *file;
else
filename_ = *file;
}
if (bind)
{
this->bind();
}
this->init(params);
}
csv_datasource::~csv_datasource() { }
void csv_datasource::bind() const
void csv_datasource::init(mapnik::parameters const& params)
{
if (is_bound_) return;
if (!inline_string_.empty())
{
std::istringstream in(inline_string_);
@ -114,7 +109,6 @@ void csv_datasource::bind() const
parse_csv(in,escape_, separator_, quote_);
in.close();
}
is_bound_ = true;
}
template <typename T>
@ -246,7 +240,7 @@ void csv_datasource::parse_csv(T& stream,
// grammer = boost::escaped_list_separator<char>('\\', ',', '\"');
grammer = boost::escaped_list_separator<char>(esc, sep, quo);
}
catch(const std::exception & ex)
catch(std::exception const& ex)
{
std::ostringstream s;
s << "CSV Plugin: " << ex.what();
@ -372,7 +366,7 @@ void csv_datasource::parse_csv(T& stream,
break;
}
}
catch(const std::exception & ex)
catch(std::exception const& ex)
{
std::ostringstream s;
s << "CSV Plugin: error parsing headers: " << ex.what();
@ -813,7 +807,7 @@ void csv_datasource::parse_csv(T& stream,
if (!quiet_) std::clog << ex.what() << "\n";
}
}
catch(const std::exception & ex)
catch(std::exception const& ex)
{
std::ostringstream s;
s << "CSV Plugin: unexpected error parsing line: " << line_number
@ -847,14 +841,11 @@ datasource::datasource_t csv_datasource::type() const
mapnik::box2d<double> csv_datasource::envelope() const
{
if (!is_bound_) bind();
return extent_;
}
boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_type() const
{
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
int multi_type = 0;
unsigned num_features = features_.size();
@ -877,15 +868,11 @@ boost::optional<mapnik::datasource::geometry_t> csv_datasource::get_geometry_typ
mapnik::layer_descriptor csv_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
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();
std::set<std::string>::const_iterator pos = attribute_names.begin();
while (pos != attribute_names.end())
@ -917,7 +904,5 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt) const
{
if (!is_bound_) bind();
throw mapnik::datasource_exception("CSV Plugin: features_at_point is not supported yet");
}

View file

@ -10,7 +10,7 @@
class csv_datasource : public mapnik::datasource
{
public:
csv_datasource(mapnik::parameters const& params, bool bind=true);
csv_datasource(mapnik::parameters const& params);
virtual ~csv_datasource ();
mapnik::datasource::datasource_t type() const;
static std::string name();
@ -19,13 +19,13 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;
template <typename T>
void parse_csv(T& stream,
std::string const& escape,
std::string const& separator,
std::string const& quote) const;
private:
void init(mapnik::parameters const& params);
mutable mapnik::layer_descriptor desc_;
mutable mapnik::box2d<double> extent_;
mutable std::string filename_;

View file

@ -75,21 +75,25 @@ 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),
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))
{
#ifdef MAPNIK_DEBUG
std::clog << "GDAL Plugin: Initializing..." << std::endl;
#endif
this->init(params);
}
void gdal_datasource::init(mapnik::parameters const& params)
{
GDALAllRegister();
boost::optional<std::string> file = params.get<std::string>("file");
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)
{
dataset_name_ = *base + "/" + *file;
@ -98,20 +102,9 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
{
dataset_name_ = *file;
}
if (bind)
{
this->bind();
}
}
void gdal_datasource::bind() const
{
if (is_bound_) return;
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
band_ = *params_.get<int>("band", -1);
shared_dataset_ = *params.get<mapnik::boolean>("shared", false);
band_ = *params.get<int>("band", -1);
GDALDataset *dataset = open_dataset();
nbands_ = dataset->GetRasterCount();
@ -120,7 +113,7 @@ void gdal_datasource::bind() const
double tr[6];
bool bbox_override = false;
boost::optional<std::string> bbox_s = params_.get<std::string>("bbox");
boost::optional<std::string> bbox_s = params.get<std::string>("bbox");
if (bbox_s)
{
#ifdef MAPNIK_DEBUG
@ -192,7 +185,6 @@ void gdal_datasource::bind() const
std::clog << "GDAL Plugin: Raster Extent=" << extent_ << std::endl;
#endif
is_bound_ = true;
}
gdal_datasource::~gdal_datasource()
@ -211,8 +203,6 @@ std::string gdal_datasource::name()
box2d<double> gdal_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
@ -228,10 +218,8 @@ layer_descriptor gdal_datasource::get_descriptor() const
featureset_ptr gdal_datasource::features(query const& q) const
{
if (! is_bound_) bind();
gdal_query gq = q;
// TODO - move to boost::make_shared, but must reduce # of args to <= 9
return featureset_ptr(new gdal_featureset(*open_dataset(),
band_,
@ -247,8 +235,6 @@ featureset_ptr gdal_datasource::features(query const& q) const
featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
gdal_query gq = pt;
// TODO - move to boost::make_shared, but must reduce # of args to <= 9

View file

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

View file

@ -84,7 +84,7 @@ void geos_error(const char* fmt, ...)
}
geos_datasource::geos_datasource(parameters const& params, bool bind)
geos_datasource::geos_datasource(parameters const& params)
: datasource(params),
extent_(),
extent_initialized_(false),
@ -93,48 +93,39 @@ geos_datasource::geos_datasource(parameters const& params, bool bind)
geometry_data_(""),
geometry_data_name_("name"),
geometry_id_(1)
{
boost::optional<std::string> geometry = params.get<std::string>("wkt");
if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry;
boost::optional<std::string> ext = params_.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext);
boost::optional<int> id = params_.get<int>("gid");
if (id) geometry_id_ = *id;
boost::optional<std::string> gdata = params_.get<std::string>("field_data");
if (gdata) geometry_data_ = *gdata;
boost::optional<std::string> gdata_name = params_.get<std::string>("field_name");
if (gdata_name) geometry_data_name_ = *gdata_name;
desc_.add_descriptor(attribute_descriptor(geometry_data_name_, mapnik::String));
if (bind)
{
this->bind();
}
{
init(params);
}
geos_datasource::~geos_datasource()
{
if (is_bound_)
{
geometry_.set_feature(0);
finishGEOS();
}
geometry_.set_feature(0);
finishGEOS();
}
void geos_datasource::bind() const
void geos_datasource::init(mapnik::parameters const& params)
{
if (is_bound_) return;
// open geos driver
initGEOS(geos_notice, geos_error);
boost::optional<std::string> geometry = params.get<std::string>("wkt");
if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry;
boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext) extent_initialized_ = extent_.from_string(*ext);
boost::optional<int> id = params.get<int>("gid");
if (id) geometry_id_ = *id;
boost::optional<std::string> gdata = params.get<std::string>("field_data");
if (gdata) geometry_data_ = *gdata;
boost::optional<std::string> gdata_name = params.get<std::string>("field_name");
if (gdata_name) geometry_data_name_ = *gdata_name;
desc_.add_descriptor(attribute_descriptor(geometry_data_name_, mapnik::String));
// parse the string into geometry
geometry_.set_feature(GEOSGeomFromWKT(geometry_string_.c_str()));
if (*geometry_ == NULL || ! GEOSisValid(*geometry_))
@ -216,8 +207,6 @@ void geos_datasource::bind() const
{
throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry");
}
is_bound_ = true;
}
std::string geos_datasource::name()
@ -232,14 +221,11 @@ mapnik::datasource::datasource_t geos_datasource::type() const
box2d<double> geos_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_type() const
{
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
// get geometry type
@ -271,17 +257,13 @@ boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_ty
layer_descriptor geos_datasource::get_descriptor() const
{
if (! is_bound_) bind();
return desc_;
}
featureset_ptr geos_datasource::features(query const& q) const
{
if (! is_bound_) bind();
const mapnik::box2d<double> extent = q.get_bbox();
mapnik::box2d<double> const& extent = q.get_bbox();
std::ostringstream s;
s << "POLYGON(("
<< extent.minx() << " " << extent.miny() << ","
@ -305,8 +287,6 @@ featureset_ptr geos_datasource::features(query const& q) const
featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
std::ostringstream s;
s << "POINT(" << pt.x << " " << pt.y << ")";

View file

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

View file

@ -71,7 +71,7 @@ boost::mutex knd_list_mutex;
std::list<kismet_network_data> knd_list;
const unsigned int queue_size = 20;
kismet_datasource::kismet_datasource(parameters const& params, bool bind)
kismet_datasource::kismet_datasource(parameters const& params)
: datasource(params),
extent_(),
extent_initialized_(false),
@ -79,7 +79,7 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
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)
{
host_ = *host;
@ -89,37 +89,25 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
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)
{
port_ = *port;
}
boost::optional<std::string> srs = params_.get<std::string>("srs");
boost::optional<std::string> srs = params.get<std::string>("srs");
if (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)
{
extent_initialized_ = extent_.from_string(*ext);
}
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()
@ -138,7 +126,6 @@ mapnik::datasource::datasource_t kismet_datasource::type() const
box2d<double> kismet_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
@ -154,7 +141,6 @@ layer_descriptor kismet_datasource::get_descriptor() const
featureset_ptr kismet_datasource::features(query const& q) const
{
if (! is_bound_) bind();
// std::clog << "kismet_datasource::features()" << endl;
@ -172,7 +158,6 @@ featureset_ptr kismet_datasource::features(query const& q) const
featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
// std::clog << "kismet_datasource::features_at_point()" << endl;

View file

@ -43,7 +43,7 @@
class kismet_datasource : public mapnik::datasource
{
public:
kismet_datasource(mapnik::parameters const& params, bool bind = true);
kismet_datasource(mapnik::parameters const& params);
virtual ~kismet_datasource ();
datasource::datasource_t type() const;
static std::string name();
@ -52,11 +52,10 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private:
void init(mapnik::parameters const& params);
void run (const std::string& host, const unsigned int port);
mapnik::box2d<double> extent_;
bool extent_initialized_;
std::string host_;

View file

@ -67,24 +67,25 @@ const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA";
DATASOURCE_PLUGIN(occi_datasource)
occi_datasource::occi_datasource(parameters const& params, bool bind)
occi_datasource::occi_datasource(parameters const& params)
: datasource (params),
params_(params),
type_(datasource::Vector),
fields_(*params_.get<std::string>("fields", "*")),
geometry_field_(*params_.get<std::string>("geometry_field", "")),
fields_(*params.get<std::string>("fields", "*")),
geometry_field_(*params.get<std::string>("geometry_field", "")),
srid_initialized_(false),
extent_initialized_(false),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
row_limit_(*params_.get<int>("row_limit", 0)),
row_prefetch_(*params_.get<int>("row_prefetch", 100)),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
row_limit_(*params.get<int>("row_limit", 0)),
row_prefetch_(*params.get<int>("row_prefetch", 100)),
pool_(0),
conn_(0)
{
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");
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");
boost::optional<std::string> table = params.get<std::string>("table");
if (! table)
{
throw datasource_exception("OCCI Plugin: no <table> parameter specified");
@ -94,52 +95,44 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
table_ = *table;
}
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);
use_connection_pool_ = *params.get<mapnik::boolean>("use_connection_pool",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);
boost::optional<int> srid = params_.get<int>("srid");
boost::optional<int> srid = params.get<int>("srid");
if (srid)
{
srid_ = *srid;
srid_initialized_ = true;
}
if (bind)
{
this->bind();
}
this->init(params);
}
occi_datasource::~occi_datasource()
{
if (is_bound_)
{
Environment* env = occi_environment::get_environment();
Environment* env = occi_environment::get_environment();
if (use_connection_pool_)
if (use_connection_pool_)
{
if (pool_ != 0)
{
if (pool_ != 0)
{
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
}
env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE);
}
else
}
else
{
if (conn_ != 0)
{
if (conn_ != 0)
{
env->terminateConnection(conn_);
}
env->terminateConnection(conn_);
}
}
}
void occi_datasource::bind() const
void occi_datasource::init(mapnik::parameters const& params)
{
if (is_bound_) return;
// connect to environment
if (use_connection_pool_)
{
@ -148,11 +141,11 @@ void occi_datasource::bind() const
Environment* env = occi_environment::get_environment();
pool_ = env->createStatelessConnectionPool(
*params_.get<std::string>("user"),
*params_.get<std::string>("password"),
*params_.get<std::string>("host"),
*params_.get<int>("max_size", 10),
*params_.get<int>("initial_size", 1),
*params.get<std::string>("user"),
*params.get<std::string>("password"),
*params.get<std::string>("host"),
*params.get<int>("max_size", 10),
*params.get<int>("initial_size", 1),
1,
StatelessConnectionPool::HOMOGENEOUS);
}
@ -168,9 +161,9 @@ void occi_datasource::bind() const
Environment* env = occi_environment::get_environment();
conn_ = env->createConnection(
*params_.get<std::string>("user"),
*params_.get<std::string>("password"),
*params_.get<std::string>("host"));
*params.get<std::string>("user"),
*params.get<std::string>("password"),
*params.get<std::string>("host"));
}
catch (SQLException& ex)
{
@ -342,8 +335,6 @@ void occi_datasource::bind() const
throw datasource_exception(ex.getMessage());
}
}
is_bound_ = true;
}
std::string occi_datasource::name()
@ -359,7 +350,6 @@ mapnik::datasource::datasource_t occi_datasource::type() const
box2d<double> occi_datasource::envelope() const
{
if (extent_initialized_) return extent_;
if (! is_bound_) bind();
double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0;
@ -478,20 +468,17 @@ box2d<double> occi_datasource::envelope() 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>();
}
layer_descriptor occi_datasource::get_descriptor() const
{
if (! is_bound_) bind();
return desc_;
}
featureset_ptr occi_datasource::features(query const& q) const
{
if (! is_bound_) bind();
box2d<double> const& box = q.get_bbox();
@ -540,15 +527,18 @@ featureset_ptr occi_datasource::features(query const& q) const
if (row_limit_ > 0)
{
std::string row_limit_string = "rownum < " + row_limit_;
std::ostringstream row_limit_string;
row_limit_string << "rownum < " << row_limit_;
if (boost::algorithm::ifind_first(query, "WHERE"))
{
boost::algorithm::ireplace_first(query, "WHERE", row_limit_string + " AND ");
row_limit_string << " AND ";
boost::algorithm::ireplace_first(query, "WHERE", row_limit_string.str());
}
else if (boost::algorithm::ifind_first(query, table_name_))
{
boost::algorithm::ireplace_first(query, table_name_, table_name_ + " " + row_limit_string);
boost::algorithm::ireplace_first(query, table_name_, table_name_ + " " + row_limit_string.str());
}
else
{
@ -575,7 +565,6 @@ featureset_ptr occi_datasource::features(query const& q) const
featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
std::ostringstream s;
s << "SELECT " << geometry_field_;
@ -621,15 +610,18 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
if (row_limit_ > 0)
{
std::string row_limit_string = "rownum < " + row_limit_;
std::ostringstream row_limit_string;
row_limit_string << "rownum < " << row_limit_;
if (boost::algorithm::ifind_first(query, "WHERE"))
{
boost::algorithm::ireplace_first(query, "WHERE", row_limit_string + " AND ");
row_limit_string << " AND ";
boost::algorithm::ireplace_first(query, "WHERE", row_limit_string.str());
}
else if (boost::algorithm::ifind_first(query, table_name_))
{
boost::algorithm::ireplace_first(query, table_name_, table_name_ + " " + row_limit_string);
boost::algorithm::ireplace_first(query, table_name_, table_name_ + " " + row_limit_string.str());
}
else
{

View file

@ -38,7 +38,7 @@
class occi_datasource : public mapnik::datasource
{
public:
occi_datasource(mapnik::parameters const& params, bool bind = true);
occi_datasource(mapnik::parameters const& params);
virtual ~occi_datasource ();
mapnik::datasource::datasource_t type() const;
static std::string name();
@ -47,9 +47,10 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private:
void init(mapnik::parameters const& params);
mapnik::parameters const& params_;
mapnik::datasource::datasource_t type_;
mutable std::string table_;
mutable std::string table_name_;

View file

@ -56,13 +56,28 @@ using mapnik::filter_in_box;
using mapnik::filter_at_point;
ogr_datasource::ogr_datasource(parameters const& params, bool bind)
ogr_datasource::ogr_datasource(parameters const& params)
: datasource(params),
extent_(),
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)
{
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)
{
// initialize ogr formats
OGRRegisterAll();
boost::optional<std::string> file = params.get<std::string>("file");
boost::optional<std::string> string = params.get<std::string>("string");
if (! file && ! string)
@ -86,32 +101,9 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
dataset_name_ = *file;
}
}
if (bind)
{
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;
// initialize ogr formats
OGRRegisterAll();
std::string driver = *params_.get<std::string>("driver","");
std::string driver = *params.get<std::string>("driver","");
if (! driver.empty())
{
@ -142,9 +134,9 @@ void ogr_datasource::bind() const
}
// initialize 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<std::string> layer_by_sql = params_.get<std::string>("layer_by_sql");
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<std::string> layer_by_sql = params.get<std::string>("layer_by_sql");
int passed_parameters = 0;
passed_parameters += layer_by_name ? 1 : 0;
@ -320,8 +312,6 @@ void ogr_datasource::bind() const
}
}
}
is_bound_ = true;
}
std::string ogr_datasource::name()
@ -336,7 +326,6 @@ mapnik::datasource::datasource_t ogr_datasource::type() const
box2d<double> ogr_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
@ -419,7 +408,6 @@ boost::optional<mapnik::datasource::geometry_t> ogr_datasource::get_geometry_typ
layer_descriptor ogr_datasource::get_descriptor() const
{
if (! is_bound_) bind();
return desc_;
}
@ -462,8 +450,6 @@ void validate_attribute_names(query const& q, std::vector<attribute_descriptor>
featureset_ptr ogr_datasource::features(query const& q) const
{
if (! is_bound_) bind();
if (dataset_ && layer_.is_valid())
{
// First we validate query fields: https://github.com/mapnik/mapnik/issues/792
@ -509,8 +495,6 @@ featureset_ptr ogr_datasource::features(query const& q) const
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
{
if (!is_bound_) bind();
if (dataset_ && layer_.is_valid())
{
std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();

View file

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

View file

@ -50,26 +50,21 @@ using mapnik::attribute_descriptor;
DATASOURCE_PLUGIN(osm_datasource)
osm_datasource::osm_datasource(const parameters& params, bool bind)
osm_datasource::osm_datasource(parameters const& params)
: datasource (params),
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();
}
init(params);
}
void osm_datasource::bind() const
void osm_datasource::init(mapnik::parameters const& params)
{
if (is_bound_) return;
osm_data_ = NULL;
std::string osm_filename = *params_.get<std::string>("file", "");
std::string parser = *params_.get<std::string>("parser", "libxml2");
std::string url = *params_.get<std::string>("url", "");
std::string bbox = *params_.get<std::string>("bbox", "");
std::string osm_filename = *params.get<std::string>("file", "");
std::string parser = *params.get<std::string>("parser", "libxml2");
std::string url = *params.get<std::string>("url", "");
std::string bbox = *params.get<std::string>("bbox", "");
bool do_process = false;
@ -122,8 +117,6 @@ void osm_datasource::bind() const
bounds b = osm_data_->get_bounds();
extent_ = box2d<double>(b.w, b.s, b.e, b.n);
}
is_bound_ = true;
}
osm_datasource::~osm_datasource()
@ -149,8 +142,6 @@ layer_descriptor osm_datasource::get_descriptor() const
featureset_ptr osm_datasource::features(const query& q) const
{
if (! is_bound_) bind();
filter_in_box filter(q.get_bbox());
// so we need to filter osm features by bbox here...
@ -162,8 +153,6 @@ featureset_ptr osm_datasource::features(const query& q) const
featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
filter_at_point filter(pt);
// collect all attribute names
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
@ -185,13 +174,10 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
box2d<double> osm_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
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);
}
}

View file

@ -40,24 +40,22 @@ using mapnik::box2d;
class osm_datasource : public datasource
{
public:
osm_datasource(const parameters& params, bool bind = true);
osm_datasource(parameters const& params);
virtual ~osm_datasource();
mapnik::datasource::datasource_t type() const;
featureset_ptr features(const query& q) const;
featureset_ptr features(query const& q) const;
featureset_ptr features_at_point(coord2d const& pt) const;
box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const;
static std::string name();
void bind() const;
private:
mutable box2d<double> extent_;
mutable osm_dataset* osm_data_;
void init(mapnik::parameters const& params);
box2d<double> extent_;
osm_dataset* osm_data_;
mapnik::datasource::datasource_t type_;
mutable layer_descriptor desc_;
// no copying
osm_datasource(const osm_datasource&);
osm_datasource& operator=(const osm_datasource&);
layer_descriptor desc_;
};
#endif // OSM_DATASOURCE_HPP

View file

@ -54,19 +54,19 @@ using boost::shared_ptr;
using mapnik::PoolGuard;
using mapnik::attribute_descriptor;
postgis_datasource::postgis_datasource(parameters const& params, bool bind)
postgis_datasource::postgis_datasource(parameters const& params)
: datasource(params),
table_(*params_.get<std::string>("table","")),
table_(*params.get<std::string>("table","")),
schema_(""),
geometry_table_(*params_.get<std::string>("geometry_table","")),
geometry_field_(*params_.get<std::string>("geometry_field","")),
key_field_(*params_.get<std::string>("key_field","")),
cursor_fetch_size_(*params_.get<int>("cursor_size",0)),
row_limit_(*params_.get<int>("row_limit",0)),
geometry_table_(*params.get<std::string>("geometry_table","")),
geometry_field_(*params.get<std::string>("geometry_field","")),
key_field_(*params.get<std::string>("key_field","")),
cursor_fetch_size_(*params.get<int>("cursor_size",0)),
row_limit_(*params.get<int>("row_limit",0)),
type_(datasource::Vector),
srid_(*params_.get<int>("srid",0)),
srid_(*params.get<int>("srid",0)),
extent_initialized_(false),
desc_(*params_.get<std::string>("type"),"utf-8"),
desc_(*params.get<std::string>("type"),"utf-8"),
creator_(params.get<std::string>("host"),
params.get<std::string>("port"),
params.get<std::string>("dbname"),
@ -75,30 +75,25 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
params.get<std::string>("connect_timeout","4")),
bbox_token_("!bbox!"),
scale_denom_token_("!scale_denominator!"),
persist_connection_(*params_.get<mapnik::boolean>("persist_connection",true)),
extent_from_subquery_(*params_.get<mapnik::boolean>("extent_from_subquery",false)),
persist_connection_(*params.get<mapnik::boolean>("persist_connection",true)),
extent_from_subquery_(*params.get<mapnik::boolean>("extent_from_subquery",false)),
estimate_extent_(*params.get<mapnik::boolean>("estimate_extent",false)),
// 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_max_scale_(*params_.get<int>("intersect_max_scale",0))
//show_queries_(*params_.get<mapnik::boolean>("show_queries",false))
intersect_min_scale_(*params.get<int>("intersect_min_scale",0)),
intersect_max_scale_(*params.get<int>("intersect_max_scale",0))
//show_queries_(*params.get<mapnik::boolean>("show_queries",false))
{
if (table_.empty()) 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) extent_initialized_ = extent_.from_string(*ext);
if (bind)
{
this->bind();
}
this->init(params);
}
void postgis_datasource::bind() const
void postgis_datasource::init(parameters const& params)
{
if (is_bound_) return;
boost::optional<int> initial_size = params_.get<int>("initial_size",1);
boost::optional<int> max_size = params_.get<int>("max_size",10);
boost::optional<int> initial_size = params.get<int>("initial_size",1);
boost::optional<int> max_size = params.get<int>("max_size",10);
ConnectionManager *mgr=ConnectionManager::instance();
mgr->registerPool(creator_, *initial_size, *max_size);
@ -327,11 +322,7 @@ void postgis_datasource::bind() const
}
}
}
rs->close();
is_bound_ = true;
}
}
}
@ -348,11 +339,9 @@ mapnik::datasource::datasource_t postgis_datasource::type() const
layer_descriptor postgis_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
std::string postgis_datasource::sql_bbox(box2d<double> const& env) const
{
std::ostringstream b;
@ -464,8 +453,6 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
featureset_ptr postgis_datasource::features(const query& q) const
{
if (!is_bound_) bind();
box2d<double> const& box = q.get_bbox();
double scale_denom = q.scale_denominator();
ConnectionManager *mgr=ConnectionManager::instance();
@ -538,8 +525,6 @@ featureset_ptr postgis_datasource::features(const query& q) const
featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
{
if (!is_bound_) bind();
ConnectionManager *mgr=ConnectionManager::instance();
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool)
@ -607,8 +592,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
box2d<double> postgis_datasource::envelope() const
{
if (extent_initialized_) return extent_;
if (!is_bound_) bind();
ConnectionManager *mgr=ConnectionManager::instance();
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool)
@ -618,7 +602,6 @@ box2d<double> postgis_datasource::envelope() const
{
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::ostringstream s;
boost::optional<mapnik::boolean> estimate_extent = params_.get<mapnik::boolean>("estimate_extent",false);
if (!geometryColumn_.length() > 0)
{
@ -635,7 +618,7 @@ box2d<double> postgis_datasource::envelope() const
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)"
<< " FROM (SELECT ST_Estimated_Extent('";
@ -706,9 +689,8 @@ box2d<double> postgis_datasource::envelope() const
boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry_type() const
{
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
ConnectionManager *mgr=ConnectionManager::instance();
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool)
@ -818,7 +800,7 @@ boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry
postgis_datasource::~postgis_datasource()
{
if (is_bound_ && !persist_connection_)
if (!persist_connection_)
{
ConnectionManager *mgr=ConnectionManager::instance();
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());

View file

@ -55,28 +55,33 @@ class postgis_datasource : public datasource
const std::string username_;
const std::string password_;
const std::string table_;
mutable std::string schema_;
mutable std::string geometry_table_;
std::string schema_;
std::string geometry_table_;
const std::string geometry_field_;
const std::string key_field_;
const int cursor_fetch_size_;
const int row_limit_;
mutable std::string geometryColumn_;
std::string geometryColumn_;
mapnik::datasource::datasource_t type_;
mutable int srid_;
int srid_;
mutable bool extent_initialized_;
mutable mapnik::box2d<double> extent_;
mutable layer_descriptor desc_;
layer_descriptor desc_;
ConnectionCreator<Connection> creator_;
const std::string bbox_token_;
const std::string scale_denom_token_;
bool persist_connection_;
bool extent_from_subquery_;
bool estimate_extent_;
// params below are for testing purposes only (will likely be removed at any time)
int intersect_min_scale_;
int intersect_max_scale_;
//bool show_queries_;
public:
// ctor/dtor
postgis_datasource(const parameters &params);
~postgis_datasource();
static std::string name();
mapnik::datasource::datasource_t type() const;
featureset_ptr features(const query& q) const;
@ -84,10 +89,8 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const;
postgis_datasource(const parameters &params, bool bind=true);
~postgis_datasource();
void bind() const;
private:
void init(parameters const& params);
std::string sql_bbox(box2d<double> const& env) const;
std::string populate_tokens(const std::string& sql, double scale_denom, box2d<double> const& env) const;
std::string populate_tokens(const std::string& sql) const;

View file

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

View file

@ -45,7 +45,7 @@ using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource)
raster_datasource::raster_datasource(const parameters& params, bool bind)
raster_datasource::raster_datasource(const parameters& params)
: datasource(params),
desc_(*params.get<std::string>("type"), "utf-8"),
extent_initialized_(false)
@ -54,6 +54,12 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
std::clog << "Raster Plugin: Initializing..." << std::endl;
#endif
this->init(params);
}
void raster_datasource::init(parameters const& params)
{
boost::optional<std::string> file = params.get<std::string>("file");
if (! file) throw datasource_exception("Raster Plugin: missing <file> parameter ");
@ -63,18 +69,19 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
else
filename_ = *file;
multi_tiles_ = *params_.get<bool>("multi", false);
tile_size_ = *params_.get<unsigned>("tile_size", 256);
tile_stride_ = *params_.get<unsigned>("tile_stride", 1);
multi_tiles_ = *params.get<bool>("multi", false);
tile_size_ = *params.get<unsigned>("tile_size", 256);
tile_stride_ = *params.get<unsigned>("tile_stride", 1);
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");
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");
if (lox && loy && hix && hiy)
{
extent_.init(*lox, *loy, *hix, *hiy);
@ -89,21 +96,11 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
{
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_)
{
boost::optional<unsigned> x_width = params_.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params_.get<unsigned>("y_width");
boost::optional<unsigned> x_width = params.get<unsigned>("x_width");
boost::optional<unsigned> y_width = params.get<unsigned>("y_width");
if (! x_width)
{
@ -151,8 +148,6 @@ void raster_datasource::bind() const
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl;
#endif
is_bound_ = true;
}
raster_datasource::~raster_datasource()
@ -186,8 +181,6 @@ layer_descriptor raster_datasource::get_descriptor() const
featureset_ptr raster_datasource::features(query const& q) const
{
if (! is_bound_) bind();
mapnik::CoordTransform t(width_, height_, extent_, 0, 0);
mapnik::box2d<double> intersect = extent_.intersect(q.get_bbox());
mapnik::box2d<double> ext = t.forward(intersect);

View file

@ -31,7 +31,7 @@
class raster_datasource : public mapnik::datasource
{
public:
raster_datasource(const mapnik::parameters& params, bool bind=true);
raster_datasource(mapnik::parameters const& params);
virtual ~raster_datasource();
datasource::datasource_t type() const;
static std::string name();
@ -40,8 +40,8 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
void bind() const;
private:
void init(mapnik::parameters const& params);
mapnik::layer_descriptor desc_;
std::string filename_;
std::string format_;
@ -50,11 +50,9 @@ private:
bool multi_tiles_;
unsigned tile_size_;
unsigned tile_stride_;
mutable unsigned width_;
mutable unsigned height_;
//no copying
raster_datasource(const raster_datasource&);
raster_datasource& operator=(const raster_datasource&);
unsigned width_;
unsigned height_;
};
#endif // RASTER_DATASOURCE_HPP

View file

@ -70,7 +70,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),
desc_(*params.get<std::string>("type"),"utf-8")
{
@ -92,16 +92,11 @@ rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind
else
dataset_name_ = *file;
if (bind)
{
this->bind();
}
this->init(params);
}
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");
void *dataset = open_dataset();
@ -157,8 +152,6 @@ void rasterlite_datasource::bind() const
#endif
rasterliteClose(dataset);
is_bound_ = true;
}
rasterlite_datasource::~rasterlite_datasource()
@ -177,8 +170,6 @@ mapnik::datasource::datasource_t rasterlite_datasource::type() const
box2d<double> rasterlite_datasource::envelope() const
{
if (!is_bound_) bind();
return extent_;
}
@ -194,16 +185,12 @@ layer_descriptor rasterlite_datasource::get_descriptor() const
featureset_ptr rasterlite_datasource::features(query const& q) const
{
if (!is_bound_) bind();
rasterlite_query gq = q;
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
}
featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt) const
{
if (!is_bound_) bind();
rasterlite_query gq = pt;
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
}

View file

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

View file

@ -49,12 +49,12 @@ using mapnik::filter_in_box;
using mapnik::filter_at_point;
using mapnik::attribute_descriptor;
shape_datasource::shape_datasource(const parameters &params, bool bind)
shape_datasource::shape_datasource(const parameters &params)
: datasource (params),
type_(datasource::Vector),
file_length_(0),
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"))
{
boost::optional<std::string> file = params.get<std::string>("file");
@ -67,17 +67,11 @@ shape_datasource::shape_datasource(const parameters &params, bool bind)
shape_name_ = *file;
boost::algorithm::ireplace_last(shape_name_,".shp","");
if (bind)
{
this->bind();
}
this->init(params);
}
void shape_datasource::bind() const
void shape_datasource::init(parameters const& p)
{
if (is_bound_) return;
if (!boost::filesystem::exists(shape_name_ + ".shp"))
{
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist");
@ -97,7 +91,7 @@ void shape_datasource::bind() const
try
{
boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_);
init(*shape_ref);
init_io(*shape_ref);
for (int i=0;i<shape_ref->dbf().num_fields();++i)
{
field_descriptor const& fd=shape_ref->dbf().descriptor(i);
@ -157,12 +151,11 @@ void shape_datasource::bind() const
throw;
}
is_bound_ = true;
}
shape_datasource::~shape_datasource() {}
void shape_datasource::init(shape_io& shape) const
void shape_datasource::init_io(shape_io& shape)
{
//first read header from *.shp
int file_code=shape.shp().read_xdr_integer();
@ -236,14 +229,11 @@ datasource::datasource_t shape_datasource::type() const
layer_descriptor shape_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
featureset_ptr shape_datasource::features(const query& q) const
{
if (!is_bound_) bind();
filter_in_box filter(q.get_bbox());
if (indexed_)
{
@ -270,8 +260,6 @@ featureset_ptr shape_datasource::features(const query& q) const
featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
{
if (!is_bound_) bind();
filter_at_point filter(pt);
// collect all attribute names
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
@ -310,8 +298,6 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
box2d<double> shape_datasource::envelope() const
{
if (!is_bound_) bind();
return extent_;
}

View file

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

View file

@ -50,22 +50,22 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(sqlite_datasource)
sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
sqlite_datasource::sqlite_datasource(parameters const& params)
: datasource(params),
extent_(),
extent_initialized_(false),
type_(datasource::Vector),
table_(*params_.get<std::string>("table", "")),
fields_(*params_.get<std::string>("fields", "*")),
metadata_(*params_.get<std::string>("metadata", "")),
geometry_table_(*params_.get<std::string>("geometry_table", "")),
geometry_field_(*params_.get<std::string>("geometry_field", "")),
index_table_(*params_.get<std::string>("index_table", "")),
key_field_(*params_.get<std::string>("key_field", "")),
row_offset_(*params_.get<int>("row_offset", 0)),
row_limit_(*params_.get<int>("row_limit", 0)),
table_(*params.get<std::string>("table", "")),
fields_(*params.get<std::string>("fields", "*")),
metadata_(*params.get<std::string>("metadata", "")),
geometry_table_(*params.get<std::string>("geometry_table", "")),
geometry_field_(*params.get<std::string>("geometry_field", "")),
index_table_(*params.get<std::string>("index_table", "")),
key_field_(*params.get<std::string>("key_field", "")),
row_offset_(*params.get<int>("row_offset", 0)),
row_limit_(*params.get<int>("row_limit", 0)),
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)
{
/* TODO
@ -73,24 +73,15 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
- remove auto-indexing
- 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();
}
init(params);
}
void sqlite_datasource::bind() const
void sqlite_datasource::init(mapnik::parameters const& params)
{
if (is_bound_) return;
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");
boost::optional<std::string> base = params_.get<std::string>("base");
boost::optional<std::string> base = params.get<std::string>("base");
if (base)
dataset_name_ = *base + "/" + *file;
else
@ -101,15 +92,15 @@ void sqlite_datasource::bind() const
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
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);
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 == "spatialite")
@ -133,13 +124,13 @@ void sqlite_datasource::bind() const
// databases are relative to directory containing dataset_name_. Sqlite
// will default to attaching from cwd. Typicaly usage means that the
// 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)
{
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)
{
init_statements_.push_back(*initdb);
@ -148,10 +139,10 @@ void sqlite_datasource::bind() const
// now actually create the connection and start executing setup sql
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;
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;
if (passed_parameters > 1)
@ -365,8 +356,6 @@ void sqlite_datasource::bind() const
throw datasource_exception(s.str());
}
}
is_bound_ = true;
}
std::string sqlite_datasource::populate_tokens(const std::string& sql) const
@ -416,7 +405,7 @@ path read_symlink(const path& p)
}
#endif
void sqlite_datasource::parse_attachdb(std::string const& attachdb) const
void sqlite_datasource::parse_attachdb(std::string const& attachdb)
{
boost::char_separator<char> sep(",");
boost::tokenizer<boost::char_separator<char> > tok(attachdb, sep);
@ -479,14 +468,11 @@ mapnik::datasource::datasource_t sqlite_datasource::type() const
box2d<double> sqlite_datasource::envelope() const
{
if (! is_bound_) bind();
return extent_;
}
boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const
{
if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
if (dataset_)
@ -533,15 +519,11 @@ boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_
layer_descriptor sqlite_datasource::get_descriptor() const
{
if (! is_bound_) bind();
return desc_;
}
featureset_ptr sqlite_datasource::features(query const& q) const
{
if (! is_bound_) bind();
if (dataset_)
{
mapnik::box2d<double> const& e = q.get_bbox();
@ -617,8 +599,6 @@ featureset_ptr sqlite_datasource::features(query const& q) const
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
{
if (! is_bound_) bind();
if (dataset_)
{
// TODO - need tolerance

View file

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

View file

@ -11,29 +11,22 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(hello_datasource)
hello_datasource::hello_datasource(parameters const& params, bool bind)
hello_datasource::hello_datasource(parameters const& 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_()
{
if (bind)
{
this->bind();
}
this->init(params);
}
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
// 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:
// '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326)
// see http://spatialreference.org/ref/epsg/4326/ for more details
extent_.init(-180,-90,180,90);
is_bound_ = true;
}
hello_datasource::~hello_datasource() { }
@ -53,8 +46,6 @@ mapnik::datasource::datasource_t hello_datasource::type() const
mapnik::box2d<double> hello_datasource::envelope() const
{
if (!is_bound_) bind();
return extent_;
}
@ -65,15 +56,11 @@ boost::optional<mapnik::datasource::geometry_t> hello_datasource::get_geometry_t
mapnik::layer_descriptor hello_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
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 (extent_.intersects(q.get_bbox()))
{
@ -86,8 +73,6 @@ mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt) const
{
if (!is_bound_) bind();
// features_at_point is rarely used - only by custom applications,
// so for this sample plugin let's do nothing...
return mapnik::featureset_ptr();

View file

@ -9,7 +9,7 @@ class hello_datasource : public mapnik::datasource
public:
// constructor
// arguments must not change
hello_datasource(mapnik::parameters const& params, bool bind=true);
hello_datasource(mapnik::parameters const& params);
// destructor
virtual ~hello_datasource ();
@ -38,10 +38,10 @@ public:
// mandatory: return the layer descriptor
mapnik::layer_descriptor get_descriptor() const;
// mandatory: will bind the datasource given params
void bind() const;
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:
// name_, type_, extent_, and desc_
static const std::string name_;

View file

@ -1079,6 +1079,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
detector_.extent().width(), detector_.extent().height(),
1.0 /*scale_factor*/,
t_, font_manager_, detector_, query_extent_);
cairo_context context(context_);
while (helper.next()) {

View file

@ -62,7 +62,7 @@ std::map<std::string,boost::shared_ptr<PluginInfo> > datasource_cache::plugins_;
bool datasource_cache::registered_=false;
std::vector<std::string> datasource_cache::plugin_directories_;
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");
if ( ! type)
@ -106,7 +106,7 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind)
std::clog << i->first << "=" << i->second << "\n";
}
#endif
ds=datasource_ptr(create_datasource(params, bind), datasource_deleter());
ds=datasource_ptr(create_datasource(params), datasource_deleter());
#ifdef MAPNIK_DEBUG
std::clog<<"datasource="<<ds<<" type="<<type<<std::endl;

View file

@ -96,18 +96,6 @@ namespace mapnik { namespace util {
BOOST_FOREACH ( layer const& lyr_in, map_in.layers())
{
layer lyr_out(lyr_in);
datasource_ptr ds_in = lyr_in.datasource();
if (ds_in)
{
parameters p(ds_in->params());
// TODO : re-use datasource extent if already set.
datasource_ptr ds_out = datasource_cache::create(p);
if (ds_out)
{
lyr_out.set_datasource(ds_out);
}
}
map_out.addLayer(lyr_out);
}
typedef std::map<std::string, feature_type_style> style_cont;
@ -120,7 +108,6 @@ namespace mapnik { namespace util {
feature_type_style style_out(style_in,true); // deep copy
map_out.insert_style(kv.first, style_out);
}
}
}}
}}

View file

@ -323,8 +323,8 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
BOOST_FOREACH(rule const& r, style->get_rules())
{
if (r.active(scale_denom) &&
ds->type() == datasource::Raster &&
ds->params().get<double>("filter_factor",0.0) == 0.0)
ds->type() == datasource::Raster)
//ds->params().get<double>("filter_factor",0.0) == 0.0) // FIXME !!!
{
rule::symbolizers const& symbols = r.get_symbolizers();
rule::symbolizers::const_iterator symIter = symbols.begin();

View file

@ -27,6 +27,7 @@
#include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/config_error.hpp>
// stl
#include <string>
@ -45,7 +46,7 @@ layer::layer(std::string const& name, std::string const& srs)
clear_label_cache_(false),
cache_features_(false),
group_by_(""),
ds_() {}
datasource_params_() {}
layer::layer(const layer& rhs)
: name_(rhs.name_),
@ -58,7 +59,7 @@ layer::layer(const layer& rhs)
cache_features_(rhs.cache_features_),
group_by_(rhs.group_by_),
styles_(rhs.styles_),
ds_(rhs.ds_) {}
datasource_params_(rhs.datasource_params_) {}
layer& layer::operator=(const layer& rhs)
{
@ -84,7 +85,7 @@ void layer::swap(const layer& rhs)
cache_features_ = rhs.cache_features_;
group_by_ = rhs.group_by_;
styles_=rhs.styles_;
ds_=rhs.ds_;
datasource_params_ = rhs.datasource_params_;
}
layer::~layer() {}
@ -171,17 +172,38 @@ bool layer::queryable() const
datasource_ptr layer::datasource() const
{
if (ds_) return ds_;
try
{
ds_ = datasource_cache::instance()->create(datasource_params_);
}
catch (const std::exception & ex )
{
throw config_error( ex.what() );
}
catch (...)
{
throw config_error("Unknown exception occured attempting to create datasoure for layer '" + name_ + "'");
}
return ds_;
}
void layer::set_datasource(datasource_ptr const& ds)
void layer::set_datasource_parameters(parameters const& p)
{
ds_ = ds;
datasource_params_ = p;
}
parameters const& layer::datasource_parameters() const
{
return datasource_params_;
}
box2d<double> layer::envelope() const
{
if (ds_) return ds_->envelope();
datasource_ptr ds = this->datasource();
if (ds) return ds->envelope();
return box2d<double>();
}

View file

@ -606,23 +606,8 @@ void map_parser::parse_layer(Map & map, xml_node const& lay)
params["file"] = ensure_relative_to_xml(file_param);
}
//now we are ready to create datasource
try
{
boost::shared_ptr<datasource> ds =
datasource_cache::instance()->create(params);
lyr.set_datasource(ds);
}
catch (const std::exception & ex )
{
throw config_error( ex.what() );
}
catch (...)
{
throw config_error("Unknown exception occured attempting to create datasoure for layer '" + lyr.name() + "'");
}
lyr.set_datasource_parameters(params);
}
}
map.addLayer(lyr);

View file

@ -552,13 +552,13 @@ void serialize_fontset( ptree & map_node, Map::const_fontset_iterator fontset_it
}
void serialize_datasource( ptree & layer_node, datasource_ptr datasource)
void serialize_datasource( ptree & layer_node, parameters const& params)
{
ptree & datasource_node = layer_node.push_back(
ptree::value_type("Datasource", ptree()))->second;
parameters::const_iterator it = datasource->params().begin();
parameters::const_iterator end = datasource->params().end();
parameters::const_iterator it = params.begin();
parameters::const_iterator end = params.end();
for (; it != end; ++it)
{
boost::property_tree::ptree & param_node = datasource_node.push_back(
@ -679,11 +679,8 @@ void serialize_layer( ptree & map_node, const layer & layer, bool explicit_defau
style_node.put_value( style_names[i] );
}
datasource_ptr datasource = layer.datasource();
if ( datasource )
{
serialize_datasource( layer_node, datasource );
}
parameters const& params = layer.datasource_parameters();
serialize_datasource( layer_node, params);
}
void serialize_metawriter(ptree & map_node, Map::const_metawriter_iterator metawriter_it, bool explicit_defaults)