This document will give you an overview to Spatial Processing capability within SAP HANA, and how to setup and run the spatial demo app for B1 Summit 2015, which allow you to analyse the customers and sales on map.
SAP HANA has completely transformed the database industry by combining database, data processing, and application platform capabilities in a single in-memory platform. The platform also provides libraries for predictive, planning, text processing, spatial, and business analytics all on the same architecture. Simply put, this makes SAP HANA the platform for building and deploying next-generation, real-time applications and analytics. This document will take you to a tour of the spatial processing capability of SAP HANA, and how to setup and run the spatial demo app in B1 Summit 2015, which enrich and visualise Sales Analysis in geo-spatial context on map for SAP Business One.
Spatial processing with SAP HANA Overview
What is spatial Data?
Spatial data is data that describes the position, shape, and orientation of objects in a defined space. Spatial data is represented as 2D geometries in the form of points, line strings, and polygons.
It could be geo-spatial, such as the shape of a continental, a country, a State and a City on the map. For example, the following image shows the state of Massachusetts, representing the union of polygons representing zip code regions.
Or a layout design of a product or a building which can be stored as spatial data.
According to “An introduction to GIS: linking maps to databases” by Franklin, Carl and Paula Hane:
- 80% of all data contains geographical reference.
Take the delivery of product to customers in business data for example, the customer's ship-to address is recorded when the customer place an order. During the execution of delivery for the sales order, the addresses of warehouses are taken into calculation for selecting the nearest one for delivery. The warehouse staff use the bin location to locate the products for pick and pack.The shortest routine will be calculate for the transportation of the goods. The customer ship-to address, the address and bin location of warehouse are the spatial data. - 90% of mobile device are location aware. Nowadays, you checkin the places on Facebook for activities to share with friends, find the restaurant nearby with the app urbonspoon/yelp, to dine and rate etc. Using the app RunKeeper to track your running routine on the smart phone etc.
Enriching the business data with geographical context, visualising the business analysis on shape or form and presenting in real-time manner, becomes a significant competitive advantage for businesses. Especially for the industry retail, oil&gas, public sectors etc.A few use case of spatial data to list below:
- Identify hidden revenue opportunities within your customer base through location based analysis
- Retain your high-value customers, employees, vendors, store locations, etc. with the right location specific offers
- Detect fraud based on location information Pinpoint assets, equipment, and property at risk within hazard areas
- Improve customer recommendations based on their specific real-time location
- Increase cross-sell and up-sell effectiveness through location based analytics
- Identify key product, store, employee, and equipment performance drivers based on spatial data
etc.
Spatial processing with SAP HANA
Support for the processing of spatial data represents a key evolution in SAP HANA. To deliver vastly improved performance and results in everything from modeling and storage to analysis and presentation of your spatial data, SAP HANA includes a multilayered spatial engine and supports spatial columns, spatial access methods, and spatial reference systems. With these enhanced GIS features, SAP HANA now provides a common database for both your business and spatial data. SAP HANA spatial is an SAP HANA optional component.
Spatial Processing with SAP HANA Overview - YouTube
A full picture of Spatial Processing with SAP HANA
Unlike other database for OLTP and OLAP, the spatial data has to been stored and process in a separate spatial data. Spatial data can be be stored, processed and analysed directly inside SAP HANA.
1).The spatial data types supported in SAP HANA:
CREATE COLUMN TABLE SpatialShapes ( ShapeID integer, shape ST_GEOMETRY );
--ST_Point
INSERT INTO SpatialShapes VALUES(1, NEW ST_POINT('POINT(2.5 3.0)'));
--ST_LINESTRING
INSERT INTO SpatialShapes VALUES(6, NEW ST_LINESTRING('LINESTRING(3.0 3.0, 5.0 4.0, 6.0 3.0)'));
--ST_POLYGON
INSERT INTO SpatialShapes VALUES(12, NEW ST_POLYGON('POLYGON((4.0 5.0, 5.0 3.0, 6.0 5.0, 4.0 5.0))'));
2).Accessing and Manipulating Spatial Data with SQL Function and Modeling
Two common operations performed on spatial data are calculating the distance between geometries, and determining the union or intersection of multiple objects. These calculations are performed using predicates such as intersects, contains, and crosses.
--ST_AsGeoJSON() ; ST_GeometryType
SELECT NEW ST_Point( 1.0, 2.0 ).ST_AsGeoJSON() FROM dummy;
--returns the result {"type": "Point", "coordinates": [1.000000000000000,2.000000000000000]}.
--ST_AsText()/ST_GeomFromText(); ST_AsWKT()/ST_GeomFromWKT
SELECT NEW ST_Point( 1.0, 2.0 ).ST_AsText() FROM dummy;
--returns the result Point (1.000000000000000 2.000000000000000).
--Relationship:
--ST_Coutains()/ST_WithIn(); ST_Covers()/ST_CoveredBy();
--ST_Cross() / ST_Intersects()
SELECT NEW ST_Polygon( 'Polygon(( 0 0, 2 0, 1 2, 0 0 ))' ).ST_Contains( NEW ST_Point( 1, 1 ) ) FROM dummy;
--Measurement:
--ST_Distance(): Calculate the shortest distances between two geometries.
SELECT NEW ST_Point(0, 0).ST_Distance( NEW ST_Point(5, 0) ) FROM dummy;
To learn more about the Spatial Processing with SAP HANA, please refer to the video list by SAP HANA Academy.
SAP HANA Academy - Spatial YouTube
3).Geo-Content&Service:
SAP HANA not only provide the capabilities of storing and processing spatial data, but also include the Geo-Content(shape of continental, country, state etc) and map client service to facilitate the spatial-related application development.
Geo-Content: The geo-content provides generalized administration boundaries (GAB) and postal codes (POC). The geo-content for GAB is provided in CSV files, whereas the geo-content for POC is provided in shape files.
Spatial Map Client: The spatial map client provides an interface to use HERE maps.
Spatial Content Viewer: The spatial content viewer is a simple web application that allows you to view geo-content in the predefined geo models (database schemas) called SAP_SPATIAL and SAP_SPATIAL_POSTAL. You need this to view the geo-content on HERE maps. To use the spatial content viewer, you need the spatial map client.
To try out the geo-content&service in SAP HANA, please refer to the section of Additional Services for SAP HANA Spatial
http://help.sap.com/hana/sap_hana_spatial_reference_en.pdf
Spatial Demo app of B1 Summit 2015 for Sales Analysis on map
An overview of Spatial Demo App in B1 Summit 2015
The B1 Summit 2015 Spatial Demo App allows you visualize the sales analysis on the map for SAP Business One by Country, State, and Year. The shape of state will be outlined on the map and painted with the color with different transparency. The darker of its color, the higher sales revenue. And you can drill down top 10 customers on the state and explore the customers detail on the map. You can use the demo app for any country, as long as you the customer address well maintained and GAB data imported for the target country.
Demo recording:
The demo app is taking the Spatial Content Viewer as reference, using the following:
-GAB: generalized administration boundaries, the screen below is based on business data of SBODEMOUS, and the GAB for North America from SAP HANA.
-Spatial Map Client
-JavaScript APIs from HERE Maps - HERE Developer: Draw and color the polygon of the state based on the ranking by Sales Revenue, popup BubleInfo to show the detail on clicking the state and drill down to further action such as Top 10 customers for the state.
-Semantic Layer of SAP Business One: Real-time Profitability Analysis Query (/sap/<b1companydb>/ar/case/SalesAnalysisQuery)
Business Partner Explorer on Map
Sales Analysis on Map
How to setup and run the spatial demo app for B1 Summit 2015?
Prerequisites:
1.HANA SP09
2.B1H 9.1 PL09
3.Map Client (check step 1 below)
4.GAB (check step 1 below)
Step 1: Refer to the the section 4.3 Additional Services for setting up SAP HANA Spatial
Follow the steps in sequences in the document http://help.sap.com/hana/sap_hana_spatial_reference_en.pdf
4.3.1 Download Files for Additional Services from SAP Support Portal: (Installations and Upgrades | SAP Support Portal)
Please read the section in sap_hana_spatial_reference above carefully.
Download the Spatial Map Client, and the GAB files for the target country used in SAP Business One through:
https://support.sap.com/home.html -> Software Downloads -> Search for Software -> search by keyword “Map Client” or ”GAB” (Generalized Admin Boundaries)
For instance, if the customers in your SAP Business One system are mostly based on Europe, then in order to analyze the sale for the state in Europe you'll need download the GEO GAB EUROPE 1.0.
The spatial demo app of B1 summit only requires the Map Client and GAB file.
The "Content Viewer" and "POC" is not required by the B1 Spatial Demo app, so you can ignore them.
4.3.2 Import the Map Client and the Spatial Content Viewer
4.3.3.1 Create Database Schema and Table (GAB)
After schema SAP_SPATIAL created, run the following SQL in SQL Console to grant the SELECT permission on schema SAP_SPATIAL for user _SYS_REPO. For SAP_SPATIAL will be used in the B1 Spatial Models afterwards.
GRANTSELECTONSCHEMA SAP_SPATIAL TO _SYS_REPO WITHGRANTOPTION
4.3.4.1 Import Geo-Content (GAB)
You can follow the query given the guide to import the GAB data files from CSV into the tables in schema SAP_SPATIAL one by one. AREA, AREA_DESCRIPTION, HIERARCHY, HIERARCHY_DESCRIPTION, SHAPE
In case of concerning data load performance, you can refer this document.
Best Practices for SAP HANA Data Loads
4.3.5 Create a User to View Geo-Content (We use the spatial demo app of B1 Summit instead of Geo-Content Viewer)
You can name the user as "SPATIAL" or any name, then assign the schema "SAP_SPATIAL" and "_SYS_BIC" in the system to the user, since the user need to query the B1 Data query via Semantic Layer
Step 2: Download the B1SpatialApp package here.
The B1 Spatial App are made up of three parts
1).B1SpatialModels.zip: The HANA models and procedures package used by B1Spatial App,which should be imported and deployed with SAP HANA Model Management of B1H for the target company. Please note that the
The package structure as below:
spatial
models
-YST_BP_STATE_CODE
-YST_BP
-YST_SALES_ANALYSIS_QUERY
procedures
-YST_GET_SALES_BY_COUNTRY_STATE_PROC
-YST_GET_SALES_BY_STATENAME_YEAR_PROC
2).B1_SPATIAL_APP_1.0_DU.tgz: The delivery unit of the B1 Spatial App. To be imported via HANA Studio.
3).B1SpatialAppContainer_AddOn_LW.zip: The lightweight Add-On package as the container of B1SpatialApp to be open from B1 client. To be deployed via the light weight deployment of Add-On Administration.
Step 3: Import and deploy the models of spatial app with SAP HANA model management of SAP Business One,version for SAP HANA.
Menu path: Administration->Setup->General->SAP HANA Model Management.
If the model is deployed successfully, then you should be able to see the spatial models in your target company package. The screenshot just take sbodemous as example.
In case of error, please assure the following SQL executed before deploying the B1SpatialModels.
GRANTSELECTONSCHEMA SAP_SPATIAL TO _SYS_REPO WITHGRANTOPTION
For troubleshooting of model deployment, you may check trace file of index server through HANA Studio
Menu: HANA Studio=>Administraiton=>Diagnosis Files
Filter by “index”, sorted by the modified column descending.
You can find the most recently updated one, file name something like “indexserver_<hana sever>****.trc”
Double click to open it. and you also can click the refresh button to refresh.
Step 3: Import the Delivery unit (B1_SPATIAL_APP_1.0_DU.tgz) through SAP HANA Studio
Menu Path: File->Import
Select SAP HANA Content, then Delivery Unit to follow the wizard to import B1_SPATIAL_APP_1.0_DU.tgz to your target HANA system.
As a result, you can find a package named B1SpatialDemo under content folder via HANA Studio.
Step 4: Configure the B1 Spatial App for your B1 company.
There are two configurations in the config2.xscfgd inside the package /B1SpatiaDemo/services
companyDB: Replace with the target B1 company DB, the default value as "SBODEMOUS"
companyPackage:Replace with the content package for the company, the default value as "sbodemous"
In the current version, the B1 Spatial App is only connecting to one company at the same time configured as above.
It is recommended to use SAP HANA Web-Based Development Workbench Editor to edit these configuration. To use this editor, please refer this blog.
HANA XS development with the SPS07 Web IDE (focus on debugging)
Now you can open the B1SpatialApp in browser with the URL below:
http://<YOUR_HANA_SERVER>:8000/B1SpatialDemo/ui/index.html
Step 5: Deploy the lightweight container Add-On for B1 Spatial App with Lightweight Extension management in B1 Client
As the B1 Spatial App is web application hosted in HANA XS Engine, to open the B1 Spatial App from B1 client, then you need to deploy the container add-on, which will add a menu for the B1SpatialApp, and open a B1 Add-On form with the B1 Spatial App embedded.
To deploy the lightweight container Add-On for B1 Spatial App, please follow below
Menu path: Administration->Add-On Administration->Manage Extension for Lightweight Deployment
It will open the SAP Business One Extension Manager in the browser, log in with B1SiteUser and password.
1).Click Import button,
2).Browse to select the B1SpatialAppContainer_AddOn_LW.zip from step 2,
3).Click the Upload button.
4).Follow to finish the wizard. As a result, the Container AddOn is deployed.
5).Click tab Company Assignment
6).Select the B1SpatialAppContainer_AddOn_LW, and assign to your target B1 Company.
Now you can start the B1SpatialAppContainer_AddOn_LW from Add-On Manager.
To open the B1 Spatial App, go to Modules->HANA Spatial App->Customer and Sales Analysis on Map.