I would like to create polygons along a line to use them for AtlasCreator in a next step.
ArcMap has a tool called Strip Map Index Features.
With this tool I can choose the height and width of my polygons (say 8km x 4km) and produce/rotate them along the line automatically.
One of the generated attributes of each polygon is the rotation angle that I need to rotate my north arrows in Atlas Generator afterwards.
Does anyone have an idea how to solve this task in QGIS / with PyQGIS?
GRASS- or SAGA-algorithms or a prossessing-toolbox-model which could be used inside a custom plugin would be fine, too.
I need not only the print extents but also the polygons itself as I want to print a map with all polygons/extents as some sort of overview map. I am looking for a PyQGIS-solution that can be used in a QGIS-Plugin without the need for installing a software aside from QGIS (no RDBMS like PostGIS / Oracle).
Best Answer
Interesting question! It's something I've wanted to try myself, so gave it a go.
You can do this in PostGRES/POSTGIS with a function which generates a set of polygons.
In my case, I have a table with one feature (a MULTILINESTRING) which represents a railway line. It needs to use a CRS in meters, I'm using osgb (27700). I've done 4km x 2km 'pages'.
Here, you can see the result...the green stuff is the road network, clipped to a 1km buffer around the railway, which corresponds to the height of the polygons nicely.
Here's the function...
Using this function
Here's an example; 4km x 2km pages, epsg:27700 and 10% overlap
After running this you can then export from PgAdminIII into a csv file. You can import this into QGIS, but you might well need to set the CRS manually for the layer - QGIS doesn't use the SRID in EWKT to set the layer CRS for you :/
Adding bearing attribute
This is probably easier done in postgis, it can be done in QGIS expressions but you'll need to write some code. Something like this...
Caveats
It's a bit hacked-together, and only had a chance to test on one dataset.
Not 100% sure which two vertices you'll need to choose on that bearing attribute update
query
.. might need to experiment.I must confess I have no idea why I need to do such a convoluted formula to rotate the polygon to match the current line segment. I thought I could use the output from ST_Azimuth() in ST_Rotate(), but seemingly not.