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
| Parameter | Type | Description |
|---|---|---|
barriers | geomgrid[] | The array of geographic grids to assign a cost to. |
cost | smallint | The 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 = -1for grids that cannot be crossed.Rough terrain: Set a positive cost for grids that are harder to traverse. A grid with
cost = 3takes 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)