3liz / qgis-atlasprint

Export PDF using composer atlas feature, usable in server
13 stars 13 forks source link

No atlas when no map in QGIS print layout #59

Closed ghtmtt closed 2 years ago

ghtmtt commented 2 years ago

If in QGIS a print layout is created without a map, e.g. only some tables and text labels for a report-like use, the plugin is not generating anything.

The request points to:

status:fail
message: "Internal 'atlasprint' service error"

while the plugin error on the server is:

09:21:03 CRITICAL AtlasPrint[2754]: Unhandled exception:
Traceback (most recent call last):
  File "/var/www/qgis-server/plugins/atlasprint_old/service.py", line 173, in get_print
    **additional_params
  File "/var/www/qgis-server/plugins/atlasprint_old/core.py", line 143, in print_layout
    if not scales and atlas_layout.referenceMap().atlasScalingMode() == QgsLayoutItemMap.Predefined:
AttributeError: 'NoneType' object has no attribute 'atlasScalingMode'

09:21:03 CRITICAL AtlasPrint[2754]: Atlas print request error 500: Internal 'atlasprint' service error

adding a map, and checking the Exclude item from exports in the Rendering tab works, but it seems like a hack :)

Is this by design?

Gustry commented 2 years ago

Is this by design?

No, it's not by design. It's just because most QGIS layouts have a map, we didn't think about this use-case when working on this plugin. A patch would be welcome ;-)

ghtmtt commented 2 years ago

a functional workaround is something like that:

        try: 
            if not scales and atlas_layout.referenceMap().atlasScalingMode() == QgsLayoutItemMap.Predefined:
                use_project = project.useProjectScales()
                map_scales = project.mapScales()
                if not use_project or len(map_scales) == 0:
                    logger.info(
                        'Map scales not found in project, fetching predefined map scales in global config'
                    )
                    map_scales = global_scales()
                settings.predefinedMapScales = map_scales
        except:
            pass
ghtmtt commented 2 years ago

that's great. Thanks!