Select DDP features by location and export selected pages to PDF

Bonus post today – Python time! Often when I create data driven pages for different themes (Water Supply, Sanitation, Transport etc), I have to create several copies of my data driven pages index layer and edit it. This is because certain sections of the study area may not have any features for that particular theme. It’s not good enough to simply skip it, because the scale changes and there are other aesthetic factors to consider.

However, since most of these mapbooks are for asset management, how the map looks is not nearly as important as the data which can be seen, particularly the unique IDs of the features. This is why last night I came up with this script.

The DDP index layer is intersected with all the relevant feature layers, to ensure that only pages containing features for that service are selected for export. I also had the chance to use the exportToPDF function of the DataDrivenPages class. In Line 40, it allows for the export of the currently selected DDP pages.

Write all rows in a feature class to a csv file

This is something I use often, although hardly ever in the same way twice.

I’ve included Line 21 because the main reason why you would be using this method in the first place, is because a non-GIS person has requested data from you. Usually, they don’t require any Shape information.

This way, you include only the attribute information. If they do require lengths/coordinates, it’s much easier to specify a Shape token such as SHAPE@LENGTH or SHAPE@XY than the field itself.