add a method to get simple dictionary of feature attributes, remove old/deprecated feature access
This commit is contained in:
parent
aa6da2dce9
commit
803a705774
2 changed files with 15 additions and 42 deletions
|
@ -247,44 +247,6 @@ class _Datasource(Datasource,_injector):
|
|||
query.add_property_name(fld)
|
||||
return self.features(query)
|
||||
|
||||
class _DeprecatedFeatureProperties(object):
|
||||
|
||||
def __init__(self, feature):
|
||||
self._feature = feature
|
||||
|
||||
def __getitem__(self, name):
|
||||
warnings.warn("indexing feature.properties is deprecated, index the "
|
||||
"feature object itself for the same effect", DeprecationWarning, 2)
|
||||
return self._feature[name]
|
||||
|
||||
def __iter__(self):
|
||||
warnings.warn("iterating feature.properties is deprecated, iterate the "
|
||||
"feature object itself for the same effect", DeprecationWarning, 2)
|
||||
return iter(self._feature)
|
||||
|
||||
class _Feature(Feature, _injector):
|
||||
"""
|
||||
A Feature.
|
||||
|
||||
TODO: docs
|
||||
"""
|
||||
@property
|
||||
def properties(self):
|
||||
return _DeprecatedFeatureProperties(self)
|
||||
|
||||
@property
|
||||
def attributes(self):
|
||||
#XXX Returns a copy! changes to it won't affect feat.'s attrs.
|
||||
# maybe deprecate?
|
||||
return dict(self)
|
||||
|
||||
def __init__(self, ctx, id, wkt=None, **properties):
|
||||
Feature._c___init__(self, ctx, id)
|
||||
if wkt is not None:
|
||||
self.add_geometries_from_wkt(wkt)
|
||||
for k, v in properties.iteritems():
|
||||
self[k] = v
|
||||
|
||||
class _Color(Color,_injector):
|
||||
def __repr__(self):
|
||||
return "Color(R=%d,G=%d,B=%d,A=%d)" % (self.r,self.g,self.b,self.a)
|
||||
|
|
|
@ -78,12 +78,22 @@ void __setitem__(Feature & feature, std::string const& name, mapnik::value const
|
|||
feature.put(name,val);
|
||||
}
|
||||
|
||||
boost::python::dict describe(Feature const& feature)
|
||||
{
|
||||
boost::python::dict attributes;
|
||||
feature_kv_iterator itr(feature,true);
|
||||
feature_kv_iterator end(feature);
|
||||
|
||||
for ( ;itr!=end; ++itr)
|
||||
{
|
||||
attributes[boost::get<0>(*itr)] = boost::get<1>(*itr);
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
}}
|
||||
|
||||
struct UnicodeString_from_python_str
|
||||
{
|
||||
UnicodeString_from_python_str()
|
||||
|
@ -168,6 +178,7 @@ void export_feature()
|
|||
.def("geometries",make_function(get_paths_by_const_ref,return_value_policy<reference_existing_object>()))
|
||||
.def("envelope", &Feature::envelope)
|
||||
.def("has_key", &Feature::has_key)
|
||||
.def("describe",&describe)
|
||||
.def("__setitem__",&__setitem__)
|
||||
.def("__getitem__",&__getitem__)
|
||||
.def("__getitem__",&__getitem2__)
|
||||
|
|
Loading…
Add table
Reference in a new issue