I am trying to create a map series to summarise species information from various taxonomic groups, for various sites, referred to here as 'patches'. The table below shows an example of the layer I am using for the spatial map series index layer. 'Patch_Taxon_Page' is the index field.
I want to export a map series for each value of 'Patch_Name', that is saved somewhere with the value of Patch_Name as a file suffix. As if I were putting a definition query for each value of Patch_Name and exporting manually one at a time. Can anyone help me with some python code to do this from a notebook?
| Patch_Name | Taxon_Grouping | Page | Patch_Taxon_Page |
| Netpool Park | Bird | 1 | Netpool Park_Bird_1 |
| Netpool Park | Vascular Plant | 2 | Netpool Park_Vascular Plant_2 |
| Netpool Park | Vascular Plant | 3 | Netpool Park_Vascular Plant_3 |
| Mynydd Mawr Woodland Park | Arachnid | 1 | Mynydd Mawr Woodland Park_Arachnid_1 |
| Mynydd Mawr Woodland Park | Bird | 1 | Mynydd Mawr Woodland Park_Bird_1 |
| Mynydd Mawr Woodland Park | Bird | 2 | Mynydd Mawr Woodland Park_Bird_2 |
Many thanks
Solved! Go to Solution.
In your example, if you were to just export the entire series as PNG, would you end up with 6 different files named [Patch_Taxon_Page].png? You could just use a few lines of python to process those file names and aggregate them into two new PDFs named [Patch_Name].pdf.
import glob, os
from PIL import Image
folder = r"C:\Path\To\Your\PNGs"
pngs = glob.glob(os.path.join(folder, "*.png"))
for p in set(os.path.basename(f).split("_")[0] for f in pngs):
imgs = [Image.open(f).convert("RGB") for f in pngs if os.path.basename(f).split("_")[0] == p]
imgs[0].save(os.path.join(folder, f"{p}.pdf"), save_all=True, append_images=imgs[1:])
In your example, if you were to just export the entire series as PNG, would you end up with 6 different files named [Patch_Taxon_Page].png? You could just use a few lines of python to process those file names and aggregate them into two new PDFs named [Patch_Name].pdf.
import glob, os
from PIL import Image
folder = r"C:\Path\To\Your\PNGs"
pngs = glob.glob(os.path.join(folder, "*.png"))
for p in set(os.path.basename(f).split("_")[0] for f in pngs):
imgs = [Image.open(f).convert("RGB") for f in pngs if os.path.basename(f).split("_")[0] == p]
imgs[0].save(os.path.join(folder, f"{p}.pdf"), save_all=True, append_images=imgs[1:])
Many thanks! I went down a slightly different route in the end, but this is also a good solution.