I'm currently facing some hard times trying to create a simplified line from a street geometry.
The data that I'm currently using comes from OpenStreetMap, using osm2pgsql.(Which means PostGIS, but I'm open to solutions that don't use it, or use external code, like C, JS, or whatever).
In this example, the street is forked and segmented, the GeoJSON is available here.
Dumping the points of the street is useful which could be converted to a line string, however, their order is messed up, causing bizzare line formations. I could partially solve this issue ordering by lon/lat or lat/lon, but in several cases of points in the same axis or due geometry angle, it does not order them properly, and thus, does not work for all streets.
Few solutions I came up with:
- Using ST_Buffer on every segment, joining, and ST_ApproximateMedialAxis on the resulting geometry. It didn't work because some streets, even with a generous buffer have all it's segments touching each other and also ST_ApproximateMedialAxis doesn't always result in a line string (Not a function fault, it's the expected behavior).
- Ordering by LAT/LON ~ LON/LAT and creating a line from the result: Also didn't work as explained above.
- Using ST_LineMerge: Nope, in regular streets it does work, but on forked or segmented streets, it fails, as explained here.
- Iterating over points to create a line from every point nearest neighbor: Fails due the inability to find the real first and last points.
The hardest task so far is getting the farthest points from given set, to define the first and last point, getting this informations would solve the problem for me, but I'm clueless so far?
I thought about using ST_VoronoiPolygons, but I have no idea how to extract some result from that?