Commit 4f9f4459 authored by Felix Delattre's avatar Felix Delattre
Browse files

Introduced negative ids for osm relations

parent 8caadb26
Pipeline #29213 passed with stage
in 1 minute and 56 seconds
......@@ -79,23 +79,30 @@ class DiffAnalyzer:
# Check on newly created objects
for n in augmented_diff.create:
if n.tags.get("building"):
if self._is_way_or_relation(n):
numbers.append(n.attribs.get("id"))
if isinstance(n, osmdiff.osm.osm.Way):
numbers.append(int(n.attribs.get("id")))
elif isinstance(n, osmdiff.osm.osm.Relation):
numbers.append(-int(n.attribs.get("id")))
# Check on objects that have been modified
for n in augmented_diff.modify:
if n["new"].tags.get("building"):
if self._is_way_or_relation(n["new"]):
numbers.append(n["new"].attribs.get("id"))
if isinstance(n["new"], osmdiff.osm.osm.Way):
numbers.append(int(n["new"].attribs.get("id")))
elif isinstance(n["new"], osmdiff.osm.osm.Relation):
numbers.append(-int(n["new"].attribs.get("id")))
elif n["old"].tags.get("building"):
if self._is_way_or_relation(n["old"]):
numbers.append(n["old"].attribs.get("id"))
if isinstance(n["old"], osmdiff.osm.osm.Way):
numbers.append(int(n["old"].attribs.get("id")))
elif isinstance(n["old"], osmdiff.osm.osm.Relation):
numbers.append(-int(n["old"].attribs.get("id")))
# Check on deleted objects
for n in augmented_diff.delete:
if self._is_way_or_relation(n):
numbers.append(n.attribs.get("id"))
if isinstance(n, osmdiff.osm.osm.Way):
numbers.append(int(n.attribs.get("id")))
elif isinstance(n, osmdiff.osm.osm.Relation):
numbers.append(-int(n.attribs.get("id")))
await self.file_handler.write_diff_report(augmented_diff.sequence_number, numbers)
await self._set_buildings_on_message_bus(numbers)
......@@ -104,9 +111,3 @@ class DiffAnalyzer:
"""Set a list of building ids on the message bus"""
for number in numbers:
await self.message_bus.send(message="building", payload={"building_id": number})
def _is_way_or_relation(self, element) -> bool:
"""Check if element is of type `osm.Way` or `osm.Relation`"""
return isinstance(element, osmdiff.osm.osm.Way) or isinstance(
element, osmdiff.osm.osm.Relation
)
......@@ -52,4 +52,4 @@ class FileHandler:
self.config.filepath + "augmented-diff-" + str(identifier) + ".txt", mode="w"
) as f:
for number in numbers:
await f.write(number + "\n")
await f.write(str(number) + "\n")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment