Esri AcrGIS Online integration with Qlik GeoAnalytics
Qlik GeoAnalytics gives us the power to perform spatial analysis within Qlik Sense and QlikView apps. While many Qlik customers have existing GIS tools, their spatial assets are quite often sitting in silos. Combining spatial data with other data through Qlik's associative engine greatly enhances the business value that can be derived from such assets.
Some BI tools can make use of local files such as KML or Esri shape files as data sources, but this introduces security and maintenance headaches. With Qlik GeoAnalytics we have the capability to consume spatial content via hosted services. This document gives a step by step guide on how we can load data from secure content in ArcGIS to Qlik Sense.
The process described here is similar for for ArcGIS Online and on-premise, but I have only tried it out with ArcGIS Online.
The integration can be broken down into these steps:
- Implement App Login in ArcGIS
- Setup Qlik to get a security token
- Build a query for the secure content
- Load the data using Qlik GeoAnalytics
If the content is public, the process is simpler and you can skip the first two steps and ignore all the talk about tokens.
To try out these steps you will need an ArcGIS Online developer account which you can get here.
Implement App Login in ArcGIS
ArcGIS provides a way for applications to use secure content by using App Login. Once you register for a developer account, you'll see the option to create a new Application. Do that and you will be able to get the stuff we need to generate tokens in Qlik.
You'll need the Client ID and Client Secret to automate the process of getting new tokens in Qlik.
Setup Qlik to get a security token
We can use the Qlik REST connector to obtain a token in the load script. There is a good explanation of the process on the ArcGIS side here.
For ArcGIS online we need to make a request to: https://www.arcgis.com/sharing/rest/oauth2/token/
For an on-premise server the url will look like this: https://<host>:<port>/<subdirectory>/sharing/rest/oauth2/token
Create a new REST connection in Qlik Sense with the following parameters and the Client ID and Client Secret you obtained earlier.
This will generate a load script to obtain the 'access_token'. Store the token into a variable in the load script. This can be done with the code below.
// Store the token in a variable that can be used as a request parameter
LET vToken = Peek('access_token', 0, 'root');
Tokens expire after a given period, but with this setup we can get the load script to obtain a new token before loading data from ArcGIS.
Run the load to confirm that you're able to obtain a token. Copy the token text as we'll need that to build a query. One way of doing this is to export it from a table object in Qlik Sense.
Build a query for the secure content
You'll need some private content on ArcGIS Online to test out this bit. Create a new layer by uploading some spatial content such as a zipped shape file.
Make sure the security is set as private.
Once the layer is created you will be able to get a Service URL.
You can validate that the layer is private by trying out this URL in your browser. You should see a 'Token Required' message.
You can add the token we obtained earlier to the URL manually using the syntax: <Service URL>?token=<token>
This lets you get to the Service Directory. From here click on the layer name, scroll all the way to the bottom and click on Query.
You now need to build a query for this layer. I've highlighted the most common parameters you might need to set for the query. Once you're done click on the Query (GET) button.
If everything goes well you should see the JSON output of the query in your browser. Copy the URL from your browser's address bar as we will use this for loading the layer in Qlik GeoAnalytics.
Load the data using Qlik GeoAnalytics
We can now use the URL we obtained for the query to load the layer into Qlik Sense. If you are loading a polygon layer I would recommend using the Simplify operation in the GeoAnalytics connector and excluding the original geometry field in the load. If you are loading a point layer you can use the Load operation.
Once GeoAnalytics has generated the script you can change the hard coded token with the variable using dollar sign expansion i.e. $(vToken).
You should now be able to load the secure ArcGIS content into your Qlik Sense app.