I'm actually working on a way to print parts of a Polyline according to both specified paper size and scale. The paper should be rotated in order to maximize the visualisation comfort, and this must be automated.
Note : I'm using QGIS 2.18.x, and can't migrate to 3.x due to major internal extensions that haven't been switched from Python 2.x to 3.x yet.
Here are the steps I followed so far:
- Get the line length, and divide it by the page width in order to know the number of pages to print.
- Divide line length by this number to get the average distance of cable to print on each page (in order to avoid the last page to be partially used)
- Subdivide the polyline using the average distance. This is where I'm actually stuck
I found a way to get the points where I should cut, but I didn't found any function to subdivide a line using a distance. (Apart from
splitGeometry(), which doesn't works with a list of points. It doesn't make them collide the line. Also giving a polyline version of this list cuts too much, as it splits at each interesection of the lines, not only the specified points)
I only succeed to get the points that should cut the line with this code :
pointsList =  for i in range (1, pagesNb): point = line.interpolate(dist * i) pointsList.append(point.asPoint())
Make a Convex Hull of each subline and search for the longuest included line
Make the orientation of the page parallel to this line and adjust the page using the centroid and the page dimensions
Is there a function to cut a line by a ratio, a number of segments or by a list of points?
I'm also interested in any hints/improvements on this method.
I am aware that a
minimumOrientedBoundingBox() function exists, the problem is that it's not present in the QGIS version I use.
Nethertheless, if there is a way to catch the sourcecode of it and use it, I will also take that as a solution (not the one present on the toolbox and that can be called with processing, only the PyQGIS function)