I'm having a lot of trouble figuring out how to convert a 2D list of points into an SVG Path representing a political map border. I have completed all parts of a 2D terrain generator, including climate simulation, rivers, lakes, rainfall, temperature, biomes, and finally territories. This last part is where the problem lies. The entire script is written in Python.
I have a list of territories, which are represented as dicts with several properties. One of which is Color, used as an ID and to output a pretty map. Another is a list of Pixels, list of Borders, and list of Neighbors. Pixels refers to all points in the territory. Territories can be thought of a polygons. They have Border pixels, which are defined as any outside (meaning not part of the Pixels list) pixel not belonging to this territory (whether it be a River, Ocean, or Unowned pixel). I also keep a list of neighboring territories.
Now, I can't store an array of ~3000 coordinates in a database efficiently when I only really need the border. I aim to draw only the world map with the borders of each territory drawn in a layer above. So I need to convert the border to an SVG Path string.
The Borders list is unordered when the generator finishes. For each border pixel, I go clockwise around the pixel and look for another, and progressively create a SVG Path string. I can't seem to efficiently parse the borders without getting stuck. Another problem is that there may be "lakes" in the middle of the Territory, and Borders are added around those as well. These don't have to be included in the path string.
Territories can also wrap around horizontally (like Google Maps for instance), splitting the territory in two.
So the final result of my algorithm would ideally be an LIST of SVG Paths, each representing individual parts of the territory polygons.
But, how do I do this efficiently? Is there another way to efficiently store a list of potentially thousands of coordinates representing the shape of the territory?
Each white line that sticks out from the coastline is a river. You can also see a lake in the middle of the lower green territory.
PS: I was unsure of a title, if a mod would like to change it.