Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-10/hana-cloud-smart-multi-model-10.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_profile

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-10/hana-cloud-smart-multi-model-10.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_name
parser: v2
auto_validation: true
time: 15
Expand Down Expand Up @@ -49,7 +49,7 @@

1. Here is the complete statement that you can run in your example. As previously, first you create a **table type** and then the **GRAPH procedure**:

```SQL
```SQL
CREATE TYPE "TT_SPOA_VERTICES" AS TABLE ("osmid" BIGINT, "CALCULATED_COST" DOUBLE);
CREATE OR REPLACE PROCEDURE "GS_SPOA"(
IN i_startVertex BIGINT, -- the key of the start vertex
Expand All @@ -72,13 +72,13 @@

2. As an example, what to do with the SPOA method, you can calculate, where you can go in 300 seconds from your starting point Canary Wharf with this statement:

```SQL
```SQL
CALL "GS_SPOA" (1433737988, 300, ?);
```

3. To visualize the data, let's wrap it in a function and do some post-processing to our graph results. With `resultType` = `POINTS` the function will **return the raw data**, i.e. the individual street intersections that are reachable given a certain maximum of travel time. With `resultType` = `CONVEXHULL` the function will **calculate a convex hull of the points and return a single shape**. Finally, with `resultType` = `HEXAGON` a spatial clustering is applied, and **travel times are averaged for each cluster cell**.

```SQL
```SQL
CREATE OR REPLACE FUNCTION "F_SPOA_VERTICES"(
IN i_startVertex BIGINT, -- the key of the start vertex
IN i_max DOUBLE, -- the maximum distance/cost
Expand Down Expand Up @@ -109,7 +109,7 @@

4. You can use these three statements to explore from your starting point Canary Wharf:

```SQL
```SQL
SELECT * FROM "F_SPOA_VERTICES"(1433737988, 60, 'POINTS') ORDER BY "CALCULATED_COST" DESC;
SELECT * FROM "F_SPOA_VERTICES"(1433737988, 60, 'CONVEXHULL') ORDER BY "CALCULATED_COST" DESC;
SELECT * FROM "F_SPOA_VERTICES"(1433737988, 240, 'HEXAGON') ORDER BY "CALCULATED_COST" DESC;
Expand All @@ -123,7 +123,7 @@

So let's calculate 3 min drive time areas around all the bike repair shops in London. You'll use the `MAP_MERGE` operation to digest multiple POI's:

```SQL
```SQL
CREATE OR REPLACE FUNCTION "F_SPOA_VERTICES_MULTI" (IN i_filter VARCHAR(5000), IN i_max DOUBLE, IN i_resultType VARCHAR(20))
RETURNS TABLE("ID" BIGINT, "SHAPE" ST_GEOMETRY(32630), "CALCULATED_COST" DOUBLE)
LANGUAGE SQLSCRIPT READS SQL DATA AS
Expand All @@ -150,7 +150,7 @@

1. First, select the tables and then create a **GRAPH workspace** with these statements:

```SQL
```SQL
SELECT * FROM "LONDON_TUBE_STATIONS";
SELECT * FROM "LONDON_TUBE_CONNECTIONS";
CREATE GRAPH WORKSPACE "TUBE_GRAPH"
Expand All @@ -165,7 +165,7 @@

When you traverse a network in a breadth first search manner, you explore the vertices level by level. Starting at a vertex, you first visit all its direct neighbors, then the neighbors of the neighbors and so forth. BFS is a fundamental building block for many custom graph algorithms. In SAP HANA Cloud, SAP HANA database you can "hook" into the vertex/edge "visit" events, executing any logic.

```SQL
```SQL
TRAVERSE BFS ('ANY') :g FROM :v_start
ON VISIT VERTEX (Vertex v_visited, BIGINT lvl) {
[any logic goes here]
Expand All @@ -176,15 +176,15 @@

2. As usual, create the **table type** first:

```SQL
```SQL
CREATE TYPE "TT_RESULT_CC" AS TABLE (
"ID" BIGINT, "CLOSENESS_CENTRALITY" DOUBLE, "NORMALIZED_CLOSENESS_CENTRALITY" DOUBLE, "HARMONIC_CENTRALITY" DOUBLE, "NORMALIZED_HARMONIC_CENTRALITY" DOUBLE
);
```

3. Then, create the **GRAPH procedure**:

```SQL
```SQL
CREATE OR REPLACE PROCEDURE "GS_CC_SINGLE_SOURCE"(
IN i_start BIGINT,
OUT o_vertices "TT_RESULT_CC")
Expand Down Expand Up @@ -225,15 +225,15 @@

4. Once the procedure is created, you can call it:

```SQL
```SQL
CALL "GS_CC_SINGLE_SOURCE"(117, ?);
```

**The closeness centrality measure for a single vertex in a network is not very meaningful**. You need to calculate the centrality for all vertices to find the most important one. You can do this by adding a loop into your GRAPH program. A nice way to implement such loops in a parallel way is by using the `MAP_MERGE` operator in `SQLScript`. For this, you need to wrap the procedure in a function like you did in [tutorial 9, step 4](hana-cloud-smart-multi-model-9).

5. Create the **function** like this:

```SQL
```SQL
CREATE OR REPLACE FUNCTION "F_CC_SINGLE_SOURCE"(IN i_start BIGINT)
RETURNS "TT_RESULT_CC"
LANGUAGE SQLSCRIPT READS SQL DATA AS
Expand All @@ -245,7 +245,7 @@

6. Next, you can invoke this function on a set input parameter in a parallel way.

```SQL
```SQL
CREATE OR REPLACE FUNCTION "F_CC_MAP_MERGE" ()
RETURNS "TT_RESULT_CC"
LANGUAGE SQLSCRIPT READS SQL DATA AS
Expand All @@ -258,13 +258,13 @@

7. Then you can select from it:

```SQL
```SQL
SELECT * FROM "F_CC_MAP_MERGE"() ORDER BY "NORMALIZED_CLOSENESS_CENTRALITY" DESC;
```

8. Again, you can mix the results from a graph function with other SQL operations, like a JOIN.

```SQL
```SQL
SELECT *
FROM "F_CC_MAP_MERGE"() AS C
LEFT JOIN "LONDON_TUBE_STATIONS" AS S
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-4/hana-cloud-smart-multi-model-4.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_profile

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-4/hana-cloud-smart-multi-model-4.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_name
parser: v2
auto_validation: true
time: 10
Expand Down Expand Up @@ -45,49 +45,49 @@

1. First, select the two points from the previous tutorials using this statement:

```SQL
```SQL
SELECT
ST_GeomFromText('POINT (706327.107445 5710259.94449)', 32630) AS START_PT,
SHAPE AS TARGET_PT
FROM LONDON_POI lp
WHERE "osmid" = 6274057185;
```
```



2. To create a line geometry, which is connecting both points, you can then use the function [`ST_MakeLine`(*)](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/LATEST/en-US/57758b2af95346db9a478a53ec2c4ccb.html).

```SQL
```SQL
SELECT ST_MakeLine(START_PT, TARGET_PT) AS CONN_LINE
FROM
(
-- previous statement
);
```
```

3. To retrieve an arbitrary point on this line, we need to use function [`ST_LineInterpolatePoint`(*)](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/LATEST/en-US/c8efe60825514403865090fdf1dc1550.html), which takes a fraction of the line as argument. For retrieving the center point of the line, we pass the value 0.5.

```SQL
```SQL
SELECT CONN_LINE.ST_LineInterpolatePoint(0.5) AS CENTER_PT
FROM
(
-- previous statement
);
```
```

4. As a final step, we would like to draw a circle with radius distance (start, target)/2 + 500 around `CENTER_PT`. The respective function, which takes the radius as an input, is called [`ST_Buffer`(*)](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/LATEST/en-US/010c53e227a94966bb009d52d9ec47a2.html).

```SQL
```SQL
SELECT CENTER_PT.ST_Buffer(4835) AS AREA
FROM
(
-- previous statement
);
```
```

5. The above steps can be combined into a single select using method chaining.

```SQL
```SQL
SELECT
ST_MakeLine(
ST_GeomFromText('POINT (706327.107445 5710259.94449)', 32630),
Expand All @@ -97,7 +97,7 @@
.ST_Buffer(5000) AS AREA
FROM LONDON_POI
WHERE "osmid" = 6274057185;
```
```


### Add flags for all nodes in a circle
Expand All @@ -106,15 +106,15 @@

1. First, we need to enhance the existing vertex table by column `in_scope`.

```SQL
```SQL
ALTER TABLE LONDON_VERTICES ADD (IN_SCOPE INTEGER);
```

2. Second, we fill the column with 0 or 1 based on the intersection with the identified area. We can use function [`ST_Intersects`(*)](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/LATEST/en-US/7a19e197787c1014a13087ee8f970cce.html) to determine if two geometries intersect or not.

3. Instead of using an [UPDATE](https://help.sap.com/viewer/c1d3f60099654ecfb3fe36ac93c121bb/LATEST/en-US/20ff268675191014964add3d17700909.html) statement, we will use [MERGE INTO](https://help.sap.com/viewer/c1d3f60099654ecfb3fe36ac93c121bb/LATEST/en-US/3226201f95764a57810dd256c9524d56.html), which allows a more complex update logic.

```SQL
```SQL
MERGE INTO LONDON_VERTICES lv
USING
(
Expand All @@ -135,9 +135,9 @@

4. You can confirm that you properly selected the nodes by using your preferred tool for visualizing the result set with this query:

```SQL
```SQL
SELECT SHAPE FROM LONDON_VERTICES WHERE IN_SCOPE = 1;
```
```

![relevant nodes](ss-02-relevant-nodes.png)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-9/hana-cloud-smart-multi-model-9.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_profile

Check warning on line 1 in tutorials/hana-cloud-smart-multi-model-9/hana-cloud-smart-multi-model-9.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_name
parser: v2
auto_validation: true
time: 20
Expand Down Expand Up @@ -127,13 +127,13 @@

1. First, let's calculate **`PUBINESS`** by counting pubs within 100m distance and add this to our `LONDON_EDGES` table. You are using the spatial `ST_WithinDistance` predicate as join condition:

```SQL
```SQL
ON pubs."SHAPE".ST_WithinDistance(e."EDGESHAPE", 100) = 1
```

2. This is the complete statement to alter the table and adding our **`PUBINESS`** measure. Paste and execute it:

```SQL
```SQL
ALTER TABLE "LONDON_EDGES" ADD ("PUBINESS" DOUBLE DEFAULT 0);
MERGE INTO "LONDON_EDGES"
USING (
Expand All @@ -149,7 +149,7 @@

3. Using this statement, you can check the distribution of this new **`PUBINESS`** property.

```SQL
```SQL
SELECT "PUBINESS", COUNT(*) AS C FROM "LONDON_EDGES" GROUP BY "PUBINESS" ORDER BY "PUBINESS" ASC;
```

Expand All @@ -159,7 +159,7 @@

Now, you can use the new measure as part of the cost function for path finding with mode "**pub**".

```
```
Shortest_Path(:g, :v_start, :v_end, (Edge e) => DOUBLE {
RETURN :e."length"/(5.0*:e."PUBINESS"+1.0);
}, :i_direction);
Expand All @@ -169,7 +169,7 @@
For finding the path with mode "**bike**", you can use a conditional cost function. Street segments which are of type "**cycleway**" are boosted by dividing the length by 10.


```SQL
```SQL
Shortest_Path(:g, :v_start, :v_end, (EDGE e)=> DOUBLE {
IF(:e."highway" == 'cycleway') { RETURN :e."length"/10.0; }
ELSE { RETURN :e."length"; }
Expand All @@ -182,15 +182,15 @@

5. Create a **TABLE TYPE** first with the following statement.

```SQL
```SQL
CREATE TYPE "TT_SPOO_MULTI_MODE" AS TABLE (
"ID" NVARCHAR(5000), "SOURCE" BIGINT, "TARGET" BIGINT, "EDGE_ORDER" BIGINT, "length" DOUBLE, "SPEED_MPH" INT, "highway" NVARCHAR(5000)
);
```

6. Then create the **procedure** with this statement.

```SQL
```SQL
CREATE OR REPLACE PROCEDURE "GS_SPOO_MULTI_MODE"(
IN i_startVertex BIGINT, -- the ID of the start vertex
IN i_endVertex BIGINT, -- the ID of the end vertex
Expand Down Expand Up @@ -231,7 +231,7 @@

7. To see the results, you can again use a **CALL** statement:

```SQL
```SQL
CALL "GS_SPOO_MULTI_MODE"(1433737988, 1794145673, 'ANY', 'pub', ?, ?, ?);
CALL "GS_SPOO_MULTI_MODE"(1433737988, 1794145673, 'ANY', 'bike', ?, ?, ?);
```
Expand All @@ -244,15 +244,15 @@

1. First, as in the previous examples, create the **TABLE TYPE**:

```SQL
```SQL
CREATE TYPE "TT_EDGES_SPOO_F" AS TABLE (
"ID" NVARCHAR(5000), "SOURCE" BIGINT, "TARGET" BIGINT, "EDGE_ORDER" BIGINT, "length" DOUBLE, "SHAPE" ST_GEOMETRY(32630)
);
```
```

2. Then create the **function**:

```SQL
```SQL
CREATE OR REPLACE FUNCTION "F_SPOO_EDGES"(
IN i_startVertex BIGINT,
IN i_endVertex BIGINT,
Expand All @@ -267,22 +267,22 @@
CALL "GS_SPOO_MULTI_MODE"(:i_startVertex, :i_endVertex, :i_direction, :i_mode, o_path_length, o_path_weight, o_edges);
RETURN SELECT lbe.* FROM :o_edges AS P LEFT JOIN "LONDON_EDGES" lbe ON P."ID" = lbe."ID";
END;
```
```

3. Now you can simply calculate the **average** **`PUBINESS`** of a path, or UNION two paths to compare. To calculate the average value of one path, use this statement:

```SQL
```SQL
SELECT AVG("PUBINESS")
FROM "F_SPOO_EDGES"(1433737988, 1794145673, 'ANY', 'pub');
```
```

4. To compare two paths, you can use this statement:

```SQL
```SQL
SELECT "ID", "SHAPE" FROM "F_SPOO_EDGES"(1433737988, 1794145673, 'ANY', 'pub')
UNION
SELECT "ID", "SHAPE" FROM "F_SPOO_EDGES"(1433737988, 1794145673, 'ANY', 'bike');
```
```

5. Visualizing this comparison should look like this:

Expand Down
4 changes: 2 additions & 2 deletions tutorials/hana-cloud-trial-qgis-3/hana-cloud-trial-qgis-3.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in tutorials/hana-cloud-trial-qgis-3/hana-cloud-trial-qgis-3.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_profile

Check warning on line 1 in tutorials/hana-cloud-trial-qgis-3/hana-cloud-trial-qgis-3.md

View workflow job for this annotation

GitHub Actions / checks / checks

content/frontmatter-missing-field

Required frontmatter field missing or empty: author_name
parser: v2
auto_validation: true
time: 10
Expand Down Expand Up @@ -57,7 +57,7 @@

5. Copy the following SQL statement into the SQL Console and execute:

```
```
CREATE VIEW POI_DENSITY AS
(
SELECT
Expand All @@ -67,7 +67,7 @@
FROM "gis_osm_pois_free_1"
GROUP CLUSTER BY "geom" USING HEXAGON X CELLS 100
)
```
```


You can find more information on [Spatial Clustering](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/2020_04_QRC/en-US/7eb3c0e6bbf04fc6bcb9809d81533e6f.html) in the [SAP HANA Spatial Reference](https://help.sap.com/viewer/bc9e455fe75541b8a248b4c09b086cf5/2020_04_QRC/en-US/e1c934157bd14021a3b43b5822b2cbe9.html).
Expand Down
Loading