+ applied python_point_datasource.patch from lwu
This commit is contained in:
parent
a11cc119e4
commit
9a75034a88
10 changed files with 120 additions and 29 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <mapnik/datasource.hpp>
|
#include <mapnik/datasource.hpp>
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#include <mapnik/feature_layer_desc.hpp>
|
#include <mapnik/feature_layer_desc.hpp>
|
||||||
|
#include <mapnik/memory_datasource.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -83,6 +84,7 @@ void export_datasource()
|
||||||
{
|
{
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
using mapnik::datasource;
|
using mapnik::datasource;
|
||||||
|
using mapnik::point_datasource;
|
||||||
|
|
||||||
class_<datasource,boost::shared_ptr<datasource>,
|
class_<datasource,boost::shared_ptr<datasource>,
|
||||||
boost::noncopyable>("Datasource",no_init)
|
boost::noncopyable>("Datasource",no_init)
|
||||||
|
@ -97,4 +99,8 @@ void export_datasource()
|
||||||
|
|
||||||
def("Describe",&describe);
|
def("Describe",&describe);
|
||||||
def("CreateDatasource",&create_datasource);
|
def("CreateDatasource",&create_datasource);
|
||||||
|
|
||||||
|
class_<point_datasource, bases<datasource>, boost::noncopyable>("PointDatasource", init<>())
|
||||||
|
.def("add_point",&point_datasource::add_point)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/feature.hpp>
|
#include <mapnik/feature.hpp>
|
||||||
|
|
||||||
|
mapnik::geometry2d & (mapnik::Feature::*get_geom1)(unsigned) = &mapnik::Feature::get_geometry;
|
||||||
|
|
||||||
namespace boost { namespace python {
|
namespace boost { namespace python {
|
||||||
struct value_converter : public boost::static_visitor<PyObject*>
|
struct value_converter : public boost::static_visitor<PyObject*>
|
||||||
{
|
{
|
||||||
|
@ -206,6 +208,9 @@ void export_feature()
|
||||||
.def("__str__",&Feature::to_string)
|
.def("__str__",&Feature::to_string)
|
||||||
.add_property("properties",
|
.add_property("properties",
|
||||||
make_function(&Feature::props,return_value_policy<reference_existing_object>()))
|
make_function(&Feature::props,return_value_policy<reference_existing_object>()))
|
||||||
|
// .def("add_geometry", // TODO define more mapnik::Feature methods
|
||||||
|
.def("num_geometries",&Feature::num_geometries)
|
||||||
|
.def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>()))
|
||||||
;
|
;
|
||||||
|
|
||||||
class_<std::map<std::string, mapnik::value> >("Properties")
|
class_<std::map<std::string, mapnik::value> >("Properties")
|
||||||
|
|
|
@ -33,13 +33,13 @@ namespace {
|
||||||
|
|
||||||
inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr)
|
inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr)
|
||||||
{
|
{
|
||||||
mapnik::feature_ptr f = itr->next();
|
if (!itr)
|
||||||
if (!f)
|
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_StopIteration, "No more features.");
|
PyErr_SetString(PyExc_StopIteration, "No more features.");
|
||||||
boost::python::throw_error_already_set();
|
boost::python::throw_error_already_set();
|
||||||
}
|
}
|
||||||
return f;
|
|
||||||
|
return itr->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ void export_filter()
|
||||||
class_<filter<Feature>,boost::noncopyable>("Filter",
|
class_<filter<Feature>,boost::noncopyable>("Filter",
|
||||||
"An expression which allows "
|
"An expression which allows "
|
||||||
"to select features.",no_init)
|
"to select features.",no_init)
|
||||||
|
.def("passes", &filter<Feature>::pass) // note: "pass" is a reserved word in Python
|
||||||
.def("__str__",&filter<Feature>::to_string);
|
.def("__str__",&filter<Feature>::to_string);
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
40
bindings/python/mapnik_geometry.cpp
Normal file
40
bindings/python/mapnik_geometry.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
|
*
|
||||||
|
* 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$
|
||||||
|
|
||||||
|
// boost
|
||||||
|
#include <boost/python.hpp>
|
||||||
|
#include <boost/python/def.hpp>
|
||||||
|
|
||||||
|
// mapnik
|
||||||
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
|
void export_geometry()
|
||||||
|
{
|
||||||
|
using namespace boost::python;
|
||||||
|
using mapnik::geometry2d;
|
||||||
|
|
||||||
|
class_<geometry2d, boost::noncopyable>("Geometry2d",no_init)
|
||||||
|
.def("envelope",&geometry2d::envelope)
|
||||||
|
// .def("__str__",&geometry2d::to_string)
|
||||||
|
.def("type",&geometry2d::type)
|
||||||
|
// TODO add other geometry2d methods
|
||||||
|
;
|
||||||
|
}
|
|
@ -33,6 +33,7 @@ void export_layer();
|
||||||
void export_parameters();
|
void export_parameters();
|
||||||
void export_envelope();
|
void export_envelope();
|
||||||
void export_query();
|
void export_query();
|
||||||
|
void export_geometry();
|
||||||
void export_image();
|
void export_image();
|
||||||
void export_image_view();
|
void export_image_view();
|
||||||
void export_map();
|
void export_map();
|
||||||
|
@ -160,6 +161,7 @@ BOOST_PYTHON_MODULE(_mapnik)
|
||||||
register_exception_translator<mapnik::config_error>(translator);
|
register_exception_translator<mapnik::config_error>(translator);
|
||||||
register_cairo();
|
register_cairo();
|
||||||
export_query();
|
export_query();
|
||||||
|
export_geometry();
|
||||||
export_feature();
|
export_feature();
|
||||||
export_featureset();
|
export_featureset();
|
||||||
export_datasource();
|
export_datasource();
|
||||||
|
|
|
@ -23,11 +23,23 @@
|
||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#include <mapnik/query.hpp>
|
#include <mapnik/query.hpp>
|
||||||
|
#include <mapnik/envelope.hpp>
|
||||||
|
|
||||||
void export_query()
|
void export_query()
|
||||||
{
|
{
|
||||||
|
using namespace boost::python;
|
||||||
|
|
||||||
using mapnik::query;
|
using mapnik::query;
|
||||||
//class_<query>("Query",init<
|
using mapnik::Envelope;
|
||||||
|
|
||||||
|
class_<query>("Query", "a spatial query data object",
|
||||||
|
init<Envelope<double>,double>() )
|
||||||
|
.add_property("resolution", &query::resolution)
|
||||||
|
.add_property("bbox", make_function(&query::get_bbox,
|
||||||
|
return_value_policy<copy_const_reference>()) )
|
||||||
|
.add_property("property_names", make_function(&query::property_names,
|
||||||
|
return_value_policy<copy_const_reference>()) )
|
||||||
|
.def("add_property_name", &query::add_property_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ int main ( int argc , char** argv)
|
||||||
try {
|
try {
|
||||||
std::cout << " running demo ... \n";
|
std::cout << " running demo ... \n";
|
||||||
std::string mapnik_dir(argv[1]);
|
std::string mapnik_dir(argv[1]);
|
||||||
datasource_cache::instance()->register_datasources(mapnik_dir + "/lib/mapnik/input/");
|
datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/shape");
|
||||||
freetype_engine::register_font(mapnik_dir + "/lib/mapnik/fonts/DejaVuSans.ttf");
|
freetype_engine::register_font(mapnik_dir + "/fonts/dejavu-ttf-2.14/DejaVuSans.ttf");
|
||||||
|
|
||||||
Map m(800,600);
|
Map m(800,600);
|
||||||
m.set_background(color_factory::from_string("white"));
|
m.set_background(color_factory::from_string("white"));
|
||||||
|
|
|
@ -26,26 +26,50 @@
|
||||||
#define MEMORY_DATASOURCE_HPP
|
#define MEMORY_DATASOURCE_HPP
|
||||||
|
|
||||||
#include <mapnik/datasource.hpp>
|
#include <mapnik/datasource.hpp>
|
||||||
|
#include <mapnik/feature_factory.hpp> // TODO remove
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
class memory_datasource : public datasource
|
class memory_datasource : public datasource
|
||||||
{
|
{
|
||||||
friend class memory_featureset;
|
friend class memory_featureset;
|
||||||
public:
|
public:
|
||||||
memory_datasource();
|
memory_datasource();
|
||||||
virtual ~memory_datasource();
|
virtual ~memory_datasource();
|
||||||
void push(feature_ptr feature);
|
void push(feature_ptr feature);
|
||||||
int type() const;
|
int type() const;
|
||||||
featureset_ptr features(const query& q) const;
|
featureset_ptr features(const query& q) const;
|
||||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||||
Envelope<double> envelope() const;
|
Envelope<double> envelope() const;
|
||||||
layer_descriptor get_descriptor() const;
|
layer_descriptor get_descriptor() const;
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
private:
|
private:
|
||||||
std::vector<mapnik::feature_ptr> features_;
|
std::vector<mapnik::feature_ptr> features_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This class implements a simple way of displaying point-based data
|
||||||
|
// TODO -- possible redesign, move into separate file
|
||||||
|
//
|
||||||
|
|
||||||
|
class point_datasource : public mapnik::memory_datasource {
|
||||||
|
public:
|
||||||
|
point_datasource() : feat_id(0) {}
|
||||||
|
void add_point(double x, double y, const char* key, const char* value) {
|
||||||
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(feat_id++));
|
||||||
|
mapnik::geometry2d * pt = new mapnik::point_impl;
|
||||||
|
pt->move_to(x,y);
|
||||||
|
feature->add_geometry(pt);
|
||||||
|
mapnik::transcoder tr("utf-8");
|
||||||
|
(*feature)[key] = tr.transcode(value);
|
||||||
|
this->push(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
int type() const { return mapnik::datasource::Vector; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int feat_id;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MEMORY_DATASOURCE_HPP
|
#endif // MEMORY_DATASOURCE_HPP
|
||||||
|
|
|
@ -41,17 +41,18 @@ namespace mapnik {
|
||||||
|
|
||||||
feature_ptr next()
|
feature_ptr next()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
while (pos_ != end_)
|
while (pos_ != end_)
|
||||||
{
|
{
|
||||||
geometry_ptr geom = (*pos_)->get_geometry();
|
for (unsigned i=0; i<(*pos_)->num_geometries();++i) {
|
||||||
if (geom && bbox_.intersects(geom->envelope()))
|
geometry2d & geom = (*pos_)->get_geometry(i);
|
||||||
{
|
if (bbox_.intersects(geom.envelope()))
|
||||||
return *pos_++;
|
{
|
||||||
|
return *pos_++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++pos_;
|
++pos_;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return feature_ptr();
|
return feature_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue