PR #131: allow duplicate ids in OSM data.

* Allow duplicate id's in `OSMData` class as long as data identical.

Allows creating OSMData classes from composite datasets with
overlapping but identical data.

* Fixed formatting issues.
This commit is contained in:
Andrew Klofas 2022-05-01 13:22:05 -07:00 committed by GitHub
parent 7105e4ce88
commit e8604ec408
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,7 +122,7 @@ class Tagged:
return is_well_formed
@dataclass
@dataclass(eq=False)
class OSMNode(Tagged):
"""
OpenStreetMap node.
@ -182,6 +182,19 @@ class OSMNode(Tagged):
def __hash__(self) -> int:
return self.id_
def __eq__(self, other) -> bool:
if not isinstance(other, OSMNode):
return False
return (
self.id_ == other.id_
and np.array_equal(self.coordinates, other.coordinates)
and self.visible == other.visible
and self.changeset == other.changeset
and self.timestamp == other.timestamp
and self.user == other.user
and self.uid == other.uid
)
@dataclass
class OSMWay(Tagged):
@ -343,9 +356,11 @@ class OSMData:
def add_node(self, node: OSMNode) -> None:
"""Add node and update map parameters."""
if node.id_ in self.nodes:
raise NotWellFormedOSMDataException(
f"Node with duplicate id {node.id_}."
)
if node != self.nodes[node.id_]:
raise NotWellFormedOSMDataException(
f"Node with duplicate id {node.id_}."
)
return
self.nodes[node.id_] = node
if node.user:
self.authors.add(node.user)
@ -360,9 +375,11 @@ class OSMData:
def add_way(self, way: OSMWay) -> None:
"""Add way and update map parameters."""
if way.id_ in self.ways:
raise NotWellFormedOSMDataException(
f"Way with duplicate id {way.id_}."
)
if way != self.ways[way.id_]:
raise NotWellFormedOSMDataException(
f"Way with duplicate id {way.id_}."
)
return
self.ways[way.id_] = way
if way.user:
self.authors.add(way.user)
@ -374,9 +391,11 @@ class OSMData:
def add_relation(self, relation: OSMRelation) -> None:
"""Add relation and update map parameters."""
if relation.id_ in self.relations:
raise NotWellFormedOSMDataException(
f"Relation with duplicate id {relation.id_}."
)
if relation != self.relations[relation.id_]:
raise NotWellFormedOSMDataException(
f"Relation with duplicate id {relation.id_}."
)
return
self.relations[relation.id_] = relation
def parse_overpass(self, file_name: Path) -> None: