+ 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_cache.hpp>
|
||||
#include <mapnik/feature_layer_desc.hpp>
|
||||
#include <mapnik/memory_datasource.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -83,6 +84,7 @@ void export_datasource()
|
|||
{
|
||||
using namespace boost::python;
|
||||
using mapnik::datasource;
|
||||
using mapnik::point_datasource;
|
||||
|
||||
class_<datasource,boost::shared_ptr<datasource>,
|
||||
boost::noncopyable>("Datasource",no_init)
|
||||
|
@ -97,4 +99,8 @@ void export_datasource()
|
|||
|
||||
def("Describe",&describe);
|
||||
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
|
||||
#include <mapnik/feature.hpp>
|
||||
|
||||
mapnik::geometry2d & (mapnik::Feature::*get_geom1)(unsigned) = &mapnik::Feature::get_geometry;
|
||||
|
||||
namespace boost { namespace python {
|
||||
struct value_converter : public boost::static_visitor<PyObject*>
|
||||
{
|
||||
|
@ -206,6 +208,9 @@ void export_feature()
|
|||
.def("__str__",&Feature::to_string)
|
||||
.add_property("properties",
|
||||
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")
|
||||
|
|
|
@ -33,13 +33,13 @@ namespace {
|
|||
|
||||
inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr)
|
||||
{
|
||||
mapnik::feature_ptr f = itr->next();
|
||||
if (!f)
|
||||
if (!itr)
|
||||
{
|
||||
PyErr_SetString(PyExc_StopIteration, "No more features.");
|
||||
boost::python::throw_error_already_set();
|
||||
}
|
||||
return f;
|
||||
|
||||
return itr->next();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ void export_filter()
|
|||
class_<filter<Feature>,boost::noncopyable>("Filter",
|
||||
"An expression which allows "
|
||||
"to select features.",no_init)
|
||||
.def("passes", &filter<Feature>::pass) // note: "pass" is a reserved word in Python
|
||||
.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_envelope();
|
||||
void export_query();
|
||||
void export_geometry();
|
||||
void export_image();
|
||||
void export_image_view();
|
||||
void export_map();
|
||||
|
@ -160,6 +161,7 @@ BOOST_PYTHON_MODULE(_mapnik)
|
|||
register_exception_translator<mapnik::config_error>(translator);
|
||||
register_cairo();
|
||||
export_query();
|
||||
export_geometry();
|
||||
export_feature();
|
||||
export_featureset();
|
||||
export_datasource();
|
||||
|
|
|
@ -23,11 +23,23 @@
|
|||
|
||||
#include <boost/python.hpp>
|
||||
#include <mapnik/query.hpp>
|
||||
#include <mapnik/envelope.hpp>
|
||||
|
||||
void export_query()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
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 {
|
||||
std::cout << " running demo ... \n";
|
||||
std::string mapnik_dir(argv[1]);
|
||||
datasource_cache::instance()->register_datasources(mapnik_dir + "/lib/mapnik/input/");
|
||||
freetype_engine::register_font(mapnik_dir + "/lib/mapnik/fonts/DejaVuSans.ttf");
|
||||
datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/shape");
|
||||
freetype_engine::register_font(mapnik_dir + "/fonts/dejavu-ttf-2.14/DejaVuSans.ttf");
|
||||
|
||||
Map m(800,600);
|
||||
m.set_background(color_factory::from_string("white"));
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define MEMORY_DATASOURCE_HPP
|
||||
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/feature_factory.hpp> // TODO remove
|
||||
#include <vector>
|
||||
|
||||
namespace mapnik {
|
||||
|
@ -46,6 +47,29 @@ namespace mapnik {
|
|||
private:
|
||||
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
|
||||
|
|
|
@ -41,17 +41,18 @@ namespace mapnik {
|
|||
|
||||
feature_ptr next()
|
||||
{
|
||||
/*
|
||||
while (pos_ != end_)
|
||||
{
|
||||
geometry_ptr geom = (*pos_)->get_geometry();
|
||||
if (geom && bbox_.intersects(geom->envelope()))
|
||||
for (unsigned i=0; i<(*pos_)->num_geometries();++i) {
|
||||
geometry2d & geom = (*pos_)->get_geometry(i);
|
||||
if (bbox_.intersects(geom.envelope()))
|
||||
{
|
||||
return *pos_++;
|
||||
}
|
||||
}
|
||||
++pos_;
|
||||
}
|
||||
*/
|
||||
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue