gentle introduction into geospatial (using sql in sap hana)
TRANSCRIPT
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 1Public
Gentle introduction into Geospatial
[with SQL using SAP HANA]
Vitaliy @Sygyzmundovych RudnytskiyKariera IT, Wrocław, 2016/02
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 2Public
Disclaimer
This presentation outlines our general product direction and should not be relied on in making a
purchase decision. This presentation is not subject to your license agreement or any other agreement
with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to
develop or release any functionality mentioned in this presentation. This presentation and SAP's
strategy and possible future developments are subject to change and may be changed by SAP at any
time for any reason without notice. This document is provided without a warranty of any kind, either
express or implied, including but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this
document, except if such damages were caused by SAP intentionally or grossly negligent.
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 3Public
Let’s start with…
- … Vitaliy Rudnytskiy (aka Witalij Rudnicki)
@Sygyzmundovych
- SAP’s Developer Relations (developers.sap.com)
- IoT
- Based in Wrocław, Poland
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 5Public
How I got into the geospatial for the first time
https://blogs.sap.com/2016/06/24/from-wroclaw-to-warsaw-and-back-iot-analysis-with-sap-hana-sql
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 6Public
How I got into the geospatial for the second time
https://twitter.com/Sygyzmundovych/status/808250140251324416
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 7Public
How I got into the geospatial for the third time
http://www.sap.com/developer/tutorials.html
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 8Public
SAP HANA, Express editiondevelopers.sap.com/sap-hana-express
Now SAP CodeJam on SAP HANA Express edition is available:
https://blogs.sap.com/2017/01/10/sap-hana-express-edition-comes-to-sap-codejam/
SAP HANA, express edition
• targeted to run in resource-constrained environments and contains a rich set of capabilities for a
developer to work with, including geospatial data types and algorithms
• limited to 32 GB of RAM,
• comes as a binary installer or as a pre-configured virtual machine image (ova file)
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 9Public
Spatial: data types in SAP HANA and in SQL/MM standard
http://help.sap.com/saphelp_hanaplatform/helpdata/en/99/d10e4fdaaf41588480a43478e840d5/frameset.htm
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 10Public
SAP HANA SpatialImplementing SQL/MM standard
Spatial data type
CREATE COLUMN TABLE "LOCATIONS"("ID" INTEGER,"DESCRITPION" VARCHAR(100),"LOCAITON"ST_POINT(0));
Spatial query
SELECT "DESCRIPTION"FROM "LOCATIONS"WHERE "LOCATION".ST_Within(NEW ST_POLYGON('POLYGON((0 0,1 0,1 1,0 0))')) = 1;
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 11Public
Spatial SQL/MM
Format Functions Example
SELECT "NAME", "LOCATION".ST_ASTEXT(), "LOCATION".ST_ASGEOJSON()FROM "LOCATIONS";
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 12Public
Spatial Predicates
g1 g2
g1
g2
g1.ST_Touches(g2)
(g1 ∩ g2 ≠ ∅) ∧ (B(g1) ∩ B(g2) = ∅)
g1.ST_Within(g2)
g1 ∩ g2 = g1 ∧ I(g1) ∩ E(g2) = ø
g1.ST_Equals(g2)
g1 = g2
g2
g1
g1 g1.ST_Crosses(g2)
I(g1) ∩ I(g2) ≠ ∅ ∧ (g1 ∩ g2 ≠ g1) ∧ (g1 ∩ g2 ≠ g2)]
g2
g1
g1
g2
g1.ST_Overlaps(g2)
(I(g1) ∩ I(g2) ≠ ∅) ∧
(I(g1) ∩ E(g2) ≠ ∅) ∧
(E(g1) ∩ I(g2) ≠ ∅)
g1.ST_Intersects(g2)
g1 ∩ g2 ≠ ø
g1
g2
g1.ST_Disjoint(g2)
g1 ∩ g2 = ø
g1
g2
g2
g1
g2
g1
g2
g1.ST_Contains(g2)
g1 ∩ g2 = g2 ∧ I(g1) ∩ I(g2) ≠ ø
g2
g1
g1
g1.ST_Covers(g2) *
g1 ∩ g2 = g2
g2
g1
g2
* No OGC standard
g1
g2
g2
g1
g1g2
g1 g2
g1 g2
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 13Public
Trying it out: number π by throwing virtual darts
https://blogs.sap.com/2016/12/14/calculating-number-%CF%80-by-throwing-darts-digitally-in-sap-hana/
https://www.youtube.com/watch?v=M34TO71SKGk
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 14Public
What is the distance between two points?
select new st_point('POINT (0 0)').st_distance(new st_point('POINT (0 1)')) as distance
from dummy;
-- The result is „1”
But on Earth between the two GPS points?select new st_point('POINT (0 0)',4326).st_distance(new st_point('POINT (0 1)',4326)) as
distance from dummy;
-- Now the result is „110574.38855796008”, i.e. 110.57 km
http://help.sap.com/saphelp_hanaplatform/helpdata/en/7a/2ea357787c101488ecd1b725836f07/content.htm
WGS84 - SRID 4326
„The WGS84 standard provides a spheroidal reference surface for the Earth. It is the spatial reference system used by the
Global Positioning System (GPS). The coordinate origin of WGS 84 is the Earth's center, and is considered accurate up to ±1
meter. WGS stands for World Geodetic System.”
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 15Public
Spatial Reference Systems (SRS)
Unit of Measurement (UoM)
Projections to Planar World
distance/area calculations with (acceptable?) distortion
projections: cylindrical, conical, azimuthal, hybrid, …
x
y
Cartesian Coordinate System
simple and fast calculations
distance/area calculations in
euclidean space
r
Round Earth Models
accurate results in specific UoM
more complex calculations
Transformation
Transformation
Transformation
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 17Public
Round Earth Models
Sphere as simplified earth model
radius of earth = 𝑟 = 6371 km (constant)
coordinate just depends on 𝛼 and 𝛽
equator
r
Spheroid as proper earth model (WGS84)
semi major axis = equatorial radius: 𝑒𝑟 = 6378.137 km
semi minor axis = polar radius: 𝑝𝑟 = 6356.752 km
flattening: 𝑓 = (𝑒𝑟 − 𝑝𝑟) / 𝑒𝑟
equator
er
pr
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 18Public
WGS 84 Defining ParametersSource: http://earth-info.nga.mil/GandG/publications/index.html
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 21Public
Poland
Source: https://pl.wikipedia.org/wiki
EPSG 3328
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 22Public
Reference systems: there are 3000+ in total existing
Poland:
http://spatialreference.org/ref/epsg/?search=poland
In Europe:
http://www.crs-geo.eu
In the US:
https://www.nga.mil
DoD World Geodetic System 1984
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 24Public
Trying it out: ASCII world map from open data shape files
Blog to come soon…
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 36Public
Greater Business Insight & Action with Geographic Data
Customer Examples
Improve situational awareness with
location intelligence to keep
travelers safe
Track thoughts of flights per day using
rich 3D mapping interface with spatial and
temporal coordinate to improve flight
operations
Predict impact of natural disasters,
analyze cluster maps to assess critical
infrastructure (roads, hospitals etc.).
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 40Public
Spatial Data: Vector vs Raster
Vector Data
Point, Linestring, Polygon, MultiPoint, …
Networks, Topologies, Point Clouds, …
Metadata
Spatial Reference Systems (SRS)
Unit of Measures (UOM)
Raster Data
Gridded datae.g. digital terrain elevation, weather information
Image datae.g. created from optical or spectral sensors
Metadata
Raster- and Grid information
Spatial- and Band Reference System
Point Linestring Polygon CircularString
14 35 25
17 39 59
16 15 17
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 41Public
Trying it out: Earth Observation API at SAP yaas.io
https://blogs.sap.com/2016/12/07/port-of-antwerp-from-space-perspective/
© 2014 SAP SE or an SAP affiliate company. All rights reserved.
Thank you && Dziękuję!!
SAP Developers Center
http://developers.sap.com
@sygyzmundovych
Vitaliy Rudnytskiy