easy undelete of several ways

Posted by malenki on 18 November 2015 in English (English)

Second tought on my older posting about partially deleting changesets. Again, it is also a note-to-self.
Only helpful, if you have a bash with the usual tools at hand. For Windows there is Cygwin providing these.
You need a JOSM with the undelete plugin installed.

deleted objects of a changeset Example-Changeset with deleted objects and some of them selected for copying

If you stumble over a huge changeset and only want to undelete the deleted ways in that changeset without a time consuming revert of the whole changeset proceed this way:

  • copy the ways you want to undelete (mark them, press ctrl-c)
  • save them in a file foo
  • execute run on the command line

       less /path/to/file_foo | awk -F "," '{print "w"$1","}'|tr -d "\n[[:blank:]]"|sed s/[nrw],/""/g; echo " "
  • this results in a line looking this way:

  • copy this line, switch to JOSM, press shift-alt-u, paste the copied line, press enter
  • all the ways will be undeleted
  • If you want to undelete nodes or relations, do as before and only replace in print “w” the w with n for nodes or r for relations

Having a lot of time, here the ## Explanation of the command

  less /path/to/file_foo |  sends the content of file_foo to a pipe from where the next tool can parse the content.

  awk -F "," '{print "w"$1","}' | Tell awk it gets a string separated by commata and to print the first column which in our case is the ID of the way. Additionally it has to print a "**w**" in front of it so the undelete plugin later knows it has to undelete a **w**ay. The comma is added to later have a nice line without spaces. The output is again piped for the next tool.

  tr -d "\n[[:blank:]]"| Tell the tool **tr**uncate to delete all newlines to make the list of ways a single line. Additionally, have it delete all blank spaces which may occur from copying and cause a broken list. Again pipe the result.

  sed s/[nrw],/""/g; This is only there to avoid another possible error which would be a leading **w** without ID for a way. This is also done for **n**odes and **r**elations.

  echo " " Just to let the Bash make a line break. This makes it easier to copy the desired output.

Login to leave a comment