[Qgis-developer] [Qgis-user] Print one map for every category in layer with fixed extent

Blumentrath, Stefan Stefan.Blumentrath at nina.no
Wed Feb 8 01:16:06 PST 2017


Hi again,

And thanks Alexandre for the alternative solution. Your workflow is quite flexible and powerful too, and seems to be a bit more simple.
Yet, I still assume (from the experience within my organization) that it is still a bit too complex for people who use QGIS (or GIS in general) rather seldom.

Thus I packed the Python script I compiled into a plugin (“SerialPrint”) for simplistic serial map production.

If one has a composer with a map item (and optionally a legend), the plugin will loop over a list of user defined layers and:

1         toogle the current layer visible,

2         insert an entry at the top of the legend,

3         export the composition to raster or PDF,

4         toogle the current layer invisible again, remove the respective legend entry and go to next layer in the list…

The plugin needs some cosmetics and would benefit from some enhancements I already have in mind, but it should be working OK.
It is available at: https://github.com/NINAnor/SerialPrint In addition, I also just uploaded it to the plugin repository (flagged as experimental), so testing becomes more easy.

I would be happy about tests and feedback!

Kind regards,
Stefan

From: Alexandre Neto [mailto:senhor.neto at gmail.com]
Sent: mandag 6. februar 2017 00.52
To: Blumentrath, Stefan <Stefan.Blumentrath at nina.no>; Neumann, Andreas <a.neumann at carto.net>
Cc: Qgis-user at lists.osgeo.org; Terje Blindheim <terje at biofokus.no>
Subject: Re: [Qgis-user] Print one map for every category in layer with fixed extent

So,

Imagining that you have layer as a regular grid. Each cell has, for different species, the number of individuals found stored in columns. You want to keep the map always with the same extent and iterate over the columns (species).
With atlas, all you need is a layer with a list of the names of all the columns you want to iterate. It does not have to be spatial, you can just create it as a simple CSV and import that in QGIS. You can also add it other columns with information that you want to use in the maps. Here an example:
"column_name", "common_name", "scientific_name" <-- first row can be used for column names
"specie_1", "specie 1 common name", "specie 1 scientific name"
"specie_2", "specie 2 common name", "specie 2 scientific name"
"specie_3", "specie 3 common name", "specie 3 scientific name"
After loading the layer and give it a name ("list_of_species" for this example) Use that layer atlas layer.

Let's say we want to draw the cell with some color if there are more that 0 elements of a particular specie and white for the rest. In a rule-base simbology, you would need something like:
"specie_1" > 0      --> color
ELSE          --> white

Since we what to iterate the column name, we can get it from the atlas feature, and we can recreate a string that match the expression above. But we need to pass it trough the eval() function to make it work

eval('"' + attribute( @atlas_feature, 'column_name') + '" > 0')
Something similar can also be used directly in a graduated style, without the ">0" part:

eval('"' + attribute( @atlas_feature, 'column_name') + '"')
I have planned to do a blog post about this, but it's in my long to do list.

Hope it helps.
Alexandre Neto


Blumentrath, Stefan <Stefan.Blumentrath at nina.no<mailto:Stefan.Blumentrath at nina.no>> escreveu no dia domingo, 5/02/2017 às 19:41:
Hi Alexandre,

Currently I have a layer per species, but species could also be in one layer with names of the different species in the attribute table…

I already compiled a little Python script for my use case, however, if there is an existing function for that is better of course…

Thanks for helping.

Kind regards,
Stefan

From: Alexandre Neto [mailto:senhor.neto at gmail.com<mailto:senhor.neto at gmail.com>]
Sent: søndag 5. februar 2017 19.59
To: Blumentrath, Stefan <Stefan.Blumentrath at nina.no<mailto:Stefan.Blumentrath at nina.no>>; Neumann, Andreas <a.neumann at carto.net<mailto:a.neumann at carto.net>>

Cc: Qgis-user at lists.osgeo.org<mailto:Qgis-user at lists.osgeo.org>; Terje Blindheim <terje at biofokus.no<mailto:terje at biofokus.no>>
Subject: Re: [Qgis-user] Print one map for every category in layer with fixed extent


In the layer, where is the species recorded? In Columns?

If so, I have a workflow for that.

A sáb, 4/02/2017, 08:38, Blumentrath, Stefan <Stefan.Blumentrath at nina.no<mailto:Stefan.Blumentrath at nina.no>> escreveu:
Thanks Andreas for the excellent procedure description.

Good to know that Python is not required for that, and that there is a nice, flexible, and efficient solution!

For someone who uses QGIS on a regularly basis, this is actually much less work than it might seem at a first look.
However, I am afraid, if I imagine that I try to explain that to my colleagues, many would not be able or not willing to follow, I am afraid…

I found some more code snippets online, which I compiled into a small script. That could be easily wrapped into a plugin if none exists for that yet…??

Cheers
Stefan

From: Neumann, Andreas [mailto:a.neumann at carto.net<mailto:a.neumann at carto.net>]
Sent: torsdag 2. februar 2017 15.05
To: Blumentrath, Stefan <Stefan.Blumentrath at nina.no<mailto:Stefan.Blumentrath at nina.no>>
Cc: Qgis-user at lists.osgeo.org<mailto:Qgis-user at lists.osgeo.org>; Terje Blindheim <terje at biofokus.no<mailto:terje at biofokus.no>>
Subject: Re: [Qgis-user] Print one map for every category in layer with fixed extent


Hi Stefan,

It is possible without the help of Python.

You would have to split up the species into layers.

Then create an atlas layer that is the geometry you want joined with every possible layer. You can use QGIS virtual layers for that which you can define in DB manager. Or use a Postgis view for it.

So for each geographic unit you want to print you need a combination with each layer you want.

E.g.

Province 1 - Species 1

Province 1 - Species 2

Province 1 - Species 3

Province 2 - Species 1

Province 2 - Species 2

Province 2 - Species 3

In this layer, the geometry is redundant, but since you can use Postgis views or virtual layers, it is only virtually redundant.

-------------

Finally, in print composer you would use data-defined layers or visibility presets based on attributes in the atlas coverage layers.

I did exactly that - print an Atlas for several districts in my city and a loop of historic maps. For each district I printed around 15 different historic time snapshots (old maps).

Hope this helps to get started.

Andreas

On 2017-02-02 11:21, Blumentrath, Stefan wrote:
Dear all,

In a project I like to produce a sort of species distribution atlas, where I like to print out (export to image) a map from the print composer for every species recorded within one and the same municipality.

So, the map extent should not change and layout is fixed too. With these things fixed, I want to get a map for each single species mapped and thus also legend entries change. The species are in one single layer, but I could also split them if that makes it easier.

Is there a function in Atlas for that which I overlooked or a plugin or the like.
If not, is there any Python code I could repurpose for that? Found only this [1] and [2], where [1] does not work…

But before I start looking into a pygqis solution I like to make sure that this feature does not exist yet…
This is a not uncommon use case in ecology btw., so a built in function would be neat.

I am grateful for any hint.

Kind regards,
Stefan

[1] http://gis.stackexchange.com/questions/183589/using-pyqgis-to-create-images-from-the-qgis-print-composer-each-showing-a-differ
[2] http://kartoza.com/en/blog/how-to-create-a-qgis-pdf-report-with-a-few-lines-of-python/


_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org<mailto: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



_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org<mailto: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
--
Alexandre Neto
---------------------
@AlexNetoGeo
http://sigsemgrilhetas.wordpress.com
http://gisunchained.wordpress.com
--
Alexandre Neto
---------------------
@AlexNetoGeo
http://sigsemgrilhetas.wordpress.com
http://gisunchained.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170208/db985803/attachment-0001.html>


More information about the Qgis-developer mailing list