GeoScript

Previous topic

Field

Next topic

feature.io

This Page

Feature

class geoscript.feature.Feature

An object composed of a set of named attributes with values.

A feature is constructed from a dict of name value pairs and an optional identifier.

>>> f = Feature({ 'name': 'anvil', 'price': 100.0 }, 'widgets.1')
>>> str(f.get('name'))
'anvil'

A feature can also be constructed optionally with a Schema.

>>> from schema import Schema
>>> s = Schema('widgets', [('name', str), ('price', float)])
>>> f = Feature({'name': 'anvil'}, '1', s)
>>> f
widgets.1 {name: anvil, price: None}

When schema is specified feature values can be passed a list.

>>> s = Schema('widgets', [('name', str), ('price', float)])
>>> f = Feature(['anvil', 100.0], '1', s)
>>> f
widgets.1 {name: anvil, price: 100.0}
get(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'
set(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'