Object-oriented programming based flowline simplification
Recently, I have developed a set of modules within the HexWatershed python package. These functions take a flowline vector file and process it so it can be used for the HexWatershed model.
In short, these functions resolve issues:
- disconnected line
- (nested) loop caused by lake, braided river
- reversed flow direction flowline
Besides, it re-constructs the stream index and order.
However, I haven’t implemented them using the OOP approach. In this post, I will discuss what can be done to improve them.
Similar to HexWatershed C++ API, we could define vertex, edge, and cell to organize flowline. For example, a single LineString can be represented by a list of vertices. A cell can be represented by a list of close vertices or edges.
While this OOP approach can help with some processes, the benefits are not universal.
- File format conversion will unlikely benefit from this
- MultiLineString split into LineString will unlikely benefit from this as well
- Connect disconnected line can use the vertex distance to find gap;
- Find all vertices can use the flowline list;
- Advanced split can use both flowline and vertex list;
- Correct flow direction can use flowline list
- Remove loop can use flowline topology
- Merge can use edge info
- Remove small river can use flowline/edge info
Overall, it is likely OOP will help with more complicated tasks.