Author
Philip Thompson
Philip is a Senior Solution Architect and is in his 17th year at Esri Ireland
Tutorial | 21/04/21 | #WeTalkTech
The Problem
Printing, the dirty word in modern GIS. We all have Field Maps and Survey123 on our phones. We can take vast areas offline and work seamlessly in zero bandwidth using high quality, high performance maps. And yet printing remains a common requirement. Or more accurately, the generation of map centric reports in PDF or JPG format.
ArcGIS Pro provides the capability for users to create beautiful and detailed reports. However, a request we at Esri Ireland hear quite often from our customers is that they would like to be able to publish these report templates to ArcGIS Online and allow their users to generate these reports themselves from there.
Well with the capability to schedule Notebooks added to ArcGIS Online in the April update we’ll show you how you can build a solution which does just that.
Please Note: Before I start, a couple of points worth noting
In this solution I am accessing private content within my Organisation. I am providing my ArcGIS Online credentials to the ArcGIS Python libraries within a Notebook. I have done so via a credentials file held securely within my account. Never place your credentials in plain text within a Notebook.
To use notebook scheduling, you need to be a Creator or GIS Professional user type in your ArcGIS Online organization, and you need to have either an Administrator role or a custom role in which you’ve been granted privileges to create and edit notebooks, and to schedule them.
The Solution
We’ve set ourselves the challenge of solely using out-of-box tools within ArcGIS Online to generate PDF files based off of multiple custom customer branded layouts created within ArcGIS Pro. The approach we’ve taken is to simulate a classic queuing system. We’ll place “jobs” onto a queue which are picked up and processed by a scheduled task.
There are 3 parts to our solution:
The Client Application
This is the easy bit. We’ve consciously tried to use out of the box applications and services that are available to everyone within ArcGIS Online. There is no secret sauce or smoke and mirrors.
Our application needs to perform 1 function – capture a point a on a map. We would like to allow the user to populate certain attributes, and auto-populate others. So, we’ve created an application from Web AppBuilder which has 1 widget – the Smart Editor. That’s all.
Underpinning that is the service and map. Our service is a simple feature service with a number of attributes which will be used at various stages of the solution to either capture information or control if the Notebook needs to pick up this feature and generate a report for it. The layout field contains a list of values which will correspond to the layouts which we’ve created within the ArcGIS Pro Project file (.APRX) and want the user to select.
Attachments have been enabled on the service to give us an area to later store the generated PDF.
Once the service has been added to a web map, we can create feature templates for each layout.
Now a User can drop points on the map representing each layout, add a scale and a title. Job done.
The Report Layouts
We’re still in our comfort zone. We’ve created 4 different layouts. Each contains our own branding, logo and marginalia.
Now the important bit. We’ve added the services we want to appear in the report to the map view. The report will be created from the map defined in our ArcGIS Pro layout, not the map in our web application. There are mechanisms to pass the web map from the application to the APRX, but this would have necessitated custom code within the client application, and we’ve set ourselves the goal of using out of the box tools.
The Report Generation Engine
ArcGIS Notebooks gives users access to 327 python packages. We’ve used a number of those packages to build a Report Generation engine. That engine powers our solution, allowing us to separate the user experience of our client application and the intelligence of the report generation.
The Notebook environment and script will allow us to:
Upload APRX
We used an Advanced ArcGIS Notebook in order to use the ArcPy library.
ArcGIS Notebooks provides the facility to upload your own files which are then accessible within the ArcGIS Notebook workspace.
The ArcPy and ArcGIS API for Python libraries need to be imported and signed in.
Inspect the Queue
This couldn’t be simpler. We query the feature service to find all records which haven’t had a report generated against them.
Set Extent and Layout
An extent was then created based on the point captured and the scale which was requested. The APRX Map Frame was set to match that extent.
The layout used for the PDF generation is set based on the selected feature template.
Generate PDF
Once the ArcPy exportToPDF operation was invoked a PDF was generated and could be saved to the Files directory of the Notebook workspace.
The generated PDF was then saved as an attachment to the feature and the feature status changed to “IsGenerated”.
Finally, like all good guests we cleaned up after ourselves and deleted the PDF from within the Notebook.
Once we’ve saved our Notebook, we can then create a task which will run the Notebook on a schedule.
So that gives us our reporting engine and our end-to-end solution.
We hope this helps you realise the power of Scheduled ArcGIS Notebooks and how they can be applied to provide powerful solutions solely using the tools available to everyone within your ArcGIS Online account.
To access the code from this article visit Github:
https://github.com/PhilipThompson/printing-custom-layouts-from-arcgis-online
Author
Philip is a Senior Solution Architect and is in his 17th year at Esri Ireland