Skip to content

Commit

Permalink
remove duplicate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zlavergne committed Feb 4, 2020
1 parent 64cd99c commit 53e2eff
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions server/services/mapping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,88 +359,3 @@ def reset_all_badimagery(project_id: int, user_id: int):
project = ProjectService.get_project_by_id(project_id)
project.tasks_bad_imagery = 0
project.save()

@staticmethod
def generate_project_file_osm_xml(project_id: int, file_id: int, task_ids_str: str) -> str:
""" Generate xml response suitable for loading into JOSM created from an extract of the specified project file """

if task_ids_str:
task_ids = map(int, task_ids_str.split(','))
tasks = Task.get_tasks_as_geojson_feature_collection(project_id, task_ids)
if not tasks:
raise NotFound()
else:
tasks = Task.get_tasks_as_geojson_feature_collection(project_id)
if not tasks or len(tasks) == 0:
raise NotFound()

dto = ProjectFiles.get_file(project_id, file_id)

filedir = os.path.join(dto.path, os.path.splitext(dto.file_name)[0])

if not os.path.exists(filedir):
os.makedirs(filedir)

tasks_file = os.path.join(filedir, "{project_id}_tasks.geojson".format(project_id=str(project_id)))

with open(tasks_file, 'w') as t:
t.write(str(tasks))

# Convert the geojson features into separate .poly files
# to use with osmosis
poly_cmd = './server/tools/ogr2poly.py {file} -p {filedir}/ -f taskId'.format(file=tasks_file, filedir=filedir)
subprocess.check_output(poly_cmd, shell=True)
os.remove(tasks_file)

osm_files = []
for poly in os.listdir(filedir):
""" Extract from osm file into a file for each poly file """
task_cmd = './server/tools/osmosis/bin/osmosis --rx file={xml} enableDateParsing=no --bp completeWays=yes clipIncompleteEntities=true file={task_poly} --wx file={task_xml}'.format(
xml=os.path.join(dto.path, dto.file_name),
task_poly=os.path.join(filedir, poly),
task_xml=os.path.join(
filedir,
"task_{task_id}_{file_name}.osm".format(
task_id=os.path.splitext(poly)[0],
file_name=os.path.splitext(dto.file_name)[0]
)
)
)
osm_files.append(
os.path.join(
filedir,
"task_{task_id}_{file_name}.osm".format(
task_id=os.path.splitext(poly)[0],
file_name=os.path.splitext(dto.file_name)[0])
)
)
subprocess.check_output(task_cmd, shell=True)
os.remove(os.path.join(filedir, poly))

# Merge the extracted files back together. Used if more than one task is sent in request.
merge_cmd = ['./server/tools/osmosis/bin/osmosis']

for osm in osm_files:
merge_cmd.extend(['--rx', 'file={file}'.format(file=osm), '--s'])

for x in range(0, len(osm_files)-1):
merge_cmd.append('--m')

merge_cmd.extend(['--wx', 'file=-'])
merge_string = ' '.join(merge_cmd)
xml = subprocess.check_output(merge_string, shell=True)

return xml

def reset_all_badimagery(project_id: int, user_id: int):
""" Marks all bad imagery tasks ready for mapping """
badimagery_tasks = Task.query.filter(Task.task_status == TaskStatus.BADIMAGERY.value).all()

for task in badimagery_tasks:
task.lock_task_for_mapping(user_id)
task.unlock_task(user_id, new_state=TaskStatus.READY)

# Reset bad imagery counter
project = ProjectService.get_project_by_id(project_id)
project.tasks_bad_imagery = 0
project.save()

0 comments on commit 53e2eff

Please sign in to comment.