qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.51k stars 2.99k forks source link

Print Layout: display image within an attribute table - can it be done by rendering table as HTML? #52315

Open walking-the-talk opened 1 year ago

walking-the-talk commented 1 year ago

Feature description

I have an atlas with a map and associated (filtered) attribute table set up as a layout. I would like to be able to display a field as an image (based on the record value) within the attribute table, rather than the field value.

If for example an attribute table could be set to be rendered as HTML and I set the Attribute of one column to be <img src="[myimagefield]"> or more probably concat('<img src=\"',myimagefield,'\">')

At present I think I can only print one record per page if I create a report (that includes the attributes and an image). I think this would be a 'simple' solution (although might be REALLY complex to achieve!) and given that the Layout already has the function to 'extend until finished', would make layouts even more flexible. A further advantage would be the ability to create hyperlinks and potentially additional styling of the table content. There are probably lots of disadvantages that I haven't thought of!

antoniolocandro commented 1 year ago

Have you tried Add HTML? Maybe this would be able to fulfill your request.

For example, I have the flags changing based on the URL stored in a field and atlas

image

image

walking-the-talk commented 1 year ago

Thanks for the suggestion. However, I think this is restricted to one record per page - so the atlas iterates through the records (this appears to be what your layouts are showing). What I am trying to achieve is to associate an attribute table with a map - essentially a one to many relationship. I would like to be able to filter the attribute table to match the map content (already possible) and display / print the table with images associated with each record in the table (i.e. they are values in a field, and we display the image rather than the text value). This could stretch to more than one page (again already possible) so that the images could be resized as necessary. I thought about an HTML 'wrapper' for the existing attribute table layout item as a 'simple' means of achieving the outcome, because most of the heavy lifting has already been done. I don't think that the Add HTML frame(s) can produce the same effect - i.e. collate a defined group of records within the same frame. If you have found a way to do that, I am very happy to be wrong :-) However, I suppose it depends whether the attribute table item is 'constructed' in a way that can easily be translated into html format.

Thanks for your help.

github-actions[bot] commented 1 year ago

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.

walking-the-talk commented 1 year ago

Well, the 'bot' seems to think this is stale because the issue has been left in 'feedback' mode - I have provided feedback but I am unable to add / change the labels that have been assigned by @agiudiceandrea . The suggestion by @antoniolocandro of Add HMTL does not apply to an attribute table - I would like to display multiple images on a single page that are associated with the records in the attribute table - the example given is an image from a single field called using html tags.

I am hoping that the attribute table 'widget' can be adapted to parse html tags as well as QGIS functions. Or to provide an HTML 'wrapper' for the table output (and users can then construct an HTML statement within the existing attribute table 'widget'.

Thanks

zezzagio commented 11 months ago

It's far from optimal, but it seems you can actually use the HTML widget to show all the related images.

In the HTML widget, select "source" instead of "url" and write something like:

[% relation_aggregate( '[attribute_table_relation_id]', 'concatenate','<img src="' || "[myimagefield]" || '">', '\<p> ', '[myorderfield]')%]

You can find the id of the relation in the "Relations" group in the composing window of the expression.

It works, somehow; I don't know how robust and costumizable it can be.

walking-the-talk commented 8 months ago

It's far from optimal, but it seems you can actually use the HTML widget to show all the related images. ... It works, somehow; I don't know how robust and costumizable it can be.

Firstly, my apologies @zezzagio for not acknowledging this suggestion - my notification of your response didn't arrive for some reason. I came back to this problem having another report to write...

This is an excellent workaround, I have just managed to get it to work and with some styling have got a half decent table to render. So fairly robust so far:

<table style="text-align: left; width: 100%;" border="1" cellpadding="1" cellspacing="0">
<tbody>
<tr>
 <td style="text-align: center; width: 50%; font-weight: bold;">Notes</td>
<td style="text-align: center; width: 50%; font-weight: bold;">image </td>
</tr>
[%relation_aggregate('[relation_name or relation_id]','concatenate','<tr height="400"><td>'||"[photo_notes]"||'</td><td><img src="[path/to/folder/if/image/name/only/in/photo/field/]' || "[photo]" || '"></td></tr>', '','[order_by_field]')%]
</tbody>
</table>

And using a stylesheet with:

img {
    max-width: 100%;
    max-height: 100%;
}

ensures that the photo fits into a standard size row. One dumb moment forgetting to ensure my folder path has no spaces!!!

Next would be to split the frame on complete rows... But some judicious sizing of might be good enough...

I still think the attribute table render as html would me more user friendly (so I won't close this) - but what a revelation the 'relation_aggregate' is!

THANKS

zezzagio commented 8 months ago

@walking-the-talk I assume you have seen the "Report" functionallity too; it's a sort of glorified Atlas. It has a sub-report feature, though it doesn't work as in other report generators. You can't compose multiple sub-reports on the same page; every sub-report generates a new page (or a series of new pages), and there are other limitations.

Stil not what you (or I, for what it matters) want, then, but it's another way to print related information.

walking-the-talk commented 8 months ago

Yes, I have used Reports and Atlases frequently and they are powerful up to the point where you want more than one record on a page (my record so far is 280 pages! Not necessarily something to be proud of though).

Attribute Tables in the layout help to work around that to a certain extent, but the image was my stumbling block. If the atlas or report were to be created as frames with repeating content 'blocks', inside resizing or expanding as necessary to fit (including additional pages, e.g. optional new page before each atlas feature), that might be a way around it, to allow more than one record per page - much the same as the HTML frame can be used as existing or new frames. But I think that would be a major refactoring of the layout process...

So the relation_aggregate gives me some additional flexibility. Appreciated.