catatom2osm.osm module

OpenStreetMap data model.

class catatom2osm.osm.Element(container, tags={}, attrs={})[source]

Bases: object

Base class for Osm elements.

property attrs

Return the element attributes as a dictionary.

property fid

Return id as unique string.

is_new()[source]

Return true if this element is new to OSM.

property type

Return class name as string.

class catatom2osm.osm.MultiPolygon(container, parts=[], *args, **kwargs)[source]

Bases: catatom2osm.osm.Polygon

Helper to create a multipolygon type relation.

class catatom2osm.osm.Node(container, x, y=0, *args, **kwargs)[source]

Bases: catatom2osm.osm.Element

Define a node as a pair of coordinates.

property childs

Only for simetry with ways and relations.

copyto(container)[source]

Copy self in another container.

geometry()[source]

Return pair of coordinates.

property lat

Return latitude as string.

property lon

Return longitude as string.

class catatom2osm.osm.Osm(upload='never', generator=None)[source]

Bases: object

Class to implement a OSM data set.

append(data, query=None)[source]

Append data elements to this dataset avoiding duplicates.

Optionally filter by query.

Parameters
  • data (iterable, Osm or Element) – source data

  • query (func) – function to apply to each element and returns a boolean deciding if it will be included or not

Example

>>> d1 = osm.Osm()
>>> n1 = d1.Node(1, 1, tags={'tourism': 'viewpoint'})
>>> n2 = d1.Node(2, 2, tags={'amenity': 'cafe'})
>>> d2 = osm.Osm()
>>> d2.append(d1)  # all
>>> d3 = osm.Osm()
>>> d3.append(d1, lambda e: 'amenity' in e.tags)  # only amenities
property attrs

Return dictionary of properties in self._attr_list.

get(eid, etype='n')[source]

Return element by its id.

static get_outline(elements)[source]

For a set of elements, get all Way and outer ways in MultiPolygon.

merge_duplicated()[source]

Merge elements with the same geometry.

property nodes

Return list of nodes in elements.

property relations

Return list of relations in elements.

remove(el)[source]

Remove el from element, from its parents and its orphaned children.

replace(n1, n2)[source]

Replace n1 witn n2 in elements.

property ways

Return list of ways in elements.

class catatom2osm.osm.Polygon(container, rings=[], *args, **kwargs)[source]

Bases: catatom2osm.osm.Relation

Helper to create a multipolygon type relation with only one outer ring.

class catatom2osm.osm.Relation(container, members=[], *args, **kwargs)[source]

Bases: catatom2osm.osm.Element

A relation is a collection of nodes, ways or relations with a role.

class Member(element, role=None)[source]

Bases: object

An element is member of a relation with a role.

property attrs
property ref
property type
append(m, role=None)[source]

Add a member.

property childs

Return set of unique members elements.

copyto(container)[source]

Copy self in another container.

geometry()[source]

Return tuple of coordinates.

is_valid_multipolygon()[source]

Return true if this is valid as a multipolygon relation.

outer_geometry()[source]

Return equivalent geometry removing inner rings.

remove(e)[source]

Remove e from members.

replace(e1, e2)[source]

Replace first occurrence of element e1 with e2.

class catatom2osm.osm.Way(container, nodes=[], *args, **kwargs)[source]

Bases: catatom2osm.osm.Element

Define a way as a list of nodes.

append(n)[source]

Append n to nodes.

property childs

Return set of unique nodes.

clean_duplicated_nodes()[source]

Remove consecutive duplicated nodes.

copyto(container)[source]

Copy self in another container.

geometry()[source]

Return tuple of coordinates.

is_closed()[source]

Return true if the way is closed.

is_open()[source]

Return true if the way is not closed.

remove(n)[source]

Remove n from nodes.

replace(n1, n2)[source]

Replace first occurence of node n1 with n2.

search_node(x, y)[source]

Return osm node of way in the given position or None.

shoelace()[source]

Return the area for a closed way or 0, + for CCW nodes, - for CW.