Skip to content

Commit 1a4337f

Browse files
committed
implemnent Iterator interface for Featureset object, remove inefficient features method
1 parent 8eb8cc7 commit 1a4337f

3 files changed

Lines changed: 19 additions & 37 deletions

File tree

mapnik/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,20 @@ class _Geometry(Geometry, _injector):
278278

279279
class _Datasource(Datasource, _injector):
280280

281-
def featureset(self, fields=None, variables={}):
281+
def featureset(self, fields = None, variables = {}):
282282
query = Query(self.envelope())
283283
query.set_variables(variables)
284284
attributes = fields or self.fields()
285285
for fld in attributes:
286286
query.add_property_name(fld)
287287
return self.features(query)
288288

289+
def __iter__(self, fields = None, variables = {}):
290+
return self.featureset(fields, variables)
291+
# backward caps helper
289292
def all_features(self, fields=None, variables={}):
290-
return self.featureset(fields, variables).features
293+
return self.__iter__(fields, variables)
294+
291295

292296
class _Color(Color, _injector):
293297

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def run(self):
116116
linkflags.extend(check_output([mapnik_config, '--ldflags']).split(' '))
117117
linkflags.extend(check_output([mapnik_config, '--dep-libs']).split(' '))
118118
linkflags.extend([
119-
'-lmapnik',
120119
'-lmapnik-wkt',
121120
'-lmapnik-json',
122121
] + ['-l%s' % i for i in get_boost_library_names()])
@@ -231,17 +230,19 @@ def run(self):
231230
if os.environ.get("PYCAIRO", "false") == "true":
232231
try:
233232
extra_comp_args.append('-DHAVE_PYCAIRO')
234-
extra_comp_args.extend(check_output(["pkg-config", '--cflags', 'pycairo']).strip().split(' '))
235-
linkflags.extend(check_output(["pkg-config", '--libs', 'pycairo']).strip().split(' '))
233+
print("-I%s/include/pycairo".format(sys.exec_prefix))
234+
extra_comp_args.append("-I{0}/include/pycairo".format(sys.exec_prefix))
235+
#extra_comp_args.extend(check_output(["pkg-config", '--cflags', 'pycairo']).strip().split(' '))
236+
#linkflags.extend(check_output(["pkg-config", '--libs', 'pycairo']).strip().split(' '))
236237
except:
237238
raise Exception("Failed to find compiler options for pycairo")
238239

239240
if sys.platform == 'darwin':
240-
extra_comp_args.append('-mmacosx-version-min=10.8')
241+
extra_comp_args.append('-mmacosx-version-min=10.11')
241242
# silence warning coming from boost python macros which
242243
# would is hard to silence via pragma
243244
extra_comp_args.append('-Wno-parentheses-equality')
244-
linkflags.append('-mmacosx-version-min=10.8')
245+
linkflags.append('-mmacosx-version-min=10.11')
245246
else:
246247
linkflags.append('-lrt')
247248
linkflags.append('-Wl,-z,origin')

src/mapnik_featureset.cpp

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,6 @@
3636
namespace {
3737
using namespace boost::python;
3838

39-
inline list features(mapnik::featureset_ptr const& itr)
40-
{
41-
list l;
42-
while (true)
43-
{
44-
mapnik::feature_ptr fp = itr->next();
45-
if (!fp)
46-
{
47-
break;
48-
}
49-
l.append(fp);
50-
}
51-
return l;
52-
}
53-
5439
inline object pass_through(object const& o) { return o; }
5540

5641
inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr)
@@ -70,20 +55,12 @@ inline mapnik::feature_ptr next(mapnik::featureset_ptr const& itr)
7055
void export_featureset()
7156
{
7257
using namespace boost::python;
73-
class_<mapnik::Featureset,std::shared_ptr<mapnik::Featureset>,
74-
boost::noncopyable>("Featureset",no_init)
75-
.def("__iter__",pass_through)
76-
.def("next",next)
77-
.add_property("features",features,
78-
"The list of features.\n"
79-
"\n"
80-
"Usage:\n"
81-
">>> m.query_map_point(0, 10, 10)\n"
82-
"<mapnik._mapnik.Featureset object at 0x1004d2938>\n"
83-
">>> fs = m.query_map_point(0, 10, 10)\n"
84-
">>> for f in fs.features:\n"
85-
">>> print f\n"
86-
"<mapnik.Feature object at 0x105e64140>\n"
87-
)
58+
// Featureset implements Python iterator interface
59+
class_<mapnik::Featureset, std::shared_ptr<mapnik::Featureset>,
60+
boost::noncopyable>("Featureset", no_init)
61+
.def("__iter__", pass_through)
62+
.def("__next__", next)
63+
// Python2 support
64+
.def("next", next)
8865
;
8966
}

0 commit comments

Comments
 (0)