SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Determine the Distance to a Target POI

Learn how you can select specific location points via SQL and determine the distance between two points in SAP HANA Cloud, SAP HANA database.

Overview

You will learn

  • How to transform your location point to a Spatial Reference System
  • How to select a target POI from the sample data
  • How to determine the distance between two location points
Thomas Jung T Thomas Jung August 21, 2026
Created by July 26, 2021
Contributors

More from Thomas Jung

See all 233 tutorials by Thomas Jung →

Prerequisites

Prerequisites

Steps

Intro

In this tutorial, you will learn how to determine the distance to a target Point of Interest (POI). This includes three steps:

  • Select a Location via SQL
  • Select a Target POI
  • Determine distance between two points

Imagine you are done working for today, step out of the office and want to go to a bar in London to grab your well-deserved home-made iced tea.

In this exercise, you will calculate the distance between your location and a POI of the type bar in the table LONDON_POI.


Step 1 Select a location via SQL

You are starting your trip at Canary Wharf in London. In this step, you will use a select statement reflecting your starting point location as type ST_Geometry.

  1. First, you will need to find the latitude and longitude of your location. Web mapping services like Google Maps can help here. Visit maps.google.com and zoom-in to Canary Wharf in London. Right-click on the big round-about and select What’s here?.

    google maps what’s here
    google maps what’s here

  2. You can retrieve the coordinates from the small overlay at the bottom of the window or copy and paste from the current URL.

    google maps coordinates
    google maps coordinates

  3. Next, you need to bring these coordinates into SAP HANA Cloud, SAP HANA database. To do that, you can use the function ST_GeomFromText(*). This constructor for geometries expects a Well-known Text (WKT) as well as the associated spatial reference system as input. Latitude and longitude can be easily assembled to match the expected WKT string. The associated spatial reference system in this case has id 4326 (WGS84).

    SQL

SELECT ST_GeomFromText(‘POINT(-0.026859 51.505748)’, 4326) FROM DUMMY;

Code

4. If you use a SQL editor with built-in spatial visualization, like `DBeaver`, you will be able to preview the location and double-check that it matches your previously selected location.

 ![Dbeaver.io preview location](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-smart-multi-model-3/ss-03-dbeaver-preview-location.png)

5. To make the following exercises more convenient, it is a good idea to transform this point to the same spatial reference system as our data from OpenStreetMap (SRS with `id 32630`). We can extract the Well-known Text representation by using the function [`ST_AsWKT`(*)](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/LATEST/en-US/7a169dff787c1014a095b86992806f14.html).

```SQL
SELECT ST_GeomFromText('POINT(-0.026859 51.505748)', 4326) .ST_Transform(32630) .ST_AsWKT() FROM DUMMY;
  1. In the Results Panel you should now see the transformed coordinates:

    Code

POINT (706327.107445 5710259.94449)

Code


7. Next, you need to select this point with Spatial Reference System `32630` by executing the following statement.

   ```SQL
SELECT ST_GeomFromText('POINT (706327.107445 5710259.94449)', 32630) FROM DUMMY;
Step 2 Select a target POI
+
Step 4 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Select a location via SQL 2. Select a target POI 3. Determine distance between two points 4. Test yourself
Next