文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 84%

14.16.8 空间运算符函数14.16.8 Spatial Operator Functions

OpenGIS 提出了一些可以生成几何体的函数。这些函数旨在实现空间运算符。除不适用的情况外,这些函数支持所有参数类型的组合,根据 开放地理空间联盟 的规范。OpenGIS proposes a number of functions that can produce geometries. They are designed to implement spatial operators. These functions support all argument type combinations except those that are inapplicable according to the Open Geospatial Consortium specification.

MySQL 也实现了一些作为 OpenGIS 扩展的函数,这在函数描述中有所说明。此外,第 14.16.7 节,“几何属性函数” 讨论了几个从现有几何体构建新几何体的函数。有关这些函数的说明,请参见该节:MySQL also implements certain functions that are extensions to OpenGIS, as noted in the function descriptions. In addition, Section 14.16.7, “Geometry Property Functions”, discusses several functions that construct new geometries from existing ones. See that section for descriptions of these functions:

除非另有说明,本节中的函数对其几何参数的处理方式如下:Unless otherwise specified, functions in this section handle their geometry arguments as follows:

  • 如果任何参数为NULL,则返回值为NULL。If any argument is NULL, the return value is NULL.

  • 如果任何几何参数不是语法上格式正确的几何体,则会发生ER_GIS_INVALID_DATA 错误。If any geometry argument is not a syntactically well-formed geometry, an ER_GIS_INVALID_DATA error occurs.

  • 如果任何几何参数是在未定义空间参考系统(SRS)中的语法上良构的几何,将会发生ER_SRS_NOT_FOUND错误。If any geometry argument is a syntactically well-formed geometry in an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND error occurs.

  • 对于接受多个几何参数的函数,如果这些参数不在相同的 SRS 中,会出现ER_GIS_DIFFERENT_SRIDS错误。For functions that take multiple geometry arguments, if those arguments are not in the same SRS, an ER_GIS_DIFFERENT_SRIDS error occurs.

  • 如果任何几何参数具有地理 SRS 的 SRID 值,而该函数不处理地理几何体,则会出现ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS错误。If any geometry argument has an SRID value for a geographic SRS and the function does not handle geographic geometries, an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS error occurs.

  • 对于地理 SRS 几何参数,如果任何参数的经度或纬度超出范围,将会发生错误:For geographic SRS geometry arguments, if any argument has a longitude or latitude that is out of range, an error occurs:

    显示的范围以度为单位。如果 SRS 使用其他单位,则范围使用其单位对应的数值。由于浮点运算,精确的范围限制会有轻微偏差。Ranges shown are in degrees. If an SRS uses another unit, the range uses the corresponding values in its unit. The exact range limits deviate slightly due to floating-point arithmetic.

  • 否则,返回值不为 NULL。Otherwise, the return value is non-NULL.

这些空间操作符函数可用:These spatial operator functions are available:

  • ST_Buffer(g, d [, strategy1 [, strategy2 [, strategy3]]])

    返回一个几何体,该几何体表示从几何值 g 出发,距离不大于 d 的所有点。结果的坐标参考系统与几何参数相同。Returns a geometry that represents all points whose distance from the geometry value g is less than or equal to a distance of d. The result is in the same SRS as the geometry argument.

    如果几何参数为空,ST_Buffer() 返回一个空几何体。If the geometry argument is empty, ST_Buffer() returns an empty geometry.

    如果距离为 0,ST_Buffer() 将返回未改变的几何参数:If the distance is 0, ST_Buffer() returns the geometry argument unchanged:

    mysql> SET @pt = ST_GeomFromText('POINT(0 0)');
    mysql> SELECT ST_AsText(ST_Buffer(@pt, 0));
    +------------------------------+
    | ST_AsText(ST_Buffer(@pt, 0)) |
    +------------------------------+
    | POINT(0 0)                   |
    +------------------------------+
    

    如果几何参数位于笛卡尔空间参考系统中:If the geometry argument is in a Cartesian SRS:

    • ST_Buffer() 支持 Polygon 和 MultiPolygon 值的负距离,以及包含 Polygon 或 MultiPolygon 值的几何集合。ST_Buffer() supports negative distances for Polygon and MultiPolygon values, and for geometry collections containing Polygon or MultiPolygon values.

    • 如果结果缩小到消失,那么结果就是一个空几何体。If the result is reduced so much that it disappears, the result is an empty geometry.

    • 对于 Point、MultiPoint、LineString 和 MultiLineString 值,以及不包含任何 Polygon 或 MultiPolygon 值的几何集合,使用负距离调用 ST_Buffer() 时,会发生 ER_WRONG_ARGUMENTS 错误。An ER_WRONG_ARGUMENTS error occurs for ST_Buffer() with a negative distance for Point, MultiPoint, LineString, and MultiLineString values, and for geometry collections not containing any Polygon or MultiPolygon values.

    在地理空间参考系统 (SRS) 中允许 Point 几何,前提是满足以下条件:Point geometries in a geographic SRS are permitted, subject to the following conditions:

    • 如果距离不为负且未指定任何策略,该函数将返回 Point 在其 SRS 中的地理缓冲区。distance 参数必须以 SRS 距离单位(目前始终为米)为单位。If the distance is not negative and no strategies are specified, the function returns the geographic buffer of the Point in its SRS. The distance argument must be in the SRS distance unit (currently always meters).

    • 如果距离为负或指定了任何策略(NULL 除外),将产生 ER_WRONG_ARGUMENTS 错误。If the distance is negative or any strategy (except NULL) is specified, an ER_WRONG_ARGUMENTS error occurs.

    对于非 Point 几何图形,将产生 ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS 错误。For non-Point geometries, an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS error occurs.

    ST_Buffer() 允许在距离参数之后最多使用三个可选的策略参数。策略会影响缓冲区计算。这些参数是由 ST_Buffer_Strategy() 函数生成的字节字符串值,用于点、连接和端点策略:ST_Buffer() permits up to three optional strategy arguments following the distance argument. Strategies influence buffer computation. These arguments are byte string values produced by the ST_Buffer_Strategy() function, to be used for point, join, and end strategies:

    每种类型最多可以指定一种策略,并且它们可以按任何顺序给出。Up to one strategy of each type may be specified, and they may be given in any order.

    如果缓冲策略无效,将会发生 ER_WRONG_ARGUMENTS 错误。在以下任何情况下,策略都是无效的:If the buffer strategies are invalid, an ER_WRONG_ARGUMENTS error occurs. Strategies are invalid under any of these circumstances:

    • 指定了给定类型(点、连接或结束)的多种策略。Multiple strategies of a given type (point, join, or end) are specified.

    • 一个不是策略的值(例如任意二进制字符串或数字)被当作策略传递。A value that is not a strategy (such as an arbitrary binary string or a number) is passed as a strategy.

    • 传入了一个 Point 策略,但几何图形不包含 Point 或 MultiPoint 值。A Point strategy is passed and the geometry contains no Point or MultiPoint values.

    • 传入了一个端点或连接策略,但几何图形不包含 LineString、Polygon、MultiLinestring 或 MultiPolygon 值。An end or join strategy is passed and the geometry contains no LineString, Polygon, MultiLinestring or MultiPolygon values.

    mysql> SET @pt = ST_GeomFromText('POINT(0 0)');
    mysql> SET @pt_strategy = ST_Buffer_Strategy('point_square');
    mysql> SELECT ST_AsText(ST_Buffer(@pt, 2, @pt_strategy));
    +--------------------------------------------+
    | ST_AsText(ST_Buffer(@pt, 2, @pt_strategy)) |
    +--------------------------------------------+
    | POLYGON((-2 -2,2 -2,2 2,-2 2,-2 -2))       |
    +--------------------------------------------+
    
    mysql> SET @ls = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)');
    mysql> SET @end_strategy = ST_Buffer_Strategy('end_flat');
    mysql> SET @join_strategy = ST_Buffer_Strategy('join_round', 10);
    mysql> SELECT ST_AsText(ST_Buffer(@ls, 5, @end_strategy, @join_strategy))
    +---------------------------------------------------------------+
    | ST_AsText(ST_Buffer(@ls, 5, @end_strategy, @join_strategy))   |
    +---------------------------------------------------------------+
    | POLYGON((5 5,5 10,0 10,-3.5355339059327373 8.535533905932738, |
    | -5 5,-5 0,0 0,5 0,5 5))                                       |
    +---------------------------------------------------------------+
    
  • ST_Buffer_Strategy(strategy [, points_per_circle])

    此函数返回一个策略字节字符串,用于 ST_Buffer(),以影响缓冲区计算。This function returns a strategy byte string for use with ST_Buffer() to influence buffer computation.

    有关策略的信息可在 Boost.org 获得。Information about strategies is available at Boost.org.

    第一个参数必须是一个表示策略选项的字符串:The first argument must be a string indicating a strategy option:

    • 对于点策略,允许的值是 'point_circle' 和 'point_square'。For point strategies, permitted values are 'point_circle' and 'point_square'.

    • 对于连接策略,允许的值是 'join_round' 和 'join_miter'。For join strategies, permitted values are 'join_round' and 'join_miter'.

    • 对于端点策略,允许的值是 'end_round' 和 'end_flat'。For end strategies, permitted values are 'end_round' and 'end_flat'.

    如果第一个参数是 'point_circle'、'join_round'、'join_miter' 或 'end_round',则 points_per_circle 参数必须给出一个正数值。points_per_circle 的最大值为系统变量 max_points_in_geometry 的值。If the first argument is 'point_circle', 'join_round', 'join_miter', or 'end_round', the points_per_circle argument must be given as a positive numeric value. The maximum points_per_circle value is the value of the max_points_in_geometry system variable.

    有关示例,请参见 ST_Buffer() 的描述。For examples, see the description of ST_Buffer().

    ST_Buffer_Strategy() 按本节介绍中描述的方式处理其参数,但有以下例外:ST_Buffer_Strategy() handles its arguments as described in the introduction to this section, with these exceptions:

    • 如果任何参数无效,将发生 ER_WRONG_ARGUMENTS 错误。If any argument is invalid, an ER_WRONG_ARGUMENTS error occurs.

    • 如果第一个参数为 'point_square' 或 'end_flat',则 points_per_circle 参数不得给出,否则将发生 ER_WRONG_ARGUMENTS 错误。If the first argument is 'point_square' or 'end_flat', the points_per_circle argument must not be given or an ER_WRONG_ARGUMENTS error occurs.

  • ST_ConvexHull(g)

    返回表示几何值 g 的凸包的几何对象。Returns a geometry that represents the convex hull of the geometry value g.

    该函数通过首先检查其顶点是否共线来计算几何的凸包。如果顶点共线,则函数返回线性凸包,否则返回多边形凸包。该函数处理几何集合时,会提取集合中所有组件的所有顶点,创建一个 MultiPoint 值,并计算其凸包。This function computes a geometry's convex hull by first checking whether its vertex points are colinear. The function returns a linear hull if so, a polygon hull otherwise. This function processes geometry collections by extracting all vertex points of all components of the collection, creating a MultiPoint value from them, and computing its convex hull.

    ST_ConvexHull() 按本节介绍中的方式处理其参数,但有如下例外:ST_ConvexHull() handles its arguments as described in the introduction to this section, with this exception:

    • 当参数是空几何集合时,返回值为 NULL。The return value is NULL for the additional condition that the argument is an empty geometry collection.

    mysql> SET @g = 'MULTIPOINT(5 0,25 0,15 10,15 25)';
    mysql> SELECT ST_AsText(ST_ConvexHull(ST_GeomFromText(@g)));
    +-----------------------------------------------+
    | ST_AsText(ST_ConvexHull(ST_GeomFromText(@g))) |
    +-----------------------------------------------+
    | POLYGON((5 0,25 0,15 25,5 0))                 |
    +-----------------------------------------------+
    
  • ST_Difference(g1, g2)

    返回一个几何体,表示几何值 g1 与 g2 的点集差异。结果使用与几何参数相同的空间参考系统 (SRS)。Returns a geometry that represents the point set difference of the geometry values g1 and g2. The result is in the same SRS as the geometry arguments.

    ST_Difference() 允许参数使用笛卡尔或地理空间参考系统,并按本节开头介绍的方式处理其参数。ST_Difference() permits arguments in either a Cartesian or a geographic SRS, and handles its arguments as described in the introduction to this section.

    mysql> SET @g1 = Point(1,1), @g2 = Point(2,2);
    mysql> SELECT ST_AsText(ST_Difference(@g1, @g2));
    +------------------------------------+
    | ST_AsText(ST_Difference(@g1, @g2)) |
    +------------------------------------+
    | POINT(1 1)                         |
    +------------------------------------+
    
  • ST_Intersection(g1, g2)

    返回一个几何对象,表示几何值 g1 与 g2 的点集交集。结果使用与几何参数相同的空间参考系统(SRS)。Returns a geometry that represents the point set intersection of the geometry values g1 and g2. The result is in the same SRS as the geometry arguments.

    ST_Intersection() 允许参数使用笛卡尔或地理空间参考系统,并按照本节介绍中描述的方式处理其参数。ST_Intersection() permits arguments in either a Cartesian or a geographic SRS, and handles its arguments as described in the introduction to this section.

    mysql> SET @g1 = ST_GeomFromText('LineString(1 1, 3 3)');
    mysql> SET @g2 = ST_GeomFromText('LineString(1 3, 3 1)');
    mysql> SELECT ST_AsText(ST_Intersection(@g1, @g2));
    +--------------------------------------+
    | ST_AsText(ST_Intersection(@g1, @g2)) |
    +--------------------------------------+
    | POINT(2 2)                           |
    +--------------------------------------+
    
  • ST_LineInterpolatePoint(ls, fractional_distance)

    该函数接受一个LineString几何体和一个范围在 [0.0, 1.0] 内的分数距离,并返回沿LineString从起点到终点的给定分数距离处的Point。它可以用于回答诸如沿几何参数描述的道路中点的Point位置的问题。This function takes a LineString geometry and a fractional distance in the range [0.0, 1.0] and returns the Point along the LineString at the given fraction of the distance from its start point to its endpoint. It can be used to answer questions such as which Point lies halfway along the road described by the geometry argument.

    该函数可在所有空间参考系统的LineString几何体上使用,包括笛卡尔和地理坐标系统。The function is implemented for LineString geometries in all spatial reference systems, both Cartesian and geographic.

    如果 fractional_distance 参数为 1.0,由于近似值计算中的数值不精确,结果可能并不正好是 LineString 参数的最后一个点,而是接近它的一个点。If the fractional_distance argument is 1.0, the result may not be exactly the last point of the LineString argument but a point close to it due to numerical inaccuracies in approximate-value computations.

    一个相关的函数,ST_LineInterpolatePoints(),接收类似的参数,但返回一个 MultiPoint,其中包含沿 LineString 每个从起点到终点距离分数位置的 Point 值。有关两个函数的示例,请参见 ST_LineInterpolatePoints() 的说明。A related function, ST_LineInterpolatePoints(), takes similar arguments but returns a MultiPoint consisting of Point values along the LineString at each fraction of the distance from its start point to its endpoint. For examples of both functions, see the ST_LineInterpolatePoints() description.

    ST_LineInterpolatePoint() 按本节介绍中描述的方式处理其参数,但有以下例外:ST_LineInterpolatePoint() handles its arguments as described in the introduction to this section, with these exceptions:

    ST_LineInterpolatePoint() 是 MySQL 对 OpenGIS 的扩展。ST_LineInterpolatePoint() is a MySQL extension to OpenGIS.

  • ST_LineInterpolatePoints(ls, fractional_distance)

    此函数接受一个 LineString 几何体和范围在 (0.0, 1.0] 的分数距离,并返回 MultiPoint,包括 LineString 的起点,以及沿 LineString 从起点到终点每个距离分数处的 Point 值。它可以用于回答诸如在几何体参数描述的道路上,每隔 10% 的距离在哪些 Point 值的位置的问题。This function takes a LineString geometry and a fractional distance in the range (0.0, 1.0] and returns the MultiPoint consisting of the LineString start point, plus Point values along the LineString at each fraction of the distance from its start point to its endpoint. It can be used to answer questions such as which Point values lie every 10% of the way along the road described by the geometry argument.

    该函数可在所有空间参考系统的LineString几何体上使用,包括笛卡尔和地理坐标系统。The function is implemented for LineString geometries in all spatial reference systems, both Cartesian and geographic.

    如果 fractional_distance 参数能整除 1.0 而余数为零,由于近似值计算中的数值不准确,结果可能不包含 LineString 参数的最后一点,而是靠近它的一点。If the fractional_distance argument divides 1.0 with zero remainder the result may not contain the last point of the LineString argument but a point close to it due to numerical inaccuracies in approximate-value computations.

    一个相关的函数,ST_LineInterpolatePoint(),接受类似的参数,但返回沿着LineString从起点到终点的给定距离比例处的Point。A related function, ST_LineInterpolatePoint(), takes similar arguments but returns the Point along the LineString at the given fraction of the distance from its start point to its endpoint.

    ST_LineInterpolatePoints() 处理它的参数如本节介绍所述,以下情况除外:ST_LineInterpolatePoints() handles its arguments as described in the introduction to this section, with these exceptions:

    mysql> SET @ls1 = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)');
    mysql> SELECT ST_AsText(ST_LineInterpolatePoint(@ls1, .5));
    +----------------------------------------------+
    | ST_AsText(ST_LineInterpolatePoint(@ls1, .5)) |
    +----------------------------------------------+
    | POINT(0 5)                                   |
    +----------------------------------------------+
    mysql> SELECT ST_AsText(ST_LineInterpolatePoint(@ls1, .75));
    +-----------------------------------------------+
    | ST_AsText(ST_LineInterpolatePoint(@ls1, .75)) |
    +-----------------------------------------------+
    | POINT(2.5 5)                                  |
    +-----------------------------------------------+
    mysql> SELECT ST_AsText(ST_LineInterpolatePoint(@ls1, 1));
    +---------------------------------------------+
    | ST_AsText(ST_LineInterpolatePoint(@ls1, 1)) |
    +---------------------------------------------+
    | POINT(5 5)                                  |
    +---------------------------------------------+
    mysql> SELECT ST_AsText(ST_LineInterpolatePoints(@ls1, .25));
    +------------------------------------------------+
    | ST_AsText(ST_LineInterpolatePoints(@ls1, .25)) |
    +------------------------------------------------+
    | MULTIPOINT((0 2.5),(0 5),(2.5 5),(5 5))        |
    +------------------------------------------------+
    

    ST_LineInterpolatePoints() 是 MySQL 对 OpenGIS 的扩展。ST_LineInterpolatePoints() is a MySQL extension to OpenGIS.

  • ST_PointAtDistance(ls, distance)

    此函数接受一个 LineString 几何对象和一个在 [0.0, ST_Length(ls)] 范围内的距离,该距离以 LineString 的空间参考系统 (SRS) 的单位为单位,并返回从起点开始沿 LineString 指定距离的 Point。它可用于回答诸如道路起点起多少米的 Point 值等问题。This function takes a LineString geometry and a distance in the range [0.0, ST_Length(ls)] measured in the unit of the spatial reference system (SRS) of the LineString, and returns the Point along the LineString at that distance from its start point. It can be used to answer questions such as which Point value is 400 meters from the start of the road described by the geometry argument.

    该函数可在所有空间参考系统的LineString几何体上使用,包括笛卡尔和地理坐标系统。The function is implemented for LineString geometries in all spatial reference systems, both Cartesian and geographic.

    ST_PointAtDistance() 按本节介绍中描述的方式处理其参数,但有以下例外:ST_PointAtDistance() handles its arguments as described in the introduction to this section, with these exceptions:

    ST_PointAtDistance() 是对 OpenGIS 的 MySQL 扩展。ST_PointAtDistance() is a MySQL extension to OpenGIS.

  • ST_SymDifference(g1, g2)

    返回一个几何体,该几何体表示几何值 g1 和 g2 的点集合对称差,其定义如下:Returns a geometry that represents the point set symmetric difference of the geometry values g1 and g2, which is defined as:

    g1 symdifference g2 := (g1 union g2) difference (g1 intersection g2)
    

    或者,用函数调用表示法:Or, in function call notation:

    ST_SymDifference(g1, g2) = ST_Difference(ST_Union(g1, g2), ST_Intersection(g1, g2))
    

    结果与几何参数的空间参考系统相同。The result is in the same SRS as the geometry arguments.

    ST_SymDifference() 允许参数为笛卡尔或地理空间参考系统(SRS),并按照本节介绍中描述的方式处理其参数。ST_SymDifference() permits arguments in either a Cartesian or a geographic SRS, and handles its arguments as described in the introduction to this section.

    mysql> SET @g1 = ST_GeomFromText('MULTIPOINT(5 0,15 10,15 25)');
    mysql> SET @g2 = ST_GeomFromText('MULTIPOINT(1 1,15 10,15 25)');
    mysql> SELECT ST_AsText(ST_SymDifference(@g1, @g2));
    +---------------------------------------+
    | ST_AsText(ST_SymDifference(@g1, @g2)) |
    +---------------------------------------+
    | MULTIPOINT((1 1),(5 0))               |
    +---------------------------------------+
    
  • ST_Transform(g, target_srid)

    将几何体从一个空间参考系统(SRS)转换到另一个。返回值是与输入几何体相同类型的几何体,所有坐标已转换为目标 SRID,target_srid。MySQL 支持 EPSG 定义的所有 SRS,除了这里列出的那些:Transforms a geometry from one spatial reference system (SRS) to another. The return value is a geometry of the same type as the input geometry with all coordinates transformed to the target SRID, target_srid. MySQL supports all SRSs defined by EPSG except for those listed here:

    • EPSG 1042 克罗瓦克修改版EPSG 1042 Krovak Modified

    • EPSG 1043 克罗瓦克修改版(北向)EPSG 1043 Krovak Modified (North Orientated)

    • EPSG 9816 突尼斯矿业网格EPSG 9816 Tunisia Mining Grid

    • EPSG 9826 兰伯特圆锥等角(西向)EPSG 9826 Lambert Conic Conformal (West Orientated)

    ST_Transform() 按本节介绍中描述的方式处理其参数,但有以下例外情况:ST_Transform() handles its arguments as described in the introduction to this section, with these exceptions:

    ST_SRID(g, target_srid) 和 ST_Transform(g, target_srid) 的区别如下:ST_SRID(g, target_srid) and ST_Transform(g, target_srid) differ as follows:

    • ST_SRID() 改变几何的 SRID 值,而不转换其坐标。ST_SRID() changes the geometry SRID value without transforming its coordinates.

    • ST_Transform() 除了改变 SRID 值之外,还会转换几何坐标。ST_Transform() transforms the geometry coordinates in addition to changing its SRID value.

    mysql> SET @p = ST_GeomFromText('POINT(52.381389 13.064444)', 4326);
    mysql> SELECT ST_AsText(@p);
    +----------------------------+
    | ST_AsText(@p)              |
    +----------------------------+
    | POINT(52.381389 13.064444) |
    +----------------------------+
    mysql> SET @p = ST_Transform(@p, 4230);
    mysql> SELECT ST_AsText(@p);
    +---------------------------------------------+
    | ST_AsText(@p)                               |
    +---------------------------------------------+
    | POINT(52.38208611407426 13.065520672345304) |
    +---------------------------------------------+
    
  • ST_Union(g1, g2)

    返回一个表示几何值 g1 和 g2 点集合并的几何。结果使用与几何参数相同的 SRS。Returns a geometry that represents the point set union of the geometry values g1 and g2. The result is in the same SRS as the geometry arguments.

    ST_Union() 允许参数使用笛卡尔或地理空间参考系统,并按本节介绍的方式处理其参数。ST_Union() permits arguments in either a Cartesian or a geographic SRS, and handles its arguments as described in the introduction to this section.

    mysql> SET @g1 = ST_GeomFromText('LineString(1 1, 3 3)');
    mysql> SET @g2 = ST_GeomFromText('LineString(1 3, 3 1)');
    mysql> SELECT ST_AsText(ST_Union(@g1, @g2));
    +--------------------------------------+
    | ST_AsText(ST_Union(@g1, @g2))        |
    +--------------------------------------+
    | MULTILINESTRING((1 1,3 3),(1 3,3 1)) |
    +--------------------------------------+