# tf\_raster\_graph\_shortest\_slope\_weighted\_path

Aggregate point data into x/y bins of a given size in meters to form a dense spatial grid, computing the specified aggregate (using `agg_type`) across all points in each bin as the output value for the bin. A Gaussian average is then taken over the neighboring bins, with the number of bins specified by `neighborhood_fill_radius`, optionally only filling in null-valued bins if `fill_only_nulls` is set to true.

The graph shortest path is then computed between an origin point on the grid specified by `origin_x` and `origin_y` and a destination point on the grid specified by `destination_x` and `destination_y`, where the shortest path is weighted by the nth exponent of the computed slope between a bin and its neighbors, with the nth exponent being specified by `slope_weighted_exponent`. A max allowed traversable slope can be specified by `slope_pct_max`, such that no traversal is considered or allowed between bins with absolute computed slopes greater than the percentage specified by `slope_pct_max`.

```
SELECT * FROM TABLE(
    tf_raster_graph_shortest_slope_weighted_path(
        raster => CURSOR(
            SELECT x, y, z FROM table
        ),
        agg_type => <'AVG'|'COUNT'|'SUM'|'MIN'|'MAX'>,
        bin_dim => <meters>,
        geographic_coords => <true/false>,
        neighborhood_fill_radius => <num bins>,
        fill_only_nulls => <true/false>,
        origin_x => <origin x coordinate>,
        origin_y => <origin y coordinate>,
        destination_x => <destination x coordinate>,
        destination_y => <destination y coordinate>,
        slope_weighted_exponent => <exponent>,
        slope_pct_max => <max pct slope>
    )
```

**Input Arguments**

<table><thead><tr><th width="280">Parameter</th><th width="272">Description</th><th>Data Types</th></tr></thead><tbody><tr><td><code>x</code></td><td>Input x-coordinate column or expression of the data to be rasterized.</td><td>Column &#x3C;FLOAT | DOUBLE></td></tr><tr><td><code>y</code></td><td>Input y-coordinate column or expression of the data to be rasterized.</td><td>Column &#x3C;FLOAT | DOUBLE> (must be the same type as <code>x</code>)</td></tr><tr><td><code>z</code></td><td>Input z-coordinate column or expression of the data to be rasterized.</td><td>Column &#x3C;FLOAT | DOUBLE></td></tr><tr><td><code>agg_type</code></td><td>The aggregate to be performed to compute the output z-column. Should be one of <code>'AVG'</code>, <code>'COUNT'</code>, <code>'SUM',</code> <code>'MIN'</code>, or <code>'MAX'.</code></td><td>TEXT ENCODING NONE</td></tr><tr><td><code>bin_dim</code></td><td>The width and height of each x/y bin . If <code>geographic_coords</code> is true, the input x/y units will be translated to meters according to a local coordinate transform appropriate for the x/y bounds of the data.</td><td>DOUBLE</td></tr><tr><td><code>geographic_coords</code></td><td>If true, specifies that the input x/y coordinates are in lon/lat degrees. The function will then compute a mapping of degrees to meters based on the center coordinate between x_min/x_max and y_min/y_max.</td><td>BOOLEAN</td></tr><tr><td><code>neighborhood_bin_radius</code></td><td>The radius in bins to compute the gaussian blur/filter over, such that each output bin will be the average value of all bins within <code>neighborhood_fill_radius</code> bins.</td><td>BIGINT</td></tr><tr><td><code>fill_only_nulls</code></td><td>Specifies that the gaussian blur should only be used to provide output values for null output bins (i.e. bins that contained no data points or had only data points with null Z-values).</td><td>BOOLEAN</td></tr><tr><td><code>origin_x</code></td><td>The x-coordinate for the starting point for the graph traversal, in input (not bin) units.</td><td>DOUBLE</td></tr><tr><td><code>origin_y</code></td><td>The y-coordinate for the starting point for the graph traversal, in input (not bin) units.</td><td>DOUBLE</td></tr><tr><td><code>destination_x</code></td><td>The x-coordinate for the destination point for the graph traversal, in input (not bin) units.</td><td>DOUBLE</td></tr><tr><td><code>destination_y</code></td><td>The y-coordinate for the destination point for the graph traversal, in input (not bin) units.</td><td>DOUBLE</td></tr><tr><td><code>slope_weighted_exponent</code></td><td>The slope weight between neighboring raster cells will be weighted by the <code>slope_weighted_exponent</code> power. A value of 1 signifies that the raw slopes between neighboring cells should be used, increasing this value from 1 will more heavily penalize paths that traverse steep slopes.</td><td>DOUBLE</td></tr><tr><td><code>slope_pct_max</code></td><td>The max absolute value of slopes (measured in percentages) between neighboring raster cells that will be considered for traversal. A neighboring graph cell with an absolute slope greater than this amount will not be considered in the shortest slope-weighted path graph traversal</td><td>DOUBLE</td></tr></tbody></table>

**Output Columns**

```
/* Compute the shortest slope weighted path over a 30m Copernicus 
Digital Elevation Model (DEM) input raster comprising the area around Mt. Everest,
to compute the shorest slope-weighted path from the plains of Nepal to the peak */

create table mt_everest_climb as
select
  path_step,
  st_setsrid(st_point(x, y), 4326) as path_pt
from
  table(
    tf_raster_graph_shortest_slope_weighted_path(
      raster => cursor(
        select
          st_x(raster_point),
          st_y(raster_point),
          z
        from
          copernicus_30m_mt_everest
      ),
      agg_type => 'AVG',
      bin_dim => 30,
      geographic_coords => TRUE,
      neighborhood_fill_radius => 1,
      fill_only_nulls => FALSE,
      origin_x => 86.01,
      origin_y => 27.01,
      destination_x => 86.9250,
      destination_y => 27.9881,
      slope_weight_exponent => 4,
      slope_pct_max => 50
    )
  );
```

<figure><img src="https://875484548-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgWRc88gdQeZ7mRBB46Rx%2Fuploads%2Fgit-blob-667498d1fc3110083e30b9c64887bd8af3b90516%2Fmt_everest_shortest_slope_weighted_path.png?alt=media" alt=""><figcaption><p>Result of the example query above, showing the shortest slope-weighted path between the Nepali planes and the peak of Mt. Everest. The path closely mirrors the actual climbing route used.</p></figcaption></figure>
