All Products
Search
Document Center

PolarDB:ST_SetCost

Last Updated:Mar 28, 2026

Assigns a traversal cost value to an array of geographic grids, marking them as barriers in spatial path analysis.

Syntax

gridcost ST_SetCost(geomgrid[] barriers, smallint cost);

Parameters

ParameterTypeDescription
barriersgeomgrid[]The array of geographic grids to assign a cost to.
costsmallintThe traversal cost value. Set to -1 to mark the grids as impassable. For any other value, the cost is expressed as an equivalent distance: a grid with cost = N takes the same effort to traverse as N unobstructed grids.

Description

Use ST_SetCost to define traversal difficulty for specific grid cells in a path-analysis workflow. Common uses include:

  • Blocked areas: Set cost = -1 for grids that cannot be crossed.

  • Rough terrain: Set a positive cost for grids that are harder to traverse. A grid with cost = 3 takes the same effort to cross as three unobstructed grids.

The returned gridcost value pairs the encoded grid array with its assigned cost.

Examples

Assign a traversal cost of 1 to two grids:

SELECT st_setcost(array[st_gridfromtext('GZ01'), st_gridfromtext('GZ1')], 1);

Output:

("{01024002000001000000,0102410100000000}",1)