Using Choropleth Layers with HANA Cloud and SAP Analytics Cloud
If you have some spatial shapes in HANA Cloud, that you would like to visualise with SAP Analytics Cloud (SAC) you are in the right place.
To use the SAC Geospatial choropleth layer, you need a couple of helper delivery units that are supplied as Multi Target Archives (MTARs). First you must deploy the .mtar files into your HANA Cloud environment. Once installed you can use both the standard choropleth shapes and hierarchies and custom choropleth shapes and hierarchies.
The Steps described in this blog are
- Deploy and configure the Spatial Content (.mtar)
- Create Choropleth Custom Hierarchies
- Add Additional Choropleth Layers
- Combine default hierarchies with custom hierarchies
This capability was released with the SAP Analytics Cloud Q4 2020 Update.
- Spatial shape data imported in HANA Cloud with ST_GEOMETRY or similar datatypes
- SAC Location Dimension
- SAP Analytics Cloud Spatial MTARs
- Business Application Studio or Cloud Foundry (cf) command line
You can find the official Analytics Cloud documentation for Creating Geo Spatial Models from HANA Calculation Views.here.
1. Deploy and configure the Spatial Content (.mtar)
1.0 Download the GEO CONTENT
Search for ANALYTICS_CLOUD in Software Downloads
1.1 Upload the mtar files
Business Application Studio, provides a pre-configured environment for development and deployment. It can be used to deploy the two provided SAC spatial .mtar files. SAP Business Application Studio can be found in the SAP Cloud Platform Cockpit (aka BTP Cockpit) at the sub account level, navigate to Service Marketplace.
Download and extract the latest spatial content ANALYTICS_CLOUDXX_X-XXXX.zip file.
You should have four files. you require the two mtar files similar those below.
Upload the two mtars containing the SAC geospatial choropleth layers into your Business Application Studio workspace.
If you only have one HANA Cloud instance you can directly deploy the .mtar. by selecting the .mtar and choosing Deploy MTA Archive from the right click context menu.
1.2 Specify HANA Cloud Database ID
If you have multiple HANA Cloud instances within the Cloud Foundry sub-account, space, you need to tell the deployer which instance to target. This is done using a MTA Deployment Extension Descriptor file .mtaext file. You will need to create a .mtaext for each mtar before deploying. In this extension file you will specify the database id to target the correct HANA instance.
_schema-version: "3.0.0" ID: MY_DATABASE_ID_FOR_FPA_SPATIAL_DATA description: Provides the HANA Cloud Database ID to deploy the shape data for SAC choropleth layer extends: FPA_SPATIAL_DATA resources: - name: FPA_SPATIAL_DATA-hdi parameters: config: database_id: <insert your database ID here>
_schema-version: "3.0.0" ID: MY_DATABASE_ID_FOR_SPATIAL_CUSTOM_REGION description: Provides the HANA Cloud Database ID to deploy the custom hierarchy table for use with SAP Analytics Cloud extends: SAP_FPA_SPATIAL_CUSTOM_REGIONS resources: - name: SAP_FPA_SPATIAL_CUSTOM_REGIONS-hdi parameters: config: database_id: <insert your database ID here>
1.4 Deploy the mtars
You can now deploy the mtars, it will target the sub account and space that you are currently logged into.
cd mta_archives mta_archives $ cf deploy FPA_SPATIAL_DATA_1.1.24.mtar -e FPA_SPATIAL_DATA.mtaext mta_archives $ cf deploy FPA_SPATIAL_CUSTOM_REGIONS_1.0.0.mtar -e FPA_SPATIAL_CUSTOM_REGIONS.mtaext
1.5 Grant Roles to Users
Predefined HANA Roles are included with the mtars. These need to be granted to your HANA Cloud users, that will be used within SAC.
The editor role is only required for developers to insert, update, delete new layers in the CUSTOM_HIERARCHY table.
# Viewing Spatial choropleth GRANT FPA_SPATIAL_DATA."FPA_SPATIAL_DATA::PublicAccessObjects" TO I049374; GRANT SAP_FPA_SPATIAL_CUSTOM_REGIONS."sap.fpa.services.spatial::ViewerRole" TO I049374; # Editing & Creating custom choropleth layers GRANT SAP_FPA_SPATIAL_CUSTOM_REGIONS."sap.fpa.services.spatial::EditorRole" TO I049374;
If you are using the HANA Cloud Cockpit, deselect the “HDI Container API” button
1.6 Create Public Synonyms
The spatial content is deployed as HDI containers on the HANA Cloud system when the MTARs are deployed. SAC uses Public Synonyms so that it doesn’t matter where the data is actually deployed on your HANA Cloud system.
create PUBLIC synonym SAC_CHOROPLETH_DATA for "FPA_SPATIAL_DATA"."FPA_SPATIAL_DATA.choropleth::CHOROPLETH" ; create PUBLIC synonym SAC_CHOROPLETH_HIER for "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial.choropleth::CHOROPLETH_CUSTOM_HIERARCHY" ;
1.7 Enable Public Synonyms SAC Toggle in System Configuration
Within SAC, go to System Administration and enable “Use Public Synonyms for Choropleth Layer”.
You can search for this setting. To enable the switch, press edit and then save.
The installation and configuration of the SAC spatial content for the choropleth drill layer is now completed.
2. Create Choropleth Custom Hierarchies
To use the choropleth layer in SAC you need to follow a few steps.
2.1 Prepare shape data
2.2 Expose shape data as dimension calculation view
2.3 Update SAC Metadata with details of new dimension calculation view
2.4 Create Choropleth Geo Map in SAC
2.1 Prepare Shape Data
Previously I have described how to upload shapefiles to HANA Cloud.
|Column Name||Data Type||Description|
|NAME||VARCHAR(100)||SAC Display Name for Shape/Region|
|SHAPE||ST_GEOMETRY(3857)||This the choropleth shape|
|SHAPEPOINT||ST_POINT(3857)||Centre of the Shape, can be calculated with ST_Centroid() see SQL below.|
|IS_LEAF||BOOLEAN||Usually false. True/false flag to specify whether or not to drill directly to the data points.|
For the SAC Geo Map choropleth layer you need the shape data as ST_GEOMETRY(3857). Currently my data is using spatial reference 4326, it therefore needs to be transformed.
CREATE COLUMN TABLE ENGLAND_L1 (ID INT PRIMARY KEY, NAME VARCHAR(100), SHAPE ST_GEOMETRY(3857), SHAPEPOINT ST_POINT(3857), IS_LEAF BOOLEAN); INSERT INTO ENGLAND_L1 SELECT ROW_NUMBER() Over () as "ID" ,"rgn19nm" as "NAME", SHAPE.ST_Transform(3857) as SHAPE, SHAPE.ST_Transform(3857).ST_Centroid() as SHAPEPOINT, false AS IS_LEAF FROM "England-Regions";
If you really want to see what the SHAPE data looks like I would recommend using DBeaver.
2.2 Expose shape data as dimension calculation view
SAC can only access calculation views, you therefore need to expose this table as a dimension calculation view.
In SAP Business Application Studio, go to View -> Find Command -> “hana” ->
SAP HANA: Create SAP HANA Database Artifact -> Artifact Type -> Calculation View
Data Category – > Dimension
The only configuration required is to specify the ID as a Key in the semantics node.
2.3 Update SAC Metadata
SAC has a metadata table in HANA that stores the available choropleth layers.
This is held in the table “SAP_FPA_SPATIAL_CUSTOM_REGIONS”.”sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY”
By default the table should have the Default Geographical Data as below
SELECT * FROM "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY";
You need to tell SAC about the new shape data. You can do that with the following SQL statement
INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'English Regions' /* NAME: Hierarchy display name shown in SAC */, 2 /* HIERARCHYID: Hierarchy ID */, 'NAME' /* COLUMN: Column storing the shape label name to show in SAC */, 'name' /* COLUMNLABEL: use text 'name' */, 6 /* ID: Unique ID for for Shape or layer */, 1 /* LEVEL: Level in Hierarchy, can use 1, 2, 3 or 1.1, 1.2 */, 'English Region' /* LNAME: Layer display name shown in SAC */, 'SHAPE' /* LOCATION: Column storing the Shape ST_GEOMETRY Label */, 'ENGLAND_REGIONS_L1' /* OBJECT:, Dimensional Calculation View Name */, '' /* PACKAGE: Repository Package, Not used in HANA Cloud */, 'GCOE' /* SCHEMA: SCHEMA/HDI Container storing the Calculation View */, '0' /* DEFAULT: 0 for custom regions, 1 for SAP supplied conent */ );
2.4 Create Choropleth Geo Map in SAC
In SAC, I have already have a location dimension, I can now change the “Layer Type” to choropleth / drill layer and select the “English Regions” hierarchy.
If you don’t see the location options go to the model and press Save to update the metadata.
3.1 Add Additional Choropleth Layers
Using Business Application Studio, I can add further choropleth layers to my custom hierarchy using additional dimensional calculation views. These can be in the same project (HDI container) or from different HDI containers. Below I have added the required fields and logic within a calculation view.
# Calculated Column Definitions # SHAPE, ST_GEOMETRY ST_Transform(ST_GeomFromWKT("SHAPE_WKT",4326),3857) # SHAPEPOINT, ST_POINT ST_Centroid("SHAPE") # IS_LEAF, BOOLEAN false
I need to tell SAC about this new choropleth layer by adding to to the customer metadata.
INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'English Regions', 2, 'NAME', 'name', 7, 2, 'Local Authority', 'SHAPE', 'cv::LOCAL_AUTHORITY_DCV', '', 'COVID', '0');
Moving back to SAC, you now see an additional level in the hierarchy for drill down possible.
4.1 Combine default hierarchies with custom hierarchies
Extending the hierarchies further, you can combine default hierarchies with your custom hierarchies. The default (SAP supplied) SAC hierarchies include country and region. These default hierarchies can be included to improve your custom hierarchies.
When reusing the standard hierarchy levels in your mixed custom hierarchy, the following standard levels are defined:
If you want to use any of the standard hierarchy levels, the level values must be defined as above. For example, if you want to reuse SUB-REGION1 shapes, it must always be defined as Level 3 in your custom hierarchy.
INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'Country - English Regions', 3, 'AREA_NAME', 'name', 8, 1, 'Country', 'SHAPE', 'SAC_CHOROPLETH_DATA', '', 'PUBLIC', '0'); INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'Country - English Regions', 3, 'AREA_NAME', 'name', 9, 2, 'Region', 'SHAPE', 'SAC_CHOROPLETH_DATA', '', 'PUBLIC', '0'); INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'Country - English Regions', 3, 'NAME', 'name', 10, 3, 'English Region', 'SHAPE', 'ENGLAND_REGIONS_L1', '', 'GCOE', '0'); INSERT INTO "SAP_FPA_SPATIAL_CUSTOM_REGIONS"."sap.fpa.services.spatial::custom_hierarchy.CHOROPLETH_CUSTOM_HIERARCHY" VALUES( 'Country - English Regions', 3, 'NAME', 'name', 11, 4, 'Local Authority', 'SHAPE', 'cv::LOCAL_AUTHORITY_DCV', '', 'COVID', '0');
If you change the metadata, this can be cached by the MDS (MultiDimensional Services).
To force the MDS cache to be updated, go to your model and press Save.
If your geo maps are still not working, check the location dimension is still valid and defined as expected.
First of all, thank you very much for this ! Wonderful work
In my project, in SAC, the area adds the value of the neighbor shapes too. Do you see any reason for this behavior ?
Here, Henegouwen has in fact a value of 0 but it sums the 3 adjacent regions (382 = 281+26+75)
I'm using the shapes provided by SAP
I have not come across this type of issue. I would expect the shapes to aggregate the points but not those of their neighbours. Is it the shape or the point that displays the wrong value?
It would make sense to log a support ticket so that this can be investigated further.
Thanks for your feedback
[update] found the issue: one must use SHAPEPOINT instead of SHAPE in SAC. Else it aggregates the neighbors
Did you manage to use the drill up/down button in SAC with your custom hierarchies ?
It only works with the "Default hierarchical data" here.
If not, do you see an option to disable this feature ?
Yes, drill up and down work for me. I have created an animated gif (Figure 4.4) that shows this.
The issue you have is likely caused by your shapes not fitting precisely within each other.
The older documentation for this feature states.
Thank you !!! Your the cause for renewed hope
I will try asap
Thanks for remembering to share the link for the choropleths.
I wanted to ask you if geospatial shape modeling is possible with HANA Services instead of HANA Cloud? Do you know or do you have any experience or knowledge that someone has done it? Currently I am working with Hana Services and SAC Cloud Foundry.
Thank you !
The steps should be identical for any HANA deployment where you are using HDI containers.
I haven't tried with HANA as a Service or HANA 2.x, but there's nothing HANA Cloud specific.
You should be able to use the WebIDE and/or the CF command line to deploy the mtars.
Thank you so much for this. I'm in the process of a cutover from a Neo HANA DB and Neo SAC to HANA Cloud DB and SAC CF, and these steps were what I was looking for.
I do have a question and an extra step I had to add in order for the choropleth to work in SAC:
Question: when creating the public synonyms, do those statements need to be run from the SAP_FPA_SPATIAL_CUSTOM_REGIONS container or can the SQL be executed from the main DB?
Extra Step: I have a container (C_GEOSPATIAL) where I created the views in your step 2.2. I had to create a role with SELECT and EXECUTE privileges, and then grant this role to the technical user used in the SAC connection to HANA Cloud, in my case HANA_SAC:
"privileges": ["SELECT", "EXECUTE"]
SQL statement run from main DB:
grant "C_GEOSPATIAL"."P_Geospatial.db.Roles::CC_GEOSPATIAL_USER" to HANA_SAC
After granting the role, I was able to display the choropleth layers in SAC. Just checking if this was missed on your end, or if I possibly did something wrong/different from your instructions.
Or possibly you simply created the views in step 2.2 in the same container as the SAP_FPA_SPATIAL_CUSTOM_REGIONS ?
Anyway, thanks for this informative blog!
No, I didn't deploy into the SAP_FPA_SPATIAL_CUSTOM_REGIONS container.
You're right - Yes, your SAC HANA user will of course need access to the Calc Views.
My SAC HANA user already has access to the container with my Calc Views. You could say I skipped that step, I was capturing the additional steps required for Choropleth layers.
Thanks Ian for confirming. Just want to ensure I'm doing this correctly for future reference.
It's quite the paradigm shift going from XSC to XSA, not necessarily on the modelling, but the environmental setup, and the pre-requisites for actually being able to model, specifically with containers and cross container access, so I just want to be certain that I'm approaching this correctly and following the appropriate steps.
Once again, thank you for the blog!