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.
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:
Geolocations
.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 ];
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 ];
Sales by Country
.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.
Point data can also be read from Excel files:
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:$Geopoint
so that the field Location
is recognized as a point data field.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;
GeoMakePoint()
function should be used to generate point based data