~ubuntu-branches/ubuntu/trusty/mapnik/trusty-proposed

« back to all changes in this revision

Viewing changes to bindings/python/mapnik_datasource.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2009-08-27 00:28:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090827002837-ztqzfg2rmclfh4i9
Tags: 0.6.1-0ubuntu1
* New upstream release.
* Change usr/lib to usr/lib* to enable build on 64 bits systems due to new
  configuration in SConstruct in :
  - debian/libmapnik-dev.install
  - debian/libmapnik0.6.install
  - debian/mapnik-plugin-base

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <boost/python/detail/api_placeholder.hpp>
26
26
// stl
27
27
#include <sstream>
 
28
#include <vector>
 
29
 
28
30
// mapnik
29
31
#include <mapnik/envelope.hpp>
30
32
#include <mapnik/datasource.hpp>
35
37
 
36
38
using mapnik::datasource;
37
39
using mapnik::point_datasource;
38
 
 
39
 
struct ds_pickle_suite : boost::python::pickle_suite
40
 
{
41
 
   static boost::python::tuple
42
 
   getinitargs(const datasource& ds)
43
 
   {
44
 
      mapnik::parameters params = ds.params();
45
 
      return boost::python::make_tuple(params);
46
 
   }
47
 
};
 
40
using mapnik::layer_descriptor;
 
41
using mapnik::attribute_descriptor;
48
42
 
49
43
namespace  
50
44
{
92
86
        }
93
87
        return ss.str();
94
88
    }
95
 
}
 
89
    
 
90
    std::string encoding(boost::shared_ptr<mapnik::datasource> const& ds)
 
91
    {
 
92
            layer_descriptor ld = ds->get_descriptor();
 
93
            return ld.get_encoding();
 
94
    }
 
95
 
 
96
    std::string name(boost::shared_ptr<mapnik::datasource> const& ds)
 
97
    {
 
98
            layer_descriptor ld = ds->get_descriptor();
 
99
            return ld.get_name();
 
100
    }
 
101
 
 
102
    boost::python::list fields(boost::shared_ptr<mapnik::datasource> const& ds)
 
103
    {
 
104
        boost::python::list flds;
 
105
        if (ds)
 
106
        {
 
107
            layer_descriptor ld = ds->get_descriptor();
 
108
            std::vector<attribute_descriptor> const& desc_ar = ld.get_descriptors();
 
109
            std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin();
 
110
            std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
 
111
            for (; it != end; ++it)
 
112
            {
 
113
               flds.append(it->get_name());
 
114
            }
 
115
        }
 
116
        return flds;
 
117
    }
 
118
    boost::python::list field_types(boost::shared_ptr<mapnik::datasource> const& ds)
 
119
    {
 
120
        boost::python::list fld_types;
 
121
        if (ds)
 
122
        {
 
123
            layer_descriptor ld = ds->get_descriptor();
 
124
            std::vector<attribute_descriptor> const& desc_ar = ld.get_descriptors();
 
125
            std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin();
 
126
            std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
 
127
            for (; it != end; ++it)
 
128
            {  
 
129
               unsigned type = it->get_type();
 
130
               fld_types.append(type);
 
131
            }
 
132
        }
 
133
        return fld_types;
 
134
    }}
96
135
 
97
136
void export_datasource()
98
137
{
100
139
    
101
140
    class_<datasource,boost::shared_ptr<datasource>,
102
141
        boost::noncopyable>("Datasource",no_init)
103
 
        .def_pickle(ds_pickle_suite())
104
142
        .def("envelope",&datasource::envelope)
105
143
        .def("descriptor",&datasource::get_descriptor) //todo
106
144
        .def("features",&datasource::features)
 
145
        .def("fields",&fields)
 
146
        .def("_field_types",&field_types)
 
147
        .def("encoding",&encoding) //todo expose as property
 
148
        .def("name",&name)
107
149
        .def("features_at_point",&datasource::features_at_point)
108
150
        .def("params",&datasource::params,return_value_policy<copy_const_reference>(), 
109
151
             "The configuration parameters of the data source. "