2

I have set up a page layout using the Altas Feature in QGIS v3.2.3. The layout has been configured to show the location of a polygon and the location of vertices that make up each of these polygons. Alongside this I have added an attribute table to list the X and Y values of each vertex for every polygon. The Atlas feature itself is linked to the polygon shape layer whilst the attribute table is linked to a vertex point layer. And whilst there have been no problems exporting this set-up there is one aspect which I cannot seem to resolve which is that in some instances the attribute table lists vertices from different polygons (rather than listing vertices only for the Altas Feature). I have tried toggling with some of the item properties for attribute table e.g. selecting 'show only features intersecting altas feature' however I believe that the solution lies with the expression filter. Unfortunately I have not been able to set up an expression filter that will work with the Atlas Feature and therefore I am looking for some advice on this.

enter image description here

I have attached an image for reference to the above.

  • So you want to show an attribute table of all the polygon nodes? – Nathan W Nov 14 '18 at 11:45
3

If you need something like that it's possible to use a custom expression function to dump out the nodes of a given geometry into a HTML table.

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def dump_table(geometry, feature, parent):
    nodes = geometry.asMultiPolygon()[0][0]
    template = """
    <style>table, th, td {{ border: 1px solid black; }}</style>
    <table>
    <tr>
        <th>PlotNo</th>
        <th>No.</th>
        <th>X</th>
        <th>Y</th>
        </tr>
        {}
    </table>
    """
    rows = []
    for count, node in enumerate(nodes):
        row = """<tr>
        <td>{}</td>
        <td>{}</td>
        <td>{}</td>
        <td>{}</td>
        </tr>""".format(feature['PlotNo'], count, node.x(), node.y())
        rows.append(row)
    return template.format("".join(rows))

You can add custom expressions using the Function Editor in the expression builder:

enter image description here

The output will look like this:

enter image description here

Called like this dump_table($atlas_geometry)

  • Hi Nathan, thank you for your reply. I will try out the process above (basically your output is what I am looking for) – Blue Caterpillar Nov 14 '18 at 12:33
  • This is an excellent answer, but maybe overkill for the situation, since they already have the atlas layer vertices stored as a separate point layer. – csk Nov 14 '18 at 20:04
  • @csk indeed it is but good as an example of not needing the other table. – Nathan W Nov 14 '18 at 23:03
2

Make sure the point layer has a unique attribute in common with the atlas layer, where the points for a given atlas feature have the same value as that feature.

Set up a filter using this attribute, such as

"point_id" =  attribute(@atlas_feature, "atlas_id")

In this example, the common attribute is called "point_id" in the point layer, and "atlas_id" in the atlas layer.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.