So the first I did was to download the boundary:administrative ways in Jakarta area, by using the following Overpass API rule while downloading in JOSM.
Total boundary:administrative ways: 7809 of admin_level = 9 ways = 5082 of admin_level = 8 ways = 2717
I analyze the data and soon realize that there is a lot of overlapping ways, unjoined nodes with similar coordinates, and some areas that contain ways of admin_level=9 doesn’t have the father way of admin_level=8
I have prepared an script to take the highest admin_level ways, split their ways into segments and create as many boundary relations hierarchically as possible, for example, in this case, I can create the boundary relation of admin_level=8 by using the external borders of those relations with admin_level=9, and so on for the admin_level=7, etc… I will explain this algorithm in the next post when I release the script to the public.
My first task was to prepare the data(offline) before creating those relations. Therefore I had to deal with those duplicated nodes with exact same coordinates.
By using the following python script join_duplicated_nodes.py I eliminated the duplicity and joined all the duplicated nodes at once. (this task is equivalent to selecting one by one each of the nodes and clicking the ‘Merge nodes’ tool of JOSM), but you don’t want to waste that much time with 77657 nodes.
After executing the script, the total of nodes become 74936, so it joined almost 2700 nodes and we reduced the size of the OSM file a bit.
The second task was to get rid of those ways of admin_level=8 that overlap over those ways of admin_level=9 inside. In order to find out these duplicates, I made another python script(see detect_redundant_ways.py) but this time customized for the Indonesian boundary tags(you can change them to fit for your country or area context, you just need to understand the script).
Here is the result(the blue areas are those redundant level-8 ways that can be deleted in our local OSM to be ignored later on when creating the final boundary relations).
Keep tuned for the next post with the final conversion to boundary relations. Feedback wanted!