catatom2osm.osm module

OpenStreetMap data model.

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

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()[fuente]

Return true if this element is new to OSM.

property type

Return class name as string.

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

Bases: catatom2osm.osm.Polygon

Helper to create a multipolygon type relation.

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

Bases: catatom2osm.osm.Element

Define a node as a pair of coordinates.

property childs

Only for simetry with ways and relations.

copyto(container)[fuente]

Copy self in another container.

geometry()[fuente]

Return pair of coordinates.

property lat

Return latitude as string.

property lon

Return longitude as string.

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

Bases: object

Class to implement a OSM data set.

append(data, query=None)[fuente]

Append data elements to this dataset avoiding duplicates.

Optionally filter by query.

Parámetros
  • 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

Ejemplo

>>> 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')[fuente]

Return element by its id.

static get_outline(elements)[fuente]

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

merge_duplicated()[fuente]

Merge elements with the same geometry.

property nodes

Return list of nodes in elements.

property relations

Return list of relations in elements.

remove(el)[fuente]

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

replace(n1, n2)[fuente]

Replace n1 witn n2 in elements.

property ways

Return list of ways in elements.

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

Bases: catatom2osm.osm.Relation

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

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

Bases: catatom2osm.osm.Element

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

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

Bases: object

An element is member of a relation with a role.

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

Add a member.

property childs

Return set of unique members elements.

copyto(container)[fuente]

Copy self in another container.

geometry()[fuente]

Return tuple of coordinates.

is_valid_multipolygon()[fuente]

Return true if this is valid as a multipolygon relation.

outer_geometry()[fuente]

Return equivalent geometry removing inner rings.

remove(e)[fuente]

Remove e from members.

replace(e1, e2)[fuente]

Replace first occurrence of element e1 with e2.

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

Bases: catatom2osm.osm.Element

Define a way as a list of nodes.

append(n)[fuente]

Append n to nodes.

property childs

Return set of unique nodes.

clean_duplicated_nodes()[fuente]

Remove consecutive duplicated nodes.

copyto(container)[fuente]

Copy self in another container.

geometry()[fuente]

Return tuple of coordinates.

is_closed()[fuente]

Return true if the way is closed.

is_open()[fuente]

Return true if the way is not closed.

remove(n)[fuente]

Remove n from nodes.

replace(n1, n2)[fuente]

Replace first occurence of node n1 with n2.

search_node(x, y)[fuente]

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

shoelace()[fuente]

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