Creating geo maps in Qlik Sense®

Geographical information can be plotted in Qlik Sense by making use of the Map object. In order to create geo maps in Qlik Sense, we need to load the location information also called point or area data. The location information can be loaded either from a Keyhole Markup Language (KML) file, if available, or a database, web service, or from a simple Excel file. Data can also be loaded inline, which is what we are going to do in our following recipe.

Getting ready

For the purpose of this recipe, we will make use of an inline data load which gives us the location information for different countries in the form of latitudes and longitudes:

  1. Create a new Qlik Sense file and name it Geolocations.
  2. Add the following Inline table that contains the location information for countries:
    Country:
    Load RowNo() As CountryID, *,GeoMakePoint(Latitude, Longitude) As CountryGeoPoint Inline [
        Country, Latitude, Longitude
        Australia, -25.274398,133.775136
        Argentina, -38.416097,-63.616672
        India, 20.593684,78.962880
        China, 35.861660,104.195397
        Colombia, 4.570868,-74.297333    Great Britain,55.378051,-3.435973
        Switzerland ,46.8181887,8.227512
        Netherlands,52.132633,5.291266
        Salvador,13.794185,-88.896530
        Italy,41.871940,12.567380
        Peru,-9.189967,-75.015152
    ];
  3. Next, add the following Inline table that contains the Sales information for each country:
    Sales:
    Load * Inline [
        Country, Region, Sales
        Australia,Australia,133775
        Argentina, Latam,6361672
        India, APAC,7896880
        China, APAC,10419397
        Colombia, Latam,742333
        Great Britain,EMEA,3590073
        Switzerland ,EMEA,8227512
        Netherlands,EMEA,521266
        Salvador,Latam,8886530
        Italy,EMEA,12567807
        Peru,Latam,750152
    ];
  4. Load the data and save the file. Open the App overview by clicking on the Navigation dropdown Getting ready in the top left corner.

How to do it…

  1. Create a new sheet in the Qlik Sense application.
  2. Enter the Edit sheet mode and drag across the Map object from the left-hand side Assets panel on to the sheet. Name it Sales by Country.
  3. Click on Add Dimension and then select CountryGeoPoint. Select Country to represent the point name:
    How to do it…
  4. In the Properties panel to the right of your screen, add Sum(Sales) as your expression under data.
  5. The resulting map on the screen will look like the following. The map automatically picks up the Mapbox background in its point layer. The only available image type is slippy map:
    How to do it…
  6. Next, we will change the background of the map.
  7. To do this, open the Properties panel and click on Background. The Background windows Show property is by default set to On. The URL and Attribution boxes get activated when you switch the Map service from Auto to Custom.
  8. Click on the URLs and attributions hyperlink at the bottom of the Background window:
    How to do it…
  9. From the available list of slippy map servers, copy a URL and paste it into the URL text field.
  10. Next, copy the attribution string for the chosen URL and paste the string into the Attribution text-field.
  11. For the sake of our exercise, we will use the URL and Attribution string for MapQuest-OSM.
  12. Click on How to do it…. The final map will look like the following screenshot:
    How to do it…
  13. When we hover over any bubble, the tool tip shows the relevant country and sales.

How it works…

While loading the script for this recipe, we made the use of the GeoMakePoint() function. This function creates and tags a point with its latitude and longitude information. Each country is thus linked to point data, which is plotted on the map. When we use a KML file as a source, Qlik Sense automatically detects the Geopoint field; therefore, there is no need to use a special function to define the same.

While changing the background for the map, we insert the required URL that connects to the tile server that we want to use. For copyright reasons, the attribution string should correspond to the desired URL.

There's more…

Point data can also be read from Excel files:

  1. If the point data is stored in a single column called Location, that is, if each point is specified as an array of x and y coordinates and represented as [x, y]. Here x=longitude and y=latitude then:
    • The geospatial coordinates, namely, the latitudes and longitudes should be tagged with $Geopoint so that the field Location is recognized as a point data field.
    • As an example, consider that the Location data is being extracted from a file called Country.XLS having three columns Country, Location, and Sales; where Location contains the point data. The script in such a case will look like the following:
        LOAD
         Country,
         Location,
         Sales
        FROM 'lib:///Country.xls' (biff, embedded labels, table is (Sheet1$));
      
        Tag Field Location with $Geopoint;
    • Run the script and add the point dimension to the map.
  2. If the point data is stored in two columns, that is, one for latitude and the other for longitude then:
    • The GeoMakePoint() function should be used to generate point based data
  3. Similarly, one can make use of the KML files, which contain point data, area data, or both in order to create maps in Qlik Sense. The following URL explains the process of generating maps in Qlik Sense using the KML files:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset