本文整理汇总了Python中schema.Schema.__iter__方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.__iter__方法的具体用法?Python Schema.__iter__怎么用?Python Schema.__iter__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.__iter__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Feature
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import __iter__ [as 别名]
#.........这里部分代码省略.........
>>> import geom
>>> f = Feature({'geom': geom.Point(1,1)})
>>> f.geom
POINT (1 1)
>>> f.geom = geom.Point(2,2)
>>> f.geom
POINT (2 2)
"""
def getbounds(self):
if self.geom:
return geom.Bounds(prj=self.schema.proj, env=self.geom.getEnvelopeInternal())
bounds = property(getbounds)
"""
The :class:`Bounds <geoscript.geom.bounds.Bounds>` of the feature geometry.
Will return ``None`` if the feature does not contain any geometric attributes.
"""
def get(self, name):
"""
Returns a feature attribute value by name. ``KeyError`` is thrown if the attribute does not exist.
*name* is the name of the attribute whose value to return.
>>> f = Feature({'name': 'anvil', 'price': 100.0})
>>> str(f.get('name'))
'anvil'
"""
self.schema.get(name)
return self._feature.getAttribute(name)
def set(self, name, value):
"""
Sets a feature attribute value by name. ``KeyError`` is thrown is the attribute does not exist.
*name* is the name of the attribute whose value to set.
*value* is the new attribute value.
>>> f = Feature({'name': 'anvil', 'price': 100.0})
>>> str(f.get('name'))
'anvil'
>>> f.set('name', 'mallet')
>>> str(f.get('name'))
'mallet'
"""
self.schema.get(name)
self._feature.setAttribute(name, value)
def getattributes(self):
atts = {}
for fld in self.schema.fields:
atts[fld.name] = core.map(self._feature.getAttribute(fld.name))
return atts
attributes = property(getattributes, None)
"""
A ``dict`` of name, value for the attributes of the feature.
>>> f = Feature({'name': 'anvil', 'price': 100.0})
>>> atts = f.attributes
>>> str(atts['name'])
'anvil'
>>> atts['price']
100.0
"""
def __getitem__(self, key):
return self.get(key)
def __setitem__(self, key, value):
self.set(key, value)
def __iter__(self):
return self.schema.__iter__()
def iterkeys(self):
return self.__iter__()
def iteritems(self):
return self.attributes.iteritems()
def keys(self):
return [f.name for f in self.schema.fields]
def values(self):
return [core.map(val) for val in self._feature.getAttributes()]
def __repr__(self):
atts = ['%s: %s' % (fld.name, self.get(fld.name)) for fld in self.schema.fields]
id = self.id if self.id.startswith(self.schema.name) else '%s.%s' % (self.schema.name, self.id)
return '%s {%s}' % (id, string.join(atts,', '))
def __eq__(self, other):
return other and self._feature == other._feature