Actually, the ocean segments are almost the same polygons, about which we spoke earlier, only without the subtracted areas of the continents and small polygons merged with neighbors.
Some of the parts left after lands subtracting can be very small. Also, small polygons can be formed near the border of the ‘world’ polygon. We should add them to the neighboring sectors, so as not to spoil the overall picture.
Red lines in the figure indicate the desired merging of polygons.
The choice of rectangles for merging with can be done in different ways. The project implemented two methods: by the longest border and by the nearest center. In the following image, the second method is applied.
In general, we achieved what we wanted. The area of the sectors is approximately the same (on the sphere) and sectors are mainly convex with small exceptions.
On the continents we can create a more interesting subdivision. It based, from one side, on generated small Voronoi polygons (base polygons), and, from the other side, on natural geographical objects such as rivers and watersheds. The obtained structure is very similar to the world’s subdivision into the states and provinces in them. That is, it is the process of the procedural generation of the world political map.
Unlike the ocean, convexity is unnecessary, and we should consider natural boundaries, other than land borders, as possible boundaries between sectors.
Watersheds in the project are not yet build, but there are already rivers!
As the first step, we create the Voronoi diagram of small area polygons for the selected land. In the project, each division of the global landmass is marked with the identifier
aid (area Id) and can consist of a continent and nearest islands or only small islands located close by each other. The availability of areas and their identifiers can be determined from the content of the lands shapefile.
The average size of the base polygons is made as small as possible (it increases the computation time!). For the current example, we choose the average sector size of 40,000 km2 and the average size of the base polygons at 5000 km2. This is a rather large size chosen so only for clearness of the example.
In the picture there is a part of Voronoi diagram inside a land.
In practice, it is better to choose the average size of the base polygons in the interval 500–1000 km2. Smaller sizes are also permissible (up to several m2), but take into account the computation time and use a more suitable database configuration.
To merge base polygons into sectors, we randomly choose from them as much as we want to make separate sectors, and then gradually join remaining adjacent base polygons to resulting sectors.
In the picture an example of what we can get.
Now it is time to consider the rivers. We use the representation of rivers as two-dimensional linestrings, by which we can divide the initial sectors into parts (with
ST_Split function). The river linestrings can be taken from riversz shapefile. Since we do not need the z-coordinate stored in that shapefile, we cut it off when importing shapefile to PostGIS enabled database.
Division of sectors by rivers can be performed depending on a number of conditions: the final streamflow of the river, the area of the separated sector part, etc.
After this division we will get many separate parts.
Small parts of sectors (cuts) need to be attached to large sectors. But we must try not to attach parts to the same sectors from which they were cut off.
After joining, we will see the following picture.
You might think that we have done everything that is required. But in fact it is not so, because there are still small islands. Those of them that have an area close to the average sector area are made as individual sectors right away. But with those whose area is much smaller than the average sector, we act in two ways.
1. If such islands are located relatively far from existing sectors, then we make them separate sectors. “Farness” here depends on the defined average sector area: the smaller this area the more likely that the island will become a separate sector.
2. If the island is close to other already defined sectors, then it merges with one of them. With the one that has the largest area in some polygon obtained with
ST_Buffer of the island polygon.
On the next picture, four islands that have merged into two sectors.
With an increase in the defined average sector size, these islands will fall into single sector.