Ticket #113: python_point_datasource.patch
| File python_point_datasource.patch, 9.4 kB (added by lwu, 18 months ago) |
|---|
-
include/mapnik/memory_featureset.hpp
41 41 42 42 feature_ptr next() 43 43 { 44 /*45 44 while (pos_ != end_) 46 45 { 47 geometry_ptr geom = (*pos_)->get_geometry(); 48 if (geom && bbox_.intersects(geom->envelope())) 49 { 50 return *pos_++; 46 for (unsigned i=0; i<(*pos_)->num_geometries();++i) { 47 geometry2d & geom = (*pos_)->get_geometry(i); 48 if (bbox_.intersects(geom.envelope())) 49 { 50 return *pos_++; 51 } 51 52 } 52 53 ++pos_; 53 54 } 54 */55 55 56 return feature_ptr(); 56 57 } 57 58 -
include/mapnik/memory_datasource.hpp
26 26 #define MEMORY_DATASOURCE_HPP 27 27 28 28 #include <mapnik/datasource.hpp> 29 #include <mapnik/feature_factory.hpp> // TODO remove 29 30 #include <vector> 30 31 31 32 namespace mapnik { … … 46 47 private: 47 48 std::vector<mapnik::feature_ptr> features_; 48 49 }; 50 51 // This class implements a simple way of displaying point-based data 52 // TODO -- possible redesign, move into separate file 53 // 54 class point_datasource : public mapnik::memory_datasource { 55 public: 56 point_datasource() : feat_id(0) {} 57 void add_point(double x, double y, const char* key, const char* value) { 58 mapnik::feature_ptr feature(mapnik::feature_factory::create(feat_id++)); 59 mapnik::geometry2d * pt = new mapnik::point_impl; 60 pt->move_to(x,y); 61 feature->add_geometry(pt); 62 mapnik::transcoder tr("utf-8"); 63 (*feature)[key] = tr.transcode(value); 64 this->push(feature); 65 } 66 int type() const { return mapnik::datasource::Raster; } 67 68 private: 69 int feat_id; 70 }; 71 49 72 } 50 73 51 74 #endif // MEMORY_DATASOURCE_HPP -
demo/c++/rundemo.cpp
48 48 try { 49 49 std::cout << " running demo ... \n"; 50 50 std::string mapnik_dir(argv[1]); 51 datasource_cache::instance()->register_datasources(mapnik_dir + "/ lib/mapnik/input/");52 freetype_engine::register_font(mapnik_dir + "/ lib/mapnik/fonts/DejaVuSans.ttf");51 datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/shape"); 52 freetype_engine::register_font(mapnik_dir + "/fonts/dejavu-ttf-2.14/DejaVuSans.ttf"); 53 53 54 54 Map m(800,600); 55 55 m.set_background(color_factory::from_string("white")); -
bindings/python/mapnik_query.cpp
23 23 24 24 #include <boost/python.hpp> 25 25 #include <mapnik/query.hpp> 26 #include <mapnik/envelope.hpp> 26 27 27 28 void export_query() 28 29 { 30 using namespace boost::python; 31 29 32 using mapnik::query; 30 //class_<query>("Query",init< 33 using mapnik::Envelope; 34 35 class_<query>("Query", "a spatial query data object", 36 init<Envelope<double>,double>() ) 37 .add_property("resolution", &query::resolution) 38 .add_property("bbox", make_function(&query::get_bbox, 39 return_value_policy<copy_const_reference>()) ) 40 .add_property("property_names", make_function(&query::property_names, 41 return_value_policy<copy_const_reference>()) ) 42 .def("add_property_name", &query::add_property_name); 31 43 } 32 44 33 45 -
bindings/python/mapnik_featureset.cpp
33 33 34 34 inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr) 35 35 { 36 mapnik::feature_ptr f = itr->next(); 37 if (!f) 36 if (!itr) 38 37 { 39 38 PyErr_SetString(PyExc_StopIteration, "No more features."); 40 39 boost::python::throw_error_already_set(); 41 40 } 42 return f; 41 42 return itr->next(); 43 43 } 44 44 } 45 45 -
bindings/python/mapnik_python.cpp
33 33 void export_parameters(); 34 34 void export_envelope(); 35 35 void export_query(); 36 void export_geometry(); 36 37 void export_image(); 37 38 void export_image_view(); 38 39 void export_map(); … … 151 152 152 153 register_exception_translator<mapnik::config_error>(translator); 153 154 register_cairo(); 154 export_query(); 155 export_query(); 156 export_geometry(); 155 157 export_feature(); 156 158 export_featureset(); 157 159 export_datasource(); -
bindings/python/mapnik_datasource.cpp
30 30 #include <mapnik/datasource.hpp> 31 31 #include <mapnik/datasource_cache.hpp> 32 32 #include <mapnik/feature_layer_desc.hpp> 33 #include <mapnik/memory_datasource.hpp> 33 34 34 35 namespace 35 36 { … … 83 84 { 84 85 using namespace boost::python; 85 86 using mapnik::datasource; 87 using mapnik::point_datasource; 86 88 87 89 class_<datasource,boost::shared_ptr<datasource>, 88 90 boost::noncopyable>("Datasource",no_init) … … 97 99 98 100 def("Describe",&describe); 99 101 def("CreateDatasource",&create_datasource); 102 103 class_<point_datasource, bases<datasource>, boost::noncopyable>("PointDatasource", init<>()) 104 .def("add_point",&point_datasource::add_point) 105 ; 100 106 } -
bindings/python/mapnik_geometry.cpp
1 /***************************************************************************** 2 * 3 * This file is part of Mapnik (c++ mapping toolkit) 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 *****************************************************************************/ 20 //$Id$ 21 22 // boost 23 #include <boost/python.hpp> 24 #include <boost/python/def.hpp> 25 26 // mapnik 27 #include <mapnik/geometry.hpp> 28 29 void export_geometry() 30 { 31 using namespace boost::python; 32 using mapnik::geometry2d; 33 34 class_<geometry2d, boost::noncopyable>("Geometry2d",no_init) 35 .def("envelope",&geometry2d::envelope) 36 // .def("__str__",&geometry2d::to_string) 37 .def("type",&geometry2d::type) 38 // TODO add other geometry2d methods 39 ; 40 } -
bindings/python/mapnik_filter.cpp
47 47 class_<filter<Feature>,boost::noncopyable>("Filter", 48 48 "An expression which allows " 49 49 "to select features.",no_init) 50 .def("passes", &filter<Feature>::pass) // note: "pass" is a reserved word in Python 50 51 .def("__str__",&filter<Feature>::to_string); 51 52 ; 52 53 -
bindings/python/mapnik_feature.cpp
30 30 // mapnik 31 31 #include <mapnik/feature.hpp> 32 32 33 mapnik::geometry2d & (mapnik::Feature::*get_geom1)(unsigned) = &mapnik::Feature::get_geometry; 34 33 35 namespace boost { namespace python { 34 36 struct value_converter : public boost::static_visitor<PyObject*> 35 37 { … … 206 208 .def("__str__",&Feature::to_string) 207 209 .add_property("properties", 208 210 make_function(&Feature::props,return_value_policy<reference_existing_object>())) 211 // .def("add_geometry", // TODO define more mapnik::Feature methods 212 .def("num_geometries",&Feature::num_geometries) 213 .def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>())) 209 214 ; 210 215 211 216 class_<std::map<std::string, mapnik::value> >("Properties")
