# Boundary Methodology

For those looking to replicate or create workflows of their own, the following serves as a high-level overview of the steps carried out during spatial data processing to create the digital boundary file that can be clipped to any admin 0 layer. Source code used to perform transformations are available on GitHub. The primary tools used in this pipeline include QGIS (through JSON batch files), GDAL (command line), and Pandas (table transformations).

Fig 1. The data processing pipeline takes the most detailed admin level available as the input.

Fig 2. From this input, the boundaries between admin regions are extended outwards using voronoi polygons.

Fig 3. The original input is dissolved with the resulting voronoi polygons to create a borderless digital boundary file.

Fig 4. This new layer can be clipped with any other admin 0 layer.

# Detailed Steps

- Extract the edges of the boundary file as a line, while retaining information about which part of the line corresponds to which admin area. From this input, we want to extend these edges outwards in an intelligent way that will fill in space far beyond the original boundaries.
- Start with the most detailed admin level available from the original source, with all attributes stripped except for codes used for joining.
- Dissolve to a single admin 0 polygon.
- Convert both the most detailed admin level and the dissolved admin 0 layer from polygons to lines.
- Intersect line layers together, retaining information about which line segment originated from which detailed admin level.

- Extract points along the lines to be used in generating voronoi polygons. Due to how voronoi polygons are generated, input points cannot be overlapping, so the ends of lines need to be trimmed an extremely small amount to allow a gap in between them. For this project, very small is defined as 0.000001 degrees (approx. 10cm)
- Apply a very small buffer to each line segment without dissolving results.
- Convert the buffers into lines.
- Intersect the buffer lines with the line segments used at the beginning of this part. Use a line intersection tool to create points where these two layers meet. This will result in points located a very small distance from the ends of each line.
- Using these points placed almost at the end of every line segment, generate a buffer of 0.000002 degrees. This is to ensure that points next to each other will have their buffers fully overlapping. Dissolve results.
- With these small buffers covering the ends of every line segment, use the difference tool to very slightly trim each line segment, so their ends no longer touch.

- In addition to creating points where boundaries meet along the edge, more points are required to generate a proper voronoi. Since voronoi complexity increases exponentially, adding points every few meters along a boundary would take days or weeks to process, especially for those with details coastlines (Chile, Indonesia, Philippines, etc). A better alternative is to use vertices only, although here line centroids are used instead, since using vertices sometimes introduce errors in the generated results.
- The input line segments were exploded so that every strait part along them became its own feature.
- Points are generated by taking the centre of each exploded line part.
- Points generated in step 2.3 are combined with the steps above to create a single layer.

- From these points spaced along the line, voronoi polygons intelligently extend outwards and allocate available space associated with the attributes of the edge point closest to it.
- Generate voronoi polygons from the input points, filling an area double the size of the original bounding box of the input.
- Dissolve polygons that originate from the same admin polygon.
- Merge this dissolved layer with the original admin layer through a union.
- In the attribute table, in places where the original admin and the voronoi polygons intersect, ignore the voronoi attributes and use only the original. In places where there is only voronoi polygons, use those values. Merge polygons together that share the same attribute values.
- Apply topology cleaning to ensure the integrity of the final result.
- Create higher admin levels by dissolving based on attributes.
- Clip all layers to desired global admin 0 layer.