upoints.osm.Way

Package upoints :: Module osm :: Class Way |
[hide private]
[frames] | no frames]

# Class Way

    object --+
             |
          list --+
                 |
      point.Points --+
                     |
                    Way

Class for representing a way element from OSM data files

Since: 0.9.0

Instance Methods | [hide private]
new list |
__init__(self, ident, nodes, visible=False, user=None, timestamp=None, tags=None) Initialise a new Way object |
`str` |
__repr__(self) Self-documenting string representation |
`str` |
__str__(self, nodes=False) Pretty printed location string |
`ET.Element` |
toosm(self) Generate a OSM way element subtree |
Inherited from `point.Points`: `bearing`, `destination`, `distance`, `final_bearing`, `forward`, `import_locations`, `inverse`, `midpoint`, `range`, `sun_events`, `sunrise`, `sunset`, `to_grid_locator` Inherited from `list`: `__add__`, `__contains__`, `__delitem__`, `__delslice__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__getslice__`, `__gt__`, `__hash__`, `__iadd__`, `__imul__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__mul__`, `__ne__`, `__new__`, `__reversed__`, `__rmul__`, `__setitem__`, `__setslice__`, `append`, `count`, `extend`, `index`, `insert`, `pop`, `remove`, `reverse`, `sort` Inherited from `object`: `__delattr__`, `__reduce__`, `__reduce_ex__`, `__setattr__`

Static Methods | [hide private]
Node |
parse_elem(element) Parse a OSM way XML element |

Instance Variables | [hide private]
| ident Way's unique indentifier
| tags Tags associated with the way
| timestamp The date and time a way was logged
| user User who logged the way
| visible Whether the way is visible

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, ident, nodes, visible=False, user=None, timestamp=None, tags=None) (Constructor) |
Initialise a new Way object Parameters: `ident` (`int`) - Unique identifier for the way `nodes` (`list` of `str` objects) - Identifiers of the nodes that form this way `visible` (`bool`) - Whether the way is visible `user` (`str`) - User who logged the way `timestamp` (`str`) - The date and time a way was logged `tags` (`dict`) - Tags associated with the way Returns: new list Overrides: object.__init__

### __repr__(self) (Representation operator) |
Self-documenting string representation
    >>> Way(0, (0, 1, 2))
    Way(0, [0, 1, 2], False, None, None, None)
    >>> Way(0, (0, 1, 2), True, "jnrowe", Timestamp(2008, 1, 25))
    Way(0, [0, 1, 2], True, 'jnrowe', Timestamp(2008, 1, 25, 0, 0),
        None)
    >>> Way(0, (0, 1, 2), tags={"key": "value"})
    Way(0, [0, 1, 2], False, None, None, {'key': 'value'})
Returns: `str` String to recreate Way object Overrides: object.__repr__

### __str__(self, nodes=False) (Informal representation operator) |
Pretty printed location string
    >>> print(Way(0, (0, 1, 2)))
    Way 0 (nodes: 0, 1, 2)
    >>> print(Way(0, (0, 1, 2), True, "jnrowe",
    ...           Timestamp(2008, 1, 25)))
    Way 0 (nodes: 0, 1, 2) [visible, user: jnrowe, timestamp: 2008-01-25T00:00:00+00:00]
    >>> print(Way(0, (0, 1, 2), tags={"key": "value"}))
    Way 0 (nodes: 0, 1, 2) [key: value]
    >>> nodes = [
    ...     Node(0, 52.015749, -0.221765, True, "jnrowe",
    ...          Timestamp(2008, 1, 25, 12, 52, 11), None),
    ...     Node(1, 52.015761, -0.221767, True, None,
    ...          Timestamp(2008, 1, 25, 12, 53, 14),
    ...          {"created_by": "hand", "highway": "crossing"}),
    ...     Node(2, 52.015754, -0.221766, True, "jnrowe",
    ...          Timestamp(2008, 1, 25, 12, 52, 30),
    ...          {"amenity": "pub"}),
    ... ]
    >>> print(Way(0, (0, 1, 2), tags={"key": "value"}).__str__(nodes))
    Way 0 [key: value]
        Node 0 (52°00'56"N, 000°13'18"W) [visible, user: jnrowe, timestamp: 2008-01-25T12:52:11+00:00]
        Node 1 (52°00'56"N, 000°13'18"W) [visible, timestamp: 2008-01-25T12:53:14+00:00, highway: crossing, created_by: hand]
        Node 2 (52°00'56"N, 000°13'18"W) [visible, user: jnrowe, timestamp: 2008-01-25T12:52:30+00:00, amenity: pub]
Parameters: `nodes` (`list`) - Nodes to be used in expanding references Returns: `str` Human readable string representation of Way object Overrides: object.__str__

### toosm(self) |
Generate a OSM way element subtree
    >>> ET.tostring(Way(0, (0, 1, 2)).toosm())
    '<way id="0" visible="false"><nd ref="0" /><nd ref="1" /><nd ref="2" /></way>'
    >>> ET.tostring(Way(0, (0, 1, 2), True, "jnrowe", Timestamp(2008, 1, 25)).toosm())
    '<way id="0" timestamp="2008-01-25T00:00:00+00:00" user="jnrowe" visible="true"><nd ref="0" /><nd ref="1" /><nd ref="2" /></way>'
    >>> ET.tostring(Way(0, (0, 1, 2), tags={"key": "value"}).toosm())
    '<way id="0" visible="false"><tag k="key" v="value" /><nd ref="0" /><nd ref="1" /><nd ref="2" /></way>'
Returns: `ET.Element` OSM way element

### parse_elem(element) Static Method |
Parse a OSM way XML element Parameters: `element` (`ET.Element`) - XML Element to parse Returns: Node Way object representing parsed element