Skip to content

OSM data views🔗

These classes expose the data from an OSM file to the Python scripts. Objects of these classes are always views unless stated otherwise. This means that they are only valid as long as the view to an object is valid.

OSM types🔗

osmium.osm.osm_entity_bits 🔗

OSM primary objects🔗

osmium.osm.OSMObject 🔗

This is the base class for all OSM entity classes below and contains all common attributes.

changeset: int property 🔗

(read-only) Id of changeset where this version of the object was created.

deleted: bool property 🔗

(read-only) True if the object is no longer visible.

id: int property 🔗

(read-only) OSM id of the object.

tags: TagList property 🔗

(read-only) List of tags describing the object. See osmium.osm.TagList.

timestamp: dt.datetime property 🔗

(read-only) Date when this version has been created, returned as a datetime.datetime.

uid: int property 🔗

(read-only) Id of the user that created this version of the object. Only this ID uniquely identifies users.

user: str property 🔗

(read-only) Name of the user that created this version. Be aware that user names can change, so that the same user ID may appear with different names and vice versa.

version: int property 🔗

(read-only) Version number of the object.

visible: bool property 🔗

(read-only) True if the object is visible.

is_area() -> bool 🔗

Return true if the object is a Way object.

is_node() -> bool 🔗

Return true if the object is a Node object.

is_relation() -> bool 🔗

Return true if the object is a Relation object.

is_way() -> bool 🔗

Return true if the object is a Way object.

positive_id() -> int 🔗

Get the absolute value of the id of this object.

type_str() -> str 🔗

Return a single character identifying the type of the object. The character is the same as used in OPL.

user_is_anonymous() -> bool 🔗

Check if the user is anonymous. If true, the uid does not uniquely identify a single user but only the group of all anonymous users in general.

osmium.osm.Node 🔗

Bases: osmium.osm.types.OSMObject['cosm.COSMNode']

Represents a single OSM node. It inherits all properties from OSMObjects and adds a single extra attribute: the location.

lat: float property 🔗

Return latitude of the node.

location: osmium.osm.Location property 🔗

The geographic coordinates of the node. See osmium.osm.Location.

lon: float property 🔗

Return longitude of the node.

replace(**kwargs: Any) -> osmium.osm.mutable.Node 🔗

Create a mutable node replacing the properties given in the named parameters. The properties may be any of the properties of OSMObject or Node.

Note that this function only creates a shallow copy per default. It is still bound to the scope of the original object. To create a full copy use: node.replace(tags=dict(node.tags))

osmium.osm.Way 🔗

Bases: osmium.osm.types.OSMObject['cosm.COSMWay']

Represents an OSM way. It inherits the attributes from OSMObject and adds an ordered list of nodes that describes the way.

nodes: WayNodeList property 🔗

(read-only) Ordered list of nodes. See osmium.osm.WayNodeList.

ends_have_same_id() -> bool 🔗

True if the start and end node are exactly the same.

ends_have_same_location() -> bool 🔗

True if the start and end node of the way are at the same location. Expects that the coordinates of the way nodes have been loaded (see SimpleHandler apply functions and FileProcessor.with_locations()) If the locations are not present then the function returns always true.

is_closed() -> bool 🔗

True if the start and end node are the same (synonym for ends_have_same_id).

replace(**kwargs: Any) -> osmium.osm.mutable.Way 🔗

Create a mutable way replacing the properties given in the named parameters. The properties may be any of the properties of OSMObject or Way.

Note that this function only creates a shallow copy per default. It is still bound to the scope of the original object. To create a full copy use: way.replace(tags=dict(way.tags), nodes=list(way.nodes))

osmium.osm.Relation 🔗

Bases: osmium.osm.types.OSMObject['cosm.COSMRelation']

Represents a OSM relation. It inherits the attributes from OSMObject and adds an ordered list of members.

members: RelationMemberList property 🔗

(read-only) Ordered list of relation members. See osmium.osm.RelationMemberList.

replace(**kwargs: Any) -> osmium.osm.mutable.Relation 🔗

Create a mutable relation replacing the properties given in the named parameters. The properties may be any of the properties of OSMObject or Relation.

Note that this function only creates a shallow copy per default. It is still bound to the scope of the original object. To create a full copy use: rel.replace(tags=dict(rel.tags), members=list(rel.members))

osmium.osm.Area 🔗

Bases: osmium.osm.types.OSMObject['cosm.COSMArea']

Areas are a special kind of meta-object representing a polygon. They can either be derived from closed ways or from relations that represent multipolygons. They also inherit the attributes of OSMObjects and in addition contain polygon geometries. Areas have their own unique id space. This is computed as the OSM id times 2 and for relations 1 is added.

from_way() -> bool 🔗

Return true if the area was created from a way, false if it was created from a relation of multipolygon type.

inner_rings(oring: OuterRing) -> InnerRingIterator 🔗

Return an iterator over all inner rings of the multipolygon.

is_multipolygon() -> bool 🔗

Return true if this area is a true multipolygon, i.e. it consists of multiple outer rings.

num_rings() -> Tuple[int, int] 🔗

Return a tuple with the number of outer rings and inner rings.

This function goes through all rings to count them.

orig_id() -> int 🔗

Compute the original OSM id of this object. Note that this is not necessarily unique because the object might be a way or relation which have an overlapping id space.

outer_rings() -> OuterRingIterator 🔗

Return an iterator over all outer rings of the multipolygon.

osmium.osm.Changeset 🔗

A changeset description.

bounds: osmium.osm.Box property 🔗

(read-only) The bounding box of the area that was edited.

closed_at: dt.datetime property 🔗

(read-only) Timestamp when the changeset was finalized. May be None when the changeset is still open.

created_at: dt.datetime property 🔗

(read-only) Timestamp when the changeset was first opened.

id: int property 🔗

(read-only) Unique ID of the changeset.

num_changes: int property 🔗

(read-only) The total number of objects changed in this Changeset.

open: bool property 🔗

(read-only) True when the changeset is still open.

tags: TagList property 🔗

(read-only) List of tags describing the object. See osmium.osm.TagList.

uid: int property 🔗

(read-only) User ID of the changeset creator.

user: str property 🔗

(read-only) Name of the user that created the changeset. Be aware that user names can change, so that the same user ID may appear with different names and vice versa.

user_is_anonymous() -> bool 🔗

Check if the user anonymous. If true, the uid does not uniquely identify a single user but only the group of all anonymous users in general.

Tag lists🔗

osmium.osm.Tag 🔗

Bases: typing.NamedTuple

A single OSM tag.

k: str instance-attribute 🔗

Tag key

v: str instance-attribute 🔗

Tag value

osmium.osm.TagList 🔗

Bases: typing.Iterable[osmium.osm.types.Tag]

A fixed list of tags. The list is exported as an unmutable, dictionary-like object where the keys are tag strings and the items are Tags.

get(key: str, default: Optional[str] = None) -> Optional[str] 🔗

Return the value for the given key. or 'value' if the key does not exist in the list.

Node lists🔗

osmium.osm.NodeRef 🔗

A reference to a OSM node that also caches the nodes location.

lat: float property 🔗

(read-only) Latitude (y coordinate) as floating point number.

lon: float property 🔗

(read-only) Longitude (x coordinate) as floating point number.

x: int property 🔗

(read-only) X coordinate (longitude) as a fixed-point integer.

y: int property 🔗

(read-only) Y coordinate (latitude) as a fixed-point integer.

osmium.osm.NodeRefList 🔗

A list of node references, implemented as an immutable sequence of osmium.osm.NodeRef. This class is normally not used directly, use one of its subclasses instead.

ends_have_same_id() -> bool 🔗

True if the start and end node are exactly the same.

ends_have_same_location() -> bool 🔗

True if the start and end node of the way are at the same location. " Expects that the coordinates of the way nodes have been loaded (SimpleHandler apply functions and FileProcessor.with_locations()). If the locations are not present then the function returns always true.

is_closed() -> bool 🔗

True if the start and end node are the same (synonym for ends_have_same_id).

osmium.osm.WayNodeList 🔗

Bases: osmium.osm.types.NodeRefList

List of nodes in a way. For its members see osmium.osm.NodeRefList.

osmium.osm.InnerRing 🔗

Bases: osmium.osm.types.NodeRefList

List of nodes in an inner ring. " For its members see osmium.osm.NodeRefList.

osmium.osm.OuterRing 🔗

Bases: osmium.osm.types.NodeRefList

List of nodes in an outer ring. For its members see osmium.osm.NodeRefList.

Relation members🔗

osmium.osm.RelationMember 🔗

Single member of a relation.

ref: int = ref instance-attribute 🔗

OSM ID of the object. Only unique within the type.

role: str = role instance-attribute 🔗

The role of the member within the relation, a free-text string. If no role is set then the string is empty.

type: str = mtype instance-attribute 🔗

Type of object referenced, a node, way or relation.

osmium.osm.RelationMemberList 🔗

An immutable sequence of relation members osmium.osm.RelationMember.

Geometry types🔗

osmium.osm.Box 🔗

osmium.osm.Location 🔗

Mutable OSM objects🔗

osmium.osm.mutable.OSMObject 🔗

Mutable version of osmium.osm.OSMObject.

__init__(base: Optional[OSMObjectLike] = None, id: Optional[int] = None, version: Optional[int] = None, visible: Optional[bool] = None, changeset: Optional[int] = None, timestamp: Optional[datetime] = None, uid: Optional[int] = None, tags: Optional[TagSequence] = None, user: Optional[str] = None) -> None 🔗

Initialise an object with the following optional attributes: id, version, visible, changeset, timestamp, uid and tags. Timestamps may be strings or datetime objects. Tags can be an osmium.osm.TagList, a dict-like object or a list of tuples, where each tuple contains a (key value) string pair.

If the base parameter is given in the constructor, then the object will be initialised first from the attributes of this base object.

osmium.osm.mutable.Node 🔗

Bases: osmium.osm.mutable.OSMObject

The mutable version of osmium.osm.Node.

__init__(base: Optional[Union[Node, osmium.osm.Node]] = None, location: Optional[LocationLike] = None, **attrs: Any) -> None 🔗

Initialise a node with all optional attributes from osmium.osm.mutable.OSMObject as well as a location attribute. This may either be an osmium.osm.Location or a tuple of lon/lat coordinates.

osmium.osm.mutable.Way 🔗

Bases: osmium.osm.mutable.OSMObject

The mutable version of osmium.osm.Way.

__init__(base: Optional[Union[Way, osmium.osm.Way]] = None, nodes: Optional[NodeSequence] = None, **attrs: Any) -> None 🔗

Initialise a way with all optional attributes from osmium.osm.mutable.OSMObject as well as a nodes attribute. This may either be an osmium.osm.NodeRefList or a list consisting of osmium.osm.NodeRef or simple node ids.

osmium.osm.mutable.Relation 🔗

Bases: osmium.osm.mutable.OSMObject

The mutable version of osmium.osm.Relation.

__init__(base: Optional[Union[Relation, osmium.osm.Relation]] = None, members: Optional[MemberSequence] = None, **attrs: Any) -> None 🔗

Initialise a relation with all optional attributes from osmium.osm.mutable.OSMObject as well as a members attribute. This may either be an osmium.osm.RelationMemberList or a list consisting of osmium.osm.RelationMember or tuples of (type, id, role). The member type must be a single character 'n', 'w' or 'r'.