[Qgis-user] Programmatically export layout with georeferenced file
DelazJ
delazj at gmail.com
Sun May 27 00:49:41 PDT 2018
Hi Nyall
2018-05-25 1:58 GMT+02:00 Nyall Dawson <nyall.dawson at gmail.com>:
> On 25 May 2018 at 03:02, DelazJ <delazj at gmail.com> wrote:
> > Hi all,
> >
> > I have a layout on which I checked the "save world file" option in Layout
> > --> Exports settings
> > When I export this layout to image, I'd expect it to generate a world
> file
> > next to it considering that the generateWorldFile is an attribute of the
> > ImageExportSettings class [0]. But no world file.
>
> The GUI setting isn't stored in the layout* - you need to manually
> set generateWorldFile to true
> in your ImageExportSettings if you want the world file created.
>
>
> > mylayout=QgsProject.instance().layoutManager().layoutByName('Composeur
> 1')
> > exporter = QgsLayoutExporter(mylayout)
> > exporter.exportToImage(filePath, QgsLayoutExporter.ImageExportSettings)
>
> If you want the world file, this should be
>
> exporter = QgsLayoutExporter(mylayout)
> settings = QgsLayoutExporter.ImageExportSettings()
> settings.generateWorldFile = True
> exporter.exportToImage(filePath, settings)
>
> Unfortunately, in my real world use case, I don't know whether the world
file is desired. I'm updating my MapsPrinter plugin [0] which helps
exporting multiple layouts at once.. So I should catch the selection the
user made in the GUI. This leads me to use the customProperty:
exporter = QgsLayoutExporter(mylayout)
settings = QgsLayoutExporter.ImageExportSettings()
settings.generateWorldFile = mylayout.customProperty('exportWorldFile')
leading to this function [1] . It does seem to work but I realize that for
svg particularly, I cannot have access to properties like RDF metadata nor
layered SVG as they are proposed to the user only in the export process. I
understand that there's some unstability in layout(?) customProperty API
but would that be possible to have these options in the layout export
settings frame or what are the plans regarding them (if any)?
Side note on the plugin I'm working on:
1/ I'm trying to count the number of pages that are actually exportable and
use the following code:
page_number, pagesToExport = 0, 0
while page_number < layout.pageCollection().pageCount():
if layout.pageCollection().shouldExportPage(page_number):
pagesToExport += 1
print(pagesToExport)
It seems that layout.pageCollection().shouldExportPage(page_number) always
return true. In a two pages layout, I checked the "Exclude page from
export" option on one page and calling that returns true for both pages.
Exporting from GUI or code does however output only one page. Isn't that
the right property to check?
2/ The count of pages was intended to help me display a progress bar for
each processed page but while this is possible for simple export, it does
not look like there's a way to catch when a page/feature is output in a
atlas configuration. No signal emitted until the end of all the iterations,
right?
Again, thanks Nyall for the help and for having simplified (afaict) the
Python side of layout (despite all my questions - /me sunday Python learner)
Regards,
Harrissou
[0] https://github.com/DelazJ/MapsPrinter/tree/migration_to_v3
[1]
https://github.com/DelazJ/MapsPrinter/commit/1a1adbe6a8500abf5b738c4ec907ff7e02f364fb#diff-a5fa5f963eba950b6c361daae67e552fR670
> > ls=QgsProject.instance().layoutManager().layouts()
> > for elt in ls:
> > exporter = QgsLayoutExporter(elt)
> > imgSettings = exporter.ImageExportSettings()
> > print(elt.name(), imgSettings.generateWorldFile)
> >
> > which returns False for any layout, including the one I checked the
> option
> > for. Btw, dpi returns -1.0, pages return an empty list... I guess I might
> > have missed something but...No idea.
>
> That's because imgSettings here is a default constructed
> ImageExportSettings - which defaults to no world file, and dpi of -1
> (as noted in the docs, the dpi in ImageExportSettings is an override
> ... if it's -1, then the layout's DPI will be used). An empty pages
> list means export all pages. You need to manually populate this
> ImageExportSettings as required for your export.
>
> Nyall
>
>
> * actually it is stored in a customProperty for the layout, but that's
> not part of stable API
>
> layout.customProperty('exportWorldFile')
>
>
> >
> > [0]
> > https://qgis.org/pyqgis/master/core/Layout/QgsLayoutExporter
> .html#qgis.core.QgsLayoutExporter.ImageExportSettings
> >
> > Thanks for your help,
> > Harrissou
> >
> > _______________________________________________
> > Qgis-user mailing list
> > Qgis-user at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20180527/75585835/attachment.html>
More information about the Qgis-user
mailing list