适用于: Databricks Runtime 17.1 及更高版本
Important
此功能目前以公共预览版提供。
将新点添加到输入线字符串 GEOGRAPHY
中的第 n 个位置或 GEOMETRY
。
Syntax
st_addpoint ( geo1Expr, geo2Expr[, indexExpr] )
Arguments
-
geo1Expr
:一个GEOGRAPHY
或者GEOMETRY
值,用以表示线字符串。 -
geo2Expr
:表示GEOGRAPHY
GEOMETRY
点的值。 -
indexExpr
:一个可选INTEGER
值,指示应在其中添加新点的行字符串中基于 1 的位置。 默认值为 -1。
Returns
如果GEOGRAPHY
和geo1Expr
都属于类型geo2Expr
,则该值为类型GEOGRAPHY
;如果GEOMETRY
和geo1Expr
都属于类型geo2Expr
,则该值为类型GEOMETRY
。
如果 indexExpr
为正值,则返回 GEOGRAPHY
或 GEOMETRY
值为新的线字符串,其 indexExpr
第一个点(从左计数)设置为 geo2Expr
。
如果 indexExpr
为负数,则从右侧测量从 1 开始的添加点的线串位置。
- 如果任何输入为
NULL
,该函数将返回NULL
。 - 输出行字符串的 SRID 值等于输入
GEOGRAPHY
或GEOMETRY
值的通用 SRID 值。 - 输出
GEOGRAPHY
或GEOMETRY
线字符串的维度与该geo1Expr
维度相同。 如果geo2Expr
包含在geo1Expr
中不存在其维度的坐标,则将对应坐标设置为 0。
Error conditions
- 如果
geo1Expr
的类型为GEOGRAPHY
,而geo2Expr
的类型为GEOMETRY
,或者反过来,则函数将返回 DATATYPE_MISMATCH。 - 如果 SRID 值
geo1Expr
不同geo2Expr
,函数将返回 ST_DIFFERENT_SRID_VALUES。 - 在以下任一情况下,该函数将返回 ST_INVALID_ARGUMENT :
- 值
geo1Expr
不是线字符串,也不是空线字符串。 -
geo2Expr
的值不是一个点。 -
geo2Expr
的值是一个空点。
- 值
- 如果值的绝对值为 0 或者比线串中的点数加一还大,则函数返回 ST_INVALID_INDEX_VALUE
Examples
-- We do not specify a position; the point is appended at the end (right) of the linestring.
> SELECT st_asewkt(st_addpoint(st_geomfromtext('LINESTRING(1 2,3 4)', 4326), st_geomfromtext('POINT(7 8)', 4326)));
SRID=4326;LINESTRING(1 2,3 4,7 8)
-- A positive index indicates the position. We add the point at that position in the linestring.
> SELECT st_astext(st_addpoint(st_geomfromtext('LINESTRING(1 2,3 4)'), st_geomfromtext('POINT(7 8)'), 3))
LINESTRING(1 2,3 4,7 8)
-- The position is specified as a negative index. The point is added at that position counting from the right.
-- The point is missing a Z coordinate. This is set to 0 when the point is added in the linestring.
> SELECT st_asewkt(st_addpoint(st_geogfromtext('LINESTRING ZM (1 2 3 4,5 6 7 8)'), st_geogfromtext('POINT M (0 9 99)'), -1))
SRID=4326;LINESTRING ZM (1 2 3 4,5 6 7 8,0 9 0 99)