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

Class Node

 object --+    
          |    
point.Point --+
              |
             Node

Class for representing a node element from OSM data files

Since: 0.9.0

Instance Methods [hide private]
 
__init__(self, ident, latitude, longitude, visible=False, user=None, timestamp=None, tags=None)
Initialise a new Node object
str
__str__(self, mode='dms')
Pretty printed location string
ET.Element
toosm(self)
Generate a OSM node element subtree
str
get_area_url(self, distance)
Generate URL for downloading OSM data within a region
Osm
fetch_area_osm(self, distance)
Fetch, and import, an OSM region

Inherited from point.Point: __dict__, __eq__, __hash__, __ne__, __repr__, __unicode__, bearing, destination, distance, final_bearing, forward, inverse, midpoint, sun_events, sunrise, sunset, to_grid_locator

Inherited from point.Point (private): _set_location

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Static Methods [hide private]
Node
parse_elem(element)
Parse a OSM node XML element
Instance Variables [hide private]
  ident
Node's unique indentifier
  latitude
Location's latitude
  longitude
Locations's longitude
  tags
Tags associated with the node
  timestamp
The date and time a node was logged
  user
User who logged the node
  visible
Whether the node is visible

Inherited from point.Point: rad_latitude, rad_longitude, timezone, units

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, ident, latitude, longitude, visible=False, user=None, timestamp=None, tags=None)
(Constructor)

 

Initialise a new Node object

>>> Node(0, 52, 0)
Node(0, 52.0, 0.0, False, None, None, None)
>>> Node(0, 52, 0, True, "jnrowe", Timestamp(2008, 1, 25))
Node(0, 52.0, 0.0, True, 'jnrowe',
     Timestamp(2008, 1, 25, 0, 0), None)
>>> Node(0, 52, 0, tags={"key": "value"})
Node(0, 52.0, 0.0, False, None, None, {'key': 'value'})
Parameters:
  • ident (int) - Unique identifier for the node
  • latitude (float or coercible to float) - Nodes's latitude
  • longitude (float or coercible to float) - Node's longitude
  • visible (bool) - Whether the node is visible
  • user (str) - User who logged the node
  • timestamp (str) - The date and time a node was logged
  • tags (dict) - Tags associated with the node
Raises:
  • ValueError - Unknown value for angle
  • ValueError - Unknown value for units
  • ValueError - Invalid value for latitude or longitude
Overrides: object.__init__

__str__(self, mode='dms')
(Informal representation operator)

 

Pretty printed location string

>>> print(Node(0, 52, 0))
Node 0 (52°00'00"N, 000°00'00"E)
>>> print(Node(0, 52, 0, True, "jnrowe",
...            Timestamp(2008, 1, 25)))
Node 0 (52°00'00"N, 000°00'00"E) [visible, user: jnrowe, timestamp:
2008-01-25T00:00:00+00:00]
>>> print(Node(0, 52, 0, tags={"key": "value"}))
Node 0 (52°00'00"N, 000°00'00"E) [key: value]
Parameters:
  • mode (str) - Coordinate formatting system to use
Returns: str
Human readable string representation of Node object
Raises:
  • ValueError - Unknown value for mode
Overrides: object.__str__

toosm(self)

 

Generate a OSM node element subtree

>>> ET.tostring(Node(0, 52, 0).toosm())
 '<node id="0" lat="52.0" lon="0.0" visible="false" />'
>>> ET.tostring(Node(0, 52, 0, True, "jnrowe",
...                  Timestamp(2008, 1, 25)).toosm())
'<node id="0" lat="52.0" lon="0.0" timestamp="2008-01-25T00:00:00+00:00" user="jnrowe" visible="true" />'
>>> ET.tostring(Node(0, 52, 0, tags={"key": "value"}).toosm())
'<node id="0" lat="52.0" lon="0.0" visible="false"><tag k="key" v="value" /></node>'
Returns: ET.Element
OSM node element

get_area_url(self, distance)

 

Generate URL for downloading OSM data within a region

>>> Home = Node(0, 52, 0)
>>> Home.get_area_url(3)
'http://api.openstreetmap.org/api/0.5/map?bbox=-0.0438497383115,51.9730034021,0.0438497383115,52.0269965979'
>>> Home.get_area_url(12)
'http://api.openstreetmap.org/api/0.5/map?bbox=-0.175398634277,51.8920136086,0.175398634277,52.1079863914'
Parameters:
  • distance (int) - Boundary distance in kilometres
Returns: str
URL that can be used to fetch the OSM data within distance of location

fetch_area_osm(self, distance)

 

Fetch, and import, an OSM region

>>> Home = Node(0, 52, 0)
>>> # The following test is skipped, because the Osm object doesn't
>>> # support a reliable way __repr__ method.
>>> Home.fetch_area_osm(3) # doctest: +SKIP
Parameters:
  • distance (int) - Boundary distance in kilometres
Returns: Osm
All the data OSM has on a region imported for use

parse_elem(element)
Static Method

 
Parse a OSM node XML element
Parameters:
  • element (ET.Element) - XML Element to parse
Returns: Node
Node object representing parsed element