Вы находитесь на странице: 1из 50

Week 2 Unit 1: Geocoding and

Reverse Geocoding
Geocoding and Reverse Geocoding
Motivation

You have the address of an entity, e.g. a


customer.
SAP SE
To analyze the spatial distribution of your
customers, you need the geolocation. Dietmar-Hopp-Allee 16
69190 Walldorf
Mapping addresses to geolocation is called
geocoding.
The reverse operation mapping geolocations Latitude = 49.2936957
to addresses is called reverse geocoding. Longitude = 8.6394329

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Geocoding and Reverse Geocoding
Process Flow

SAP HANA supports geocoding, reverse Geocoding service,


geocoding, and address cleansing. e.g. HERE

This data transformation/enrichment can


either run locally (reference data is stored in
SAP HANA*) or via a remote service.
Local geocoding and address cleansing is Geocode
handled by SAP HANA smart data quality. Address transform or Longitude,
Data geocode Latitude
index

Geocode reference data

*additional licenses might be required SAP HANA

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Geocoding and Reverse Geocoding
SAP HANA smart data quality Geocode transform

SAP HANA smart data quality


No communication with external data
Geocoding as ONE step within a larger
ETL/data quality pipeline

Address Geocode Longitude,


Data transform Latitude

Geocode reference data

SAP HANA

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Geocoding and Reverse Geocoding
SAP HANA smart data quality Geocode transform

Generates latitude and longitude from an address, and generates addresses from
latitude and longitude coordinates.

Prerequisites
Download and install the geocode directories from SAP Service Marketplace
Set up appropriate permissions

Notes
The accuracy of the point is based on the completeness of the address.
The Geocode node falls back to a lower-level point when the finer level cannot be obtained.
The value in the GEO_ASMT_LEVEL output column identifies the level that the point
represents.
SAP HANA smart data quality may require additional licenses.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 5


Geocoding and Reverse Geocoding
SAP HANA smart data quality Geocode transform (SAP Web IDE)

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Geocoding and Reverse Geocoding
SAP HANA smart data quality Geocode transform

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Geocoding and Reverse Geocoding
Geocode index

SAP HANA geocode index Geocoding service,


e.g. HERE
Uses local reference data or
an external service
Geocodes are stored in a column
of the data table insert

Automatic updates
ID City Str Lon Geocode
/Lat index

Geocode reference data

SAP HANA

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 8


Geocoding and Reverse Geocoding
Geocode index

Generates latitude and longitude from an address

Options
Use the SAP HANA smart data quality geocode provider
Or use a custom provider

Prerequisites
Set up SAP HANA smart data quality
Or implement a custom geocode provider, e.g. using JavaScript on XSC

Notes
The assignment of the point may fail if the address cannot be resolved on a specific
address level.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 9


Geocoding and Reverse Geocoding
Geocode index

CREATE GEOCODE INDEX "HSGS"."GCI_ADDRESSES" ON "HSGS"."ADDRESSES" (


"LOC_4326" GEOCODE,
"AWARDEE_COUNTRY" COUNTRY,
"AWARDEE_STATE" STATE,
"AWARDEE_CITY" CITY,
"AWARDEE_ZIP" POSTAL_CODE,
"AWARDEE_STREET" ADDRESS_LINE
) ASYNC FLUSH QUEUE AFTER 1000 ROWS;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 10


Geocoding and Reverse Geocoding
Additional information

SAP HANA Spatial Reference


5.2 Geocoding

SAP HANA Smart Data Integration


Configuration Guide
5.3 Geocode

SAP HANA Academy


Smart Data Quality/Integration:
Geocode Transformation

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 11


Thank you

Contact information:

open@sap.com
2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 13


Week 2 Unit 2: Spatial Aggregation
and Set Operations
Spatial Aggregation and Set Operations
Introduction

Set operations
Operations performed on a set of geometries, e.g. the intersection of the trading
areas of your sales stores and the downtown business area.

Aggregation
Grouping operations on a set of geometries, e.g. the convex hull over the
customer location of a sales store.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Spatial Aggregation and Set Operations
Set operation methods

You use set operation methods to relate two geometries.

SELECT "REGION_1".ST_Union("REGION_2")
FROM "SALES_REGIONS";

Analogous to arithmetic functions over numerical data


Shape A
Union
SELECT "REVENUE" - "COST" AS "PROFIT Shape B
FROM "SALES";

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Spatial Aggregation and Set Operations
List of available set operation methods

"SHAPE_A".ST_Union("SHAPE_B")

"SHAPE_A".ST_Intersection("SHAPE_B")
Union
"SHAPE_A".ST_Difference("SHAPE_B")
Intersection
"SHAPE_A".ST_SymDifference("SHAPE_B")
Difference

Symmetric
ST_IntersectionAggr("SHAPE")
Difference
ST_UnionAggr("SHAPE")

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Spatial Aggregation and Set Operations
Aggregation

You use aggregate methods to group geometries.


SELECT "CONTINENT", ST_UnionAggr("COUNTRY_SHAPE")
FROM "COUNTRIES
GROUP BY "CONTINENT";

Analogous to aggregation methods over numerical data


SELECT "COUNTRY", SUM("REVENUE")
FROM "SALES
GROUP BY "COUNTRY";

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 5


Spatial Aggregation and Set Operations
List of available geometry aggregation methods

ST_AsSVGAggr("SHAPE")
Returns a complete or partial SVG document that renders the
geometries in a group

ST_ConvexHullAggr ("SHAPE")
Returns the convex hull for all of the geometries in a group

ST_EnvelopeAggr ("SHAPE")
Returns the bounding rectangle for all of the geometries in a group

ST_IntersectionAggr ("SHAPE")
Returns the spatial intersection of all of the geometries in a group

ST_UnionAggr ("SHAPE")
Returns the spatial union of all of the geometries

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Spatial Aggregation and Set Operations
Further information

SAP HANA Spatial Reference


Aggregate Methods
Set Operation Methods

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Thank you

Contact information:

open@sap.com
2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 9


Week 2 Unit 3:
Spatial Predicates and Joins
Spatial Predicates and Joins
Introduction

You use spatial predicates to evaluate the relationship of


two geometries.

Example: Identify customers within a specific sales area.

SELECT * FROM "CUSTOMERS" "POINT".ST_Within("RECTANGLE") = 1


WHERE "LOCATION".ST_Within([geometry]) = 1;

Analogous to comparisons over numerical data

SELECT * FROM "SALES"


WHERE "AMOUNT" BETWEEN 100 AND 500;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Spatial Predicates and Joins
Examples

g1 g2 g1
g2
g2
g1 g2 g1
g2 g2
g1

g1.ST_Within(g2) g1 g1 g2
g2
g1 g2 = g1 I(g1) E(g2) = g1

g2 g2
g1.ST_Contains(g2) g1 g1.ST_Crosses(g2)

g1 g2 = g2 I(g1) I(g2) g2 I(g1) I(g2) (g1 g2 g1) (g1 g2 g2)]

g1
g1
g2 g1.ST_Touches(g2)
g1.ST_Intersects(g2) g1
g1 (g1 g2 ) (B(g1) B(g2) = )
g1 g2

g1 g2
g1
g1 g1.ST_Overlaps(g2)
g2 g2
g1 g2 (I(g1) I(g2) )
g2 (I(g1) E(g2) )
g1.ST_Disjoint(g2)
g1.ST_Equals(g2) g1.ST_Covers(g2) *
g1 g2 (E(g1) I(g2) )
g1 g2 =
g1 = g2 g1 g2 = g2
* No OGC standard
2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3
Spatial Predicates and Joins
ST_WithinDistance

The ST_WithinDistance method tests if the


smallest distance between two geometries is
within a specified distance, taking tolerance
into consideration.

"SHAPE_A".ST_WithinDistance("SHAPE_B",
[distance],[unit])

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Spatial Predicates and Joins
ST_Relate predicate use

The ST_Relate method tests if a geometry is spatially related to another geometry by looking for
intersection between the interior, boundary, and exterior.
"SHAPE_A".ST_Relate("SHAPE_B" , 'T*F**F***') = 0
You pass a DE-9IM string reflecting the intersection results to test for. If the conditions are satisfied,
ST_Relate returns 1; if not, 0 is returned.

g2 I g2 B g2 E T = one of: 0, 1, 2 (an intersection of any dimension)


F = -1
g1 I 1 2 3
* = -1, 0, 1, 2 (any value)
g1 B 4 5 6 0=0
g1 E 7 8 9 1=1
2=2
I = Interior
B = Boundary
E = Exterior

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 5


Spatial Predicates and Joins
Using spatial predicates in SAP HANA SQL

In the SELECT clause


SELECT "LOCATION".ST_Within([geometry]), "NAME" FROM "CUSTOMERS";

In the WHERE clause


SELECT "NAME" FROM "CUSTOMERS" WHERE "LOCATION".ST_Within([geometry]) = 1;

As JOIN condition
SELECT * FROM "STORES" AS S
LEFT JOIN "CUSTOMERS" AS C
ON C."LOCATION".ST_Within(S."TRADING_AREA") = 1;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Spatial Predicates and Joins
Additional information

SAP HANA Spatial Reference


Predicates

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Thank you

Contact information:

open@sap.com
2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 9


Week 2 Unit 4: Access, Computation,
and Transformation Functions
Access, Computation, and Transformation Functions
Introduction

Besides set operations and aggregation functions,


SAP HANA provides methods to
Access properties of a geometry
e.g. the X coordinate/longitude of a point
Compute properties of a geometry
e.g. the area of a polygon
Transform a geometry
e.g. a point into a circle given a buffer

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Access, Computation, and Transformation Functions
Access functions

SAP HANA supports methods to access ST_YMax()


geometry properties.
ST_YMin()
"POINT".ST_X(), "POINT".ST_Y()
"GEOM".ST_XMax(), "GEOM".ST_XMin()
2nd Point
"LINE".ST_NumPoints(), "LINE".ST_PointN([n]) NumPoints = 3
"GEOM".ST_Dimension() Start End
"LINE".ST_StartPoint(), "LINE".ST_EndPoint()
"GEOM".ST_GeometryType()
"GEOM".ST_Srid() Geometry Type
"GEOM".ST_ExteriorRing() = ST_Polygon
Exterior Ring
"GEOM".ST_InteriorRingN([n])

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Access, Computation, and Transformation Functions
Computation functions

SAP HANA supports methods to compute


geometry properties.
"LINE".ST_Length()
"GEOM".ST_Perimeter()
Length Perimeter Area
"GEOM".ST_Area()
"GEOM".ST_Centroid()
"GEOM".ST_Distance("GEOM")
Centroid Distance
"GEOM".ST_isValid(), "GEOM".ST_isEmpty(),
"LINE".ST_isClosed(), "GEOM".ST_isSimple()

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Access, Computation, and Transformation Functions
ST_Relate

The ST_Relate method tests if a geometry value is spatially related to another geometry value by
testing for the intersection between the interior, boundary, and exterior of two geometries.
"SHAPE_A".ST_Relate("SHAPE_B") = '212111212'
The result is a 9-character string in DE-9IM format, where each character of the string represents the
dimension of the result of an intersection test.

g2 I g2 B g2 E
g1 I 1 2 3 In the above example, the first digit is '2', which means the
g1 B 4 5 6 intersection of the interiors of SHAPE_A and SHAPE_B
g1 E 7 8 9 has dimension 2.

I = Interior
B = Boundary
E = Exterior

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 5


Access, Computation, and Transformation Functions
Transformation functions

SAP HANA supports methods to transform


geometries.
"GEOM".ST_Boundary()
Boundary Buffer
"GEOM".ST_Buffer([distance])
"GEOM".ST_ConvexHull()
"GEOM".ST_Envelope()
Convex Hull Envelope
"GEOM".ST_Transform([srid])

Transform

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Access, Computation, and Transformation Functions
Additional information

SAP HANA Spatial Reference


Supported Methods

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Thank you

Contact information:

open@sap.com
2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 9


Week 2 Unit 5:
Spatial Clustering
Spatial Clustering
Introduction

SAP HANA supports clustering of spatial data (points).


You use clustering to divide/separate points into
meaningful groups.

SAP HANA supports three clustering algorithms


spherical clusters
Grid
K-means
DBSCAN

When clustering, you can


Associate each data point with a cluster non-spherical clusters
Derive cluster properties, like centroid and envelope
Aggregate data of the clusters data points

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 2


Spatial Clustering
Grid

Quick and easy way to use clustering

Methods
ST_ClusterID()
ST_ClusterEnvelope()

Cells tessellate the grid.


4*3 grid clustering
Every cell has a unique identifier.
SELECT ST_ClusterID(), ST_ClusterEnvelope(), COUNT(*) AS C
FROM "CUSTOMERS"
GROUP CLUSTER BY "LOCATION"
USING GRID X CELLS 10 Y CELLS 10;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 3


Spatial Clustering
K-means

Centroid-based, iterative clustering method

Methods
ST_ClusterID()
ST_ClusterCentroid()

Suitable for spherical clusters.

Initialization methods: RANDOM PARTITION, FORGY k-means clustering


SELECT ST_ClusterID(), ST_ClusterCentroid(), COUNT(*) AS C
FROM "CUSTOMERS"
GROUP CLUSTER BY "LOCATION"
USING KMEANS CLUSTERS 10;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 4


Spatial Clustering
DBSCAN

Density-based clustering method

Methods
ST_ClusterID()

Suitable for non-spherical clusters.

Parameters: EPS, MINPTS


SELECT ST_ClusterID(), COUNT(*) AS C DBSCAN clustering
FROM "CUSTOMERS"
GROUP CLUSTER BY "LOCATION"
USING DBSCAN EPS 40 MINPTS 50;

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 5


Spatial Clustering
Window functions

Spatial clustering is supported in window functions.

SELECT ST_ClusterID() OVER (


CLUSTER BY "LOCATION" USING KMEANS CLUSTERS 100
) AS "CLUSTER_ID", "NAME", "STATUS"
FROM "CUSTOMERS"
ORDER BY "CLUSTER_ID";

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 6


Spatial Clustering
Example UI

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 7


Spatial Clustering
Additional information

SAP HANA Spatial Reference


Spatial Clustering

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 8


Thank you

Contact information:

open@sap.com
2016 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved. Public 10