in backend/services/mapping_service.py [0:0]
def generate_osm_xml(project_id: int, task_ids_str: str) -> str:
"""Generate xml response suitable for loading into JOSM. A sample output file is in
/backend/helpers/testfiles/osm-sample.xml"""
# Note XML created with upload No to ensure it will be rejected by OSM if uploaded by mistake
root = ET.Element(
"osm",
attrib=dict(version="0.6", upload="never", creator="HOT Tasking Manager"),
)
if task_ids_str:
task_ids = map(int, task_ids_str.split(","))
tasks = Task.get_tasks(project_id, task_ids)
if not tasks or len(tasks) == 0:
raise NotFound()
else:
tasks = Task.get_all_tasks(project_id)
if not tasks or len(tasks) == 0:
raise NotFound()
fake_id = -1 # We use fake-ids to ensure XML will not be validated by OSM
for task in tasks:
task_geom = shape.to_shape(task.geometry)
way = ET.SubElement(
root,
"way",
attrib=dict(id=str((task.id * -1)), action="modify", visible="true"),
)
for poly in task_geom:
for point in poly.exterior.coords:
ET.SubElement(
root,
"node",
attrib=dict(
action="modify",
visible="true",
id=str(fake_id),
lon=str(point[0]),
lat=str(point[1]),
),
)
ET.SubElement(way, "nd", attrib=dict(ref=str(fake_id)))
fake_id -= 1
xml_gpx = ET.tostring(root, encoding="utf8")
return xml_gpx