1. datasource is now a property of Layer object.

2. modified python/c++ demos to reflect the above.
3. removed large 'blobby' mapnik.hpp (compilation times!!!)
This commit is contained in:
Artem Pavlenko 2006-10-03 08:44:04 +00:00
parent 88892c196b
commit 8328424af5
19 changed files with 221 additions and 350 deletions

View file

@ -33,15 +33,15 @@ void export_datasource_cache()
using namespace boost::python; using namespace boost::python;
class_<singleton<datasource_cache,CreateStatic>,boost::noncopyable>("Singleton",no_init) class_<singleton<datasource_cache,CreateStatic>,boost::noncopyable>("Singleton",no_init)
.def("instance",&singleton<datasource_cache,CreateStatic>::instance, .def("instance",&singleton<datasource_cache,CreateStatic>::instance,
return_value_policy<reference_existing_object>()) return_value_policy<reference_existing_object>())
.staticmethod("instance") .staticmethod("instance")
; ;
class_<datasource_cache,bases<singleton<datasource_cache,CreateStatic> >, class_<datasource_cache,bases<singleton<datasource_cache,CreateStatic> >,
boost::noncopyable>("DatasourceCache",no_init) boost::noncopyable>("DatasourceCache",no_init)
.def("create",&datasource_cache::create) .def("create",&datasource_cache::create)
.staticmethod("create") .staticmethod("create")
.def("register_datasources",&datasource_cache::register_datasources) .def("register_datasources",&datasource_cache::register_datasources)
.staticmethod("register_datasources") .staticmethod("register_datasources")
; ;
} }

View file

@ -60,29 +60,32 @@ bool (Envelope<double>::*intersects_p3)(Envelope<double> const&) const = &Envelo
void export_envelope() void export_envelope()
{ {
using namespace boost::python; using namespace boost::python;
class_<Envelope<double> >("Envelope","A spacial envelope (i.e. bounding box) which also defines some basic operators.",init<double,double,double,double>()) class_<Envelope<double> >("Envelope",
"A spacial envelope (i.e. bounding box) "
"which also defines some basic operators." ,
init<double,double,double,double>())
.def(init<>()) .def(init<>())
.def(init<const coord<double,2>&, const coord<double,2>&>()) .def(init<const coord<double,2>&, const coord<double,2>&>())
.add_property("minx",&Envelope<double>::minx, "X coordinate for the lower left corner") .add_property("minx",&Envelope<double>::minx, "X coordinate for the lower left corner")
.add_property("miny",&Envelope<double>::miny, "Y coordinate for the lower left corner") .add_property("miny",&Envelope<double>::miny, "Y coordinate for the lower left corner")
.add_property("maxx",&Envelope<double>::maxx, "X coordinate for the upper right corner") .add_property("maxx",&Envelope<double>::maxx, "X coordinate for the upper right corner")
.add_property("maxy",&Envelope<double>::maxy, "Y coordinate for the upper right corner") .add_property("maxy",&Envelope<double>::maxy, "Y coordinate for the upper right corner")
.def("center",&Envelope<double>::center) .def("center",&Envelope<double>::center)
.def("center",&Envelope<double>::re_center) .def("center",&Envelope<double>::re_center)
.def("width",width_p1) .def("width",width_p1)
.def("width",width_p2) .def("width",width_p2)
.def("height",height_p1) .def("height",height_p1)
.def("height",height_p2) .def("height",height_p2)
.def("expand_to_include",expand_to_include_p1) .def("expand_to_include",expand_to_include_p1)
.def("expand_to_include",expand_to_include_p2) .def("expand_to_include",expand_to_include_p2)
.def("expand_to_include",expand_to_include_p3) .def("expand_to_include",expand_to_include_p3)
.def("contains",contains_p1) .def("contains",contains_p1)
.def("contains",contains_p2) .def("contains",contains_p2)
.def("contains",contains_p3) .def("contains",contains_p3)
.def("intersects",intersects_p1) .def("intersects",intersects_p1)
.def("intersects",intersects_p2) .def("intersects",intersects_p2)
.def("intersects",intersects_p3) .def("intersects",intersects_p3)
.def(self == self) .def(self == self)
.def_pickle(envelope_pickle_suite()) .def_pickle(envelope_pickle_suite())
; ;
} }

View file

@ -28,7 +28,6 @@
#include <regex_filter.hpp> #include <regex_filter.hpp>
#include <filter.hpp> #include <filter.hpp>
#include <filter_factory.hpp> #include <filter_factory.hpp>
#include <mapnik.hpp>
using mapnik::filter; using mapnik::filter;
using mapnik::filter_ptr; using mapnik::filter_ptr;

View file

@ -30,76 +30,6 @@
using mapnik::Layer; using mapnik::Layer;
using mapnik::parameters; using mapnik::parameters;
struct layer_pickle_suite : boost::python::pickle_suite
{
static boost::python::tuple
getinitargs(const Layer& l)
{
using namespace boost::python;
return boost::python::make_tuple(l.params());
}
static boost::python::tuple
getstate(const Layer& l)
{
using namespace boost::python;
std::vector<std::string> const& styles=l.styles();
std::vector<std::string>::const_iterator itr=styles.begin();
boost::python::list py_styles;
while (itr!=styles.end())
{
py_styles.append(*itr++);
}
return boost::python::make_tuple(l.getMinZoom(),
l.getMaxZoom(),
py_styles);
}
static void
setstate (Layer& l, boost::python::tuple state)
{
using namespace boost::python;
if (len(state) != 3)
{
PyErr_SetObject(PyExc_ValueError,
("expected 3-item tuple in call to __setstate__; got %s"
% state).ptr()
);
throw_error_already_set();
}
l.setMinZoom(extract<double>(state[0]));
l.setMaxZoom(extract<double>(state[1]));
boost::python::list styles=extract<boost::python::list>(state[2]);
for (int i=0;i<len(styles);++i)
{
l.add_style(extract<std::string>(styles[i]));
}
}
};
namespace
{
//user-friendly wrapper that uses Python dictionary
using namespace boost::python;
Layer create_layer(const dict& d)
{
parameters params;
boost::python::list keys=d.keys();
for (int i=0;i<len(keys);++i)
{
std::string key=extract<std::string>(keys[i]);
std::string value=extract<std::string>(d[key]);
params[key] = value;
}
return Layer(params);
}
}
void export_layer() void export_layer()
{ {
using namespace boost::python; using namespace boost::python;
@ -107,17 +37,42 @@ void export_layer()
.def(vector_indexing_suite<std::vector<std::string>,true >()) .def(vector_indexing_suite<std::vector<std::string>,true >())
; ;
class_<Layer>("Layer","A map layer.",no_init) class_<Layer>("Layer","A map layer.", init<std::string const&>())
.def("name",&Layer::name,return_value_policy<copy_const_reference>(), "Return the name of the layer.") .add_property("name",
.def("title",&Layer::title,return_value_policy<copy_const_reference>(), "Return the title of the layer.") make_function(&Layer::name, return_value_policy<reference_existing_object>()),
.def("abstract",&Layer::abstract,return_value_policy<copy_const_reference>(), "Return the abstract of the layer.") &Layer::set_name,
.def("params",&Layer::params,return_value_policy<reference_existing_object>(), "The configuration parameters of the layer. These vary depending on the type of data source.") "Get/Set the name of the layer.")
.def("envelope",&Layer::envelope, "Return the geographic envelope/bounding box of the data in the layer.")
.add_property("minzoom",&Layer::getMinZoom,&Layer::setMinZoom) .add_property("title",
.add_property("maxzoom",&Layer::getMaxZoom,&Layer::setMaxZoom) make_function(&Layer::title, return_value_policy<reference_existing_object>()),
.add_property("styles",make_function &Layer::set_title,
(&Layer::styles,return_value_policy<reference_existing_object>())) "Get/Set the title of the layer.")
.def_pickle(layer_pickle_suite())
.add_property("abstract",
make_function(&Layer::abstract,return_value_policy<reference_existing_object>()),
&Layer::set_abstract,
"Get/Set the abstract of the layer.")
.add_property("minzoom",
&Layer::getMinZoom,
&Layer::setMinZoom)
.add_property("maxzoom",
&Layer::getMaxZoom,
&Layer::setMaxZoom)
.add_property("styles",
make_function(&Layer::styles,
return_value_policy<reference_existing_object>()))
.add_property("datasource",
&Layer::datasource,
&Layer::set_datasource,
"The datasource attached to this layer")
.def("envelope",&Layer::envelope,
"Return the geographic envelope/bounding box "
"of the data in the layer.")
; ;
def("CreateLayer",&create_layer);
} }

View file

@ -25,8 +25,6 @@
#include <boost/get_pointer.hpp> #include <boost/get_pointer.hpp>
#include <boost/python/detail/api_placeholder.hpp> #include <boost/python/detail/api_placeholder.hpp>
//#include <mapnik.hpp>
void export_color(); void export_color();
void export_layer(); void export_layer();
void export_parameters(); void export_parameters();
@ -49,12 +47,10 @@ void export_raster_symbolizer();
void export_text_symbolizer(); void export_text_symbolizer();
void export_font_engine(); void export_font_engine();
//using namespace mapnik;
#include <map.hpp> #include <map.hpp>
#include <agg_renderer.hpp> #include <agg_renderer.hpp>
#include <graphics.hpp> #include <graphics.hpp>
//#include <filter.hpp> #include <datasource_cache.hpp>
//#include <coord.hpp>
void render_to_file(const mapnik::Map& map, void render_to_file(const mapnik::Map& map,
const std::string& file, const std::string& file,
@ -72,6 +68,25 @@ void render(const mapnik::Map& map,mapnik::Image32& image)
ren.apply(); ren.apply();
} }
namespace
{
//user-friendly wrapper that uses Python dictionary
using namespace boost::python;
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{
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]);
std::string value=extract<std::string>(d[key]);
params[key] = value;
}
return mapnik::datasource_cache::create(params);
}
}
BOOST_PYTHON_MODULE(_mapnik) BOOST_PYTHON_MODULE(_mapnik)
{ {
using namespace boost::python; using namespace boost::python;
@ -87,11 +102,16 @@ BOOST_PYTHON_MODULE(_mapnik)
; ;
class_<datasource,boost::shared_ptr<datasource>, class_<datasource,boost::shared_ptr<datasource>,
boost::noncopyable>("Datasource",no_init) boost::noncopyable>("Datasource",no_init)
.def("envelope",&datasource::envelope, .def("envelope",&datasource::envelope,
return_value_policy<reference_existing_object>()) return_value_policy<reference_existing_object>())
.def("features",&datasource::features) .def("features",&datasource::features)
; .def("params",&datasource::params,return_value_policy<reference_existing_object>(),
"The configuration parameters of the data source. "
"These vary depending on the type of data source.")
;
def("CreateDatasource",&create_datasource);
export_parameters(); export_parameters();
export_color(); export_color();
@ -111,13 +131,14 @@ BOOST_PYTHON_MODULE(_mapnik)
export_raster_symbolizer(); export_raster_symbolizer();
export_text_symbolizer(); export_text_symbolizer();
export_font_engine(); export_font_engine();
class_<coord<double,2> >("Coord",init<double,double>()) class_<coord<double,2> >("Coord",init<double,double>())
.def_readwrite("x", &coord<double,2>::x) .def_readwrite("x", &coord<double,2>::x)
.def_readwrite("y", &coord<double,2>::y) .def_readwrite("y", &coord<double,2>::y)
; ;
export_map(); export_map();
def("render_to_file",&render_to_file); def("render_to_file",&render_to_file);
def("render",&render); def("render",&render);
register_ptr_to_python<filter_ptr>(); register_ptr_to_python<filter_ptr>();

View file

@ -34,13 +34,13 @@ void export_style()
using mapnik::rules; using mapnik::rules;
class_<rules>("Rules",init<>("default ctor")) class_<rules>("Rules",init<>("default ctor"))
.def(vector_indexing_suite<rules>()) .def(vector_indexing_suite<rules>())
; ;
class_<feature_type_style>("Style",init<>("default style constructor")) class_<feature_type_style>("Style",init<>("default style constructor"))
.add_property("rules",make_function .add_property("rules",make_function
(&feature_type_style::get_rules, (&feature_type_style::get_rules,
return_value_policy<reference_existing_object>())) return_value_policy<reference_existing_object>()))
; ;
} }

View file

@ -1,5 +1,13 @@
#include <mapnik.hpp> #include <map.hpp>
#include <datasource_cache.hpp>
#include <font_engine_freetype.hpp>
#include <agg_renderer.hpp>
#include <filter_factory.hpp>
#include <color_factory.hpp>
#include <image_util.hpp>
#include <iostream> #include <iostream>
using namespace mapnik; using namespace mapnik;
@ -133,11 +141,11 @@ int main ( int argc , char** argv)
// Provincial polygons // Provincial polygons
{ {
parameters p; parameters p;
p["name"]="Provinces";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/boundaries"; p["file"]="../data/boundaries";
Layer lyr(p); Layer lyr("Provinces");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provinces"); lyr.add_style("provinces");
m.addLayer(lyr); m.addLayer(lyr);
} }
@ -145,21 +153,21 @@ int main ( int argc , char** argv)
// Drainage // Drainage
{ {
parameters p; parameters p;
p["name"]="Quebec Hydrography";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/qcdrainage"; p["file"]="../data/qcdrainage";
Layer lyr("Quebec Hydrography");
Layer lyr(p); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage"); lyr.add_style("drainage");
m.addLayer(lyr); m.addLayer(lyr);
} }
{ {
parameters p; parameters p;
p["name"]="Ontario Hydrography";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/ontdrainage"; p["file"]="../data/ontdrainage";
Layer lyr(p); Layer lyr("Ontario Hydrography");
lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage"); lyr.add_style("drainage");
m.addLayer(lyr); m.addLayer(lyr);
} }
@ -167,11 +175,10 @@ int main ( int argc , char** argv)
// Provincial boundaries // Provincial boundaries
{ {
parameters p; parameters p;
p["name"]="Provincial borders";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/boundaries_l"; p["file"]="../data/boundaries_l";
Layer lyr("Provincial borders");
Layer lyr(p); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provlines"); lyr.add_style("provlines");
m.addLayer(lyr); m.addLayer(lyr);
} }
@ -179,29 +186,29 @@ int main ( int argc , char** argv)
// Roads // Roads
{ {
parameters p; parameters p;
p["name"]="Roads";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/roads"; p["file"]="../data/roads";
Layer lyr("Roads");
Layer lyr(p); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("smallroads"); lyr.add_style("smallroads");
lyr.add_style("road-border"); lyr.add_style("road-border");
lyr.add_style("road-fill"); lyr.add_style("road-fill");
lyr.add_style("highway-border"); lyr.add_style("highway-border");
lyr.add_style("highway-fill"); lyr.add_style("highway-fill");
m.addLayer(lyr); m.addLayer(lyr);
} }
// popplaces // popplaces
{ {
parameters p; parameters p;
p["name"]="Populated Places";
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/popplaces"; p["file"]="../data/popplaces";
Layer lyr("Populated Places");
Layer lyr(p); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("popplaces"); lyr.add_style("popplaces");
m.addLayer(lyr); m.addLayer(lyr);
} }
m.zoomToBox(Envelope<double>(1405120.04127408,-247003.813399447,1706357.31328276,-25098.593149577)); m.zoomToBox(Envelope<double>(1405120.04127408,-247003.813399447,1706357.31328276,-25098.593149577));
Image32 buf(m.getWidth(),m.getHeight()); Image32 buf(m.getWidth(),m.getHeight());

View file

@ -55,7 +55,8 @@ m.background = Color('white')
# password='mypassword' # password='mypassword'
# table= TODO # table= TODO
provpoly_lyr = Layer(name='Provinces', type='shape', file='../data/boundaries') provpoly_lyr = Layer('Provinces')
provpoly_lyr.datasource = Datasource(type='shape', file='../data/boundaries')
# We then define a style for the layer. A layer can have one or many styles. # 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. # Styles are named, so they can be shared across different layers.
@ -118,8 +119,10 @@ m.layers.append(provpoly_lyr)
# A simple example ... # A simple example ...
qcdrain_lyr = Layer(name='Quebec Hydrography', type='shape', qcdrain_lyr = Layer('Quebec Hydrography')
file='../data/qcdrainage')
qcdrain_lyr.datasource = Datasource( type='shape',
file='../data/qcdrainage')
qcdrain_style = Style() qcdrain_style = Style()
qcdrain_rule = Rule() qcdrain_rule = Rule()
@ -135,15 +138,18 @@ m.layers.append(qcdrain_lyr)
# attributes, and same desired style), so we're going to # attributes, and same desired style), so we're going to
# re-use the style defined in the above layer for the next one. # re-use the style defined in the above layer for the next one.
ondrain_lyr = Layer(name='Ontario Hydrography', type='shape', ondrain_lyr = Layer('Ontario Hydrography')
file='../data/ontdrainage') ondrain_lyr.datasource = Datasource(type='shape',
file='../data/ontdrainage')
ondrain_lyr.styles.append('drainage') ondrain_lyr.styles.append('drainage')
m.layers.append(ondrain_lyr) m.layers.append(ondrain_lyr)
# Provincial boundaries # Provincial boundaries
provlines_lyr = Layer(name='Provincial borders', type='shape', provlines_lyr = Layer('Provincial borders')
file='../data/boundaries_l') provlines_lyr.datasource = Datasource (type='shape',
file='../data/boundaries_l')
# Here we define a "dash dot dot dash" pattern for the provincial boundaries. # Here we define a "dash dot dot dash" pattern for the provincial boundaries.
@ -165,7 +171,8 @@ m.layers.append(provlines_lyr)
# Roads 3 and 4 (The "grey" roads) # Roads 3 and 4 (The "grey" roads)
roads34_lyr = Layer(name='Roads', type='shape', file='../data/roads') roads34_lyr = Layer('Roads')
roads34_lyr.datasource = Datasource(type='shape', file='../data/roads')
roads34_style = Style() roads34_style = Style()
roads34_rule = Rule() roads34_rule = Rule()
@ -195,7 +202,8 @@ m.layers.append(roads34_lyr)
# Roads 2 (The thin yellow ones) # Roads 2 (The thin yellow ones)
roads2_lyr = Layer(name='Roads', type='shape', file='../data/roads') roads2_lyr = Layer('Roads')
roads2_lyr.datasource = Datasource (type='shape', file='../data/roads')
roads2_style_1 = Style() roads2_style_1 = Style()
roads2_rule_1 = Rule() roads2_rule_1 = Rule()
@ -228,7 +236,8 @@ m.layers.append(roads2_lyr)
# Roads 1 (The big orange ones, the highways) # Roads 1 (The big orange ones, the highways)
roads1_lyr = Layer(name='Roads', type='shape', file='../data/roads') roads1_lyr = Layer('Roads')
roads1_lyr.datasource = Datasource(type='shape', file='../data/roads')
roads1_style_1 = Style() roads1_style_1 = Style()
roads1_rule_1 = Rule() roads1_rule_1 = Rule()
@ -260,8 +269,9 @@ m.layers.append(roads1_lyr)
# Populated Places # Populated Places
popplaces_lyr = Layer(name='Populated Places', type='shape', popplaces_lyr = Layer('Populated Places')
file='../data/popplaces') popplaces_lyr.datasource = Datasource (type='shape',
file='../data/popplaces')
popplaces_style = Style() popplaces_style = Style()
popplaces_rule = Rule() popplaces_rule = Rule()

View file

@ -25,6 +25,7 @@
#ifndef COLOR_FACTORY_HPP #ifndef COLOR_FACTORY_HPP
#define COLOR_FACTORY_HPP #define COLOR_FACTORY_HPP
#include "config.hpp"
#include "css_color_parser.hpp" #include "css_color_parser.hpp"
namespace mapnik namespace mapnik
@ -33,19 +34,19 @@ namespace mapnik
class MAPNIK_DECL color_factory class MAPNIK_DECL color_factory
{ {
public: public:
static Color from_string(char const* css_color) static Color from_string(char const* css_color)
{ {
Color color; Color color;
actions<Color> a(color); actions<Color> a(color);
css_color_grammar<actions<Color> > grammar(a); css_color_grammar<actions<Color> > grammar(a);
parse_info<> info = parse(css_color, grammar, space_p); parse_info<> info = parse(css_color, grammar, space_p);
if (info.full) return color; if (info.full) return color;
return Color(0,0,0); return Color(0,0,0);
} }
private: private:
color_factory(); color_factory();
color_factory(color_factory const&); color_factory(color_factory const&);
color_factory& operator=(color_factory const&); color_factory& operator=(color_factory const&);
}; };
} }

View file

@ -35,24 +35,26 @@ namespace mapnik
class MAPNIK_DECL filter_factory class MAPNIK_DECL filter_factory
{ {
public: public:
static filter_ptr compile(string const& str) static filter_ptr compile(string const& str)
{ {
stack<shared_ptr<filter<FeatureT> > > filters; stack<shared_ptr<filter<FeatureT> > > filters;
stack<shared_ptr<expression<FeatureT> > > exps; stack<shared_ptr<expression<FeatureT> > > exps;
filter_grammar<FeatureT> grammar(filters,exps); filter_grammar<FeatureT> grammar(filters,exps);
char const *text = str.c_str(); char const *text = str.c_str();
parse_info<> info = parse(text,text+strlen(text),grammar,space_p); parse_info<> info = parse(text,text+strlen(text),grammar,space_p);
if (info.full && !filters.empty()) if (info.full && !filters.empty())
{ {
return filters.top(); return filters.top();
} }
else else
{ {
clog << "failed at :" << info.stop << "\n"; clog << "failed at :" << info.stop << "\n";
return filter_ptr(new none_filter<FeatureT>()); return filter_ptr(new none_filter<FeatureT>());
} }
} }
}; };
MAPNIK_DECL filter_ptr create_filter (std::string const& wkt);
} }
#endif //FILTER_FACTORY_HPP #endif //FILTER_FACTORY_HPP

View file

@ -42,7 +42,7 @@
#include "expression.hpp" #include "expression.hpp"
#include "filter.hpp" #include "filter.hpp"
#include "regex_filter.hpp" #include "regex_filter.hpp"
#include "logical.hpp"
using namespace boost::spirit; using namespace boost::spirit;
using std::string; using std::string;

View file

@ -15,11 +15,10 @@
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* #include <boost/serialization/serialization.hpp> * License along with this library; if not, write to the Free Software
License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
* *****************************************************************************/
*****************************************************************************/
//$Id: layer.hpp 39 2005-04-10 20:39:53Z pavlenko $ //$Id: layer.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef LAYER_HPP #ifndef LAYER_HPP
@ -34,7 +33,6 @@ namespace mapnik
{ {
class MAPNIK_DECL Layer class MAPNIK_DECL Layer
{ {
parameters params_;
std::string name_; std::string name_;
std::string title_; std::string title_;
std::string abstract_; std::string abstract_;
@ -42,20 +40,18 @@ namespace mapnik
double maxZoom_; double maxZoom_;
bool active_; bool active_;
bool selectable_; bool selectable_;
std::vector<std::string> styles_; std::vector<std::string> styles_;
std::string selection_style_; std::string selection_style_;
mutable std::vector<boost::shared_ptr<Feature> > selection_; mutable std::vector<boost::shared_ptr<Feature> > selection_;
mutable datasource_p ds_; mutable datasource_p ds_;
public: public:
Layer(); explicit Layer(std::string const& name);
explicit Layer(const parameters& params);
Layer(Layer const& l); Layer(Layer const& l);
Layer& operator=(Layer const& l); Layer& operator=(Layer const& l);
bool operator==(Layer const& other) const; bool operator==(Layer const& other) const;
parameters const& params() const;
void set_name(std::string const& name); void set_name(std::string const& name);
const std::string& name() const; const std::string& name() const;
void set_title(std::string const& title); void set_title(std::string const& title);
@ -79,9 +75,9 @@ namespace mapnik
std::vector<boost::shared_ptr<Feature> >& selection() const; std::vector<boost::shared_ptr<Feature> >& selection() const;
void clear_selection() const; void clear_selection() const;
void set_datasource(datasource_p const& ds); void set_datasource(datasource_p const& ds);
datasource_p const& datasource() const; datasource_p datasource() const;
Envelope<double> envelope() const; Envelope<double> envelope() const;
virtual ~Layer(); ~Layer();
private: private:
void swap(const Layer& other); void swap(const Layer& other);
}; };

View file

@ -43,8 +43,8 @@ namespace mapnik
Envelope<double> currentExtent_; Envelope<double> currentExtent_;
public: public:
typedef std::map<std::string,feature_type_style>::const_iterator style_iterator; typedef std::map<std::string,feature_type_style>::const_iterator style_iterator;
Map(); Map();
Map(int width,int height,int srid=-1); Map(int width,int height,int srid=-1);
@ -76,7 +76,7 @@ namespace mapnik
void pan_and_zoom(int x,int y,double zoom); void pan_and_zoom(int x,int y,double zoom);
const Envelope<double>& getCurrentExtent() const; const Envelope<double>& getCurrentExtent() const;
double scale() const; double scale() const;
virtual ~Map(); ~Map();
private: private:
void fixAspectRatio(); void fixAspectRatio();
}; };

View file

@ -1,84 +0,0 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: mapnik.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef MAPNIK_HPP
#define MAPNIK_HPP
#include <map>
#include <vector>
#include <cassert>
#include "global.hpp"
#include "factory.hpp"
#include "filter.hpp"
#include "query.hpp"
#include "rule.hpp"
#include "spatial.hpp"
#include "logical.hpp"
#include "comparison.hpp"
#include "regex_filter.hpp"
#include "utils.hpp"
#include "geometry.hpp"
#include "geom_util.hpp"
#include "raster.hpp"
#include "feature.hpp"
#include "attribute.hpp"
#include "attribute_collector.hpp"
#include "graphics.hpp"
#include "image_reader.hpp"
#include "line_symbolizer.hpp"
#include "polygon_symbolizer.hpp"
#include "agg_renderer.hpp"
#include "polygon_pattern_symbolizer.hpp"
#include "line_pattern_symbolizer.hpp"
#include "point_symbolizer.hpp"
#include "raster_symbolizer.hpp"
#include "text_symbolizer.hpp"
#include "image_util.hpp"
#include "datasource.hpp"
#include "layer.hpp"
#include "datasource_cache.hpp"
#include "wkb.hpp"
#include "map.hpp"
#include "feature_type_style.hpp"
#include "feature_factory.hpp"
#include "math_expr.hpp"
#include "value.hpp"
#include "expression.hpp"
#include "filter_visitor.hpp"
#include "filter_parser.hpp"
#include "filter_factory.hpp"
#include "text_symbolizer.hpp"
#include "label_placement.hpp"
#include "feature_layer_desc.hpp"
#include "css_color_parser.hpp"
#include "color_factory.hpp"
#include "config.hpp"
namespace mapnik
{
MAPNIK_DECL filter_ptr create_filter (std::string const& wkt);
}
#endif //MAPNIK_HPP

View file

@ -32,7 +32,6 @@ linkflags = '-Wl,-rpath-link,. -Wl,-soname,libmapnik.so'
source = Split( source = Split(
""" """
mapnik.cpp
datasource_cache.cpp datasource_cache.cpp
envelope.cpp envelope.cpp
graphics.cpp graphics.cpp

View file

@ -1,4 +1,4 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
@ -75,26 +75,26 @@ namespace mapnik
} }
std::clog<<"datasource="<<ds<<" type="<<type<<std::endl; std::clog<<"datasource="<<ds<<" type="<<type<<std::endl;
} }
catch (datasource_exception& ex) catch (datasource_exception& ex)
{ {
std::clog<<ex.what()<<std::endl; std::clog<<ex.what()<<std::endl;
} }
catch (...) catch (...)
{ {
std::clog<<"exception caught "<<std::endl; std::clog<<" exception caught\n";
} }
return ds; return ds;
} }
bool datasource_cache::insert(const std::string& type,const lt_dlhandle module) bool datasource_cache::insert(const std::string& type,const lt_dlhandle module)
{ {
return plugins_.insert(make_pair(type,boost::shared_ptr<PluginInfo>(new PluginInfo(type,module)))).second; return plugins_.insert(make_pair(type,boost::shared_ptr<PluginInfo>(new PluginInfo(type,module)))).second;
} }
void datasource_cache::register_datasources(const std::string& str) void datasource_cache::register_datasources(const std::string& str)
{ {
mutex::scoped_lock lock(mapnik::singleton<mapnik::datasource_cache, mutex::scoped_lock lock(mapnik::singleton<mapnik::datasource_cache,
mapnik::CreateStatic>::mutex_); mapnik::CreateStatic>::mutex_);
filesystem::path path(str); filesystem::path path(str);
filesystem::directory_iterator end_itr; filesystem::directory_iterator end_itr;
if (exists(path)) if (exists(path))

View file

@ -19,10 +19,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$ //$Id$
#include "mapnik.hpp" #include "filter_factory.hpp"
namespace mapnik namespace mapnik
{ {
@ -32,5 +31,3 @@ namespace mapnik
return factory.compile(wkt); return factory.compile(wkt);
} }
} }

View file

@ -34,9 +34,8 @@
namespace mapnik namespace mapnik
{ {
using namespace std; using namespace std;
Layer::Layer() Layer::Layer(std::string const& name)
: params_(), : name_(name),
name_("unknown"),
title_(""), title_(""),
abstract_(""), abstract_(""),
minZoom_(0), minZoom_(0),
@ -45,31 +44,18 @@ namespace mapnik
selectable_(false), selectable_(false),
selection_style_("default_selection") selection_style_("default_selection")
{} {}
Layer::Layer(const parameters& params)
:params_(params),
name_(params_["name"]),
title_(params_["title"]),
abstract_(params_["abstract"]),
minZoom_(0),
maxZoom_(std::numeric_limits<double>::max()),
active_(true),
selectable_(false),
selection_style_("default_selection")
{}
Layer::Layer(const Layer& rhs) Layer::Layer(const Layer& rhs)
:params_(rhs.params_), : name_(rhs.name_),
name_(rhs.name_), title_(rhs.title_),
title_(rhs.title_), abstract_(rhs.abstract_),
abstract_(rhs.abstract_), minZoom_(rhs.minZoom_),
minZoom_(rhs.minZoom_), maxZoom_(rhs.maxZoom_),
maxZoom_(rhs.maxZoom_), active_(rhs.active_),
active_(rhs.active_), selectable_(rhs.selectable_),
selectable_(rhs.selectable_), styles_(rhs.styles_),
ds_(rhs.ds_), ds_(rhs.ds_),
styles_(rhs.styles_), selection_style_(rhs.selection_style_) {}
selection_style_(rhs.selection_style_) {}
Layer& Layer::operator=(const Layer& rhs) Layer& Layer::operator=(const Layer& rhs)
{ {
@ -85,7 +71,6 @@ namespace mapnik
void Layer::swap(const Layer& rhs) void Layer::swap(const Layer& rhs)
{ {
params_=rhs.params_;
name_=rhs.name_; name_=rhs.name_;
title_=rhs.title_; title_=rhs.title_;
abstract_=rhs.abstract_; abstract_=rhs.abstract_;
@ -93,17 +78,12 @@ namespace mapnik
maxZoom_=rhs.maxZoom_; maxZoom_=rhs.maxZoom_;
active_=rhs.active_; active_=rhs.active_;
selectable_=rhs.selectable_; selectable_=rhs.selectable_;
ds_=rhs.ds_;
styles_=rhs.styles_; styles_=rhs.styles_;
ds_=rhs.ds_;
selection_style_=rhs.selection_style_; selection_style_=rhs.selection_style_;
} }
Layer::~Layer() {} Layer::~Layer() {}
parameters const& Layer::params() const
{
return params_;
}
void Layer::set_name( std::string const& name) void Layer::set_name( std::string const& name)
{ {
@ -124,7 +104,7 @@ namespace mapnik
{ {
return title_; return title_;
} }
void Layer::set_abstract( std::string const& abstract) void Layer::set_abstract( std::string const& abstract)
{ {
abstract_ = abstract; abstract_ = abstract;
@ -190,22 +170,11 @@ namespace mapnik
return selectable_; return selectable_;
} }
const datasource_p& Layer::datasource() const datasource_p Layer::datasource() const
{ {
if (!ds_)
{
try
{
ds_=datasource_cache::instance()->create(params_);
}
catch (...)
{
std::clog << "exception caught : can not create datasource" << std::endl;
}
}
return ds_; return ds_;
} }
// TODO: !!!!
void Layer::set_datasource(datasource_p const& ds) void Layer::set_datasource(datasource_p const& ds)
{ {
ds_ = ds; ds_ = ds;
@ -213,14 +182,10 @@ namespace mapnik
Envelope<double> Layer::envelope() const Envelope<double> Layer::envelope() const
{ {
datasource_p const& ds = datasource(); if (ds_) return ds_->envelope();
if (ds)
{
return ds->envelope();
}
return Envelope<double>(); return Envelope<double>();
} }
void Layer::selection_style(const std::string& name) void Layer::selection_style(const std::string& name)
{ {
selection_style_=name; selection_style_=name;

View file

@ -251,6 +251,6 @@ namespace mapnik
return currentExtent_.width()/width_; return currentExtent_.width()/width_;
return currentExtent_.width(); return currentExtent_.width();
} }
Map::~Map() {} Map::~Map() {}
} }