I am looking for a GIS tool/script (preference on QGIS but I can also use ArcGIS/Matlab) that allows creating a polyline layer from a polygon layer where a polyline is drawn for each polygon. The polyline is drawn being the main direction of the polygon and being within the polygon.

Below examples in image:

Main direction polyline within polygon

Another example following comments

I do not have preference for the drawing method (vertex to vertex or edge to edge, skeletons), only the result is important:

This question can be closed as I found a suitable arcgis tool: Polyline to centerline

I would have preferred a Qgis tool but it is OK for now.

Results of the tool below on real polygon layer:

Results of the tool

  • 3
    Welcome to GIS.se! Interesting problem. Could you click 'edit' and expand on your thinking about it? For example, how would you deal with a polygon that didn't have a single long centre axis, but was curved around like a fat 'C'? Defining the exact steps will get you closer to getting a solution.
    – Simbamangu
    Commented Mar 6, 2019 at 8:09
  • 3
    Would you like skeletons postgis.net/docs/ST_StraightSkeleton.html?
    – user30184
    Commented Mar 6, 2019 at 8:13
  • 1
    Possible duplicate of Finding longest line segment within polygon?
    – Hornbydd
    Commented Mar 6, 2019 at 9:42
  • 2
    Thanks for the update - you say you have 'no preference for the drawing method' but the way you want to solve the problem (the process) seems to be variable and we need more guidance! (It's this "defining the problem" requirement on SE which is really valuable - don't get discouraged, you have an interesting problem but we can't tackle it until you explain it completely). You need to clearly explain why the skeleton solution does not work, for example!
    – Simbamangu
    Commented Mar 7, 2019 at 8:53
  • 1
    @Bol - that's great! May I suggest that you delete the solution you posted in the question and instead create an answer? (By the way - looks like 'skeletons' were exactly what you were after in the end?)
    – Simbamangu
    Commented Mar 8, 2019 at 4:56